
 Rank: Guest Groups: Guest
Joined: 9/17/2007 Posts: 11,670 Points: -1,200
|
Date parsed: 05/10/2007 06:31:37 Date: Fri, 05 Oct 2007 13:31:37 -0700
i hope there are better options, but here are 2 ideas.
concatenate your fields in the argument and split them on the other end.
set the DataGrid's DataKeyField and use it to lookup your arguments again later from a persisted object.
|

 Rank: Guest Groups: Guest
Joined: 9/17/2007 Posts: 11,670 Points: -1,200
|
Date parsed: 05/10/2007 10:39:44 Date: Fri, 05 Oct 2007 17:39:44 -0700
On Oct 5, 1:43 pm, Me LK <klka...@charter.net> wrote: > Hi, > > I understand the code for passing a parameter of one field item from a > button using the command argument. What I need to do is pass three > fields. For example > > My button code currently is as follows: > > -------------------------------------------------------------------------= --=AD----------------- > Inside a data grid > > <asp:TemplateColumn> > <ItemTemplate> > <asp:LinkButton id=3DlinkButton CommandArgument=3D'< > %#databinder.eval(Container.dataitem, "intProductID") %>' Text=3D"Buy" > Runat=3D"server"></asp:LinkButton> > </ItemTemplate> > </asp:TemplateColumn> > > -------------------------------------------------------------------------= --=AD----------------------- > My codebehind is > > Private Sub itemInfo_itemCommand(ByVal source As Object, ByVal e As > System.web.UI.WebControls.DataGridCommandEventArgs) Handles > itemInfo.ItemCommand > 'The command arguement of the button that was clicked > 'In the datagrid contains the productID > Dim intProductID As Integer =3D e.CommandArgument > 'Add the product to the shopping cart > ShoppingCart.AddProduct(intProductID) > > End Sub > -------------------------------------------------------------------------= --=AD--------------- > > ShoppingCart.AddProduct(intProductID) is in a class document and is as > follows > > Public Shared Function AddProduct(ByVal intProductID As Integer) > > ' Create the connection object > Dim connection As New SqlConnection(connectionString) > ' Create and initialize the command object > Dim command As New SqlCommand("AddProductToCart", connection) > command.CommandType =3D CommandType.StoredProcedure > ' Add an input parameter and supply a value for it > command.Parameters.Add("@CartID", SqlDbType.Char, 36) > command.Parameters("@CartID").Value =3D shoppingCartID > ' Add an input parameter and supply a value for it > command.Parameters.Add("@intProductID", SqlDbType.Int) > command.Parameters("@intProductID").Value =3D intProductID > > ' Open the connection, execute the command, and close the > connection > Try > connection.Open() > command.ExecuteNonQuery() > Finally > connection.Close() > End Try > End Function > > Now I not only need to pass IntProductID but also size and color. How > will I create three parameters using a button? > > Would love ideas > > Thanks > LK
<asp:TemplateColumn> <ItemTemplate> <asp:LinkButton id=3DlinkButton CommandArgument=3D'<%# databinder.eval(Container.dataitem, "intProductID") & "|" & databinder.eval(Container.dataitem, "charProductColor") & "|" & databinder.eval(Container.dataitem, "intProductSize") %>' Text=3D"Buy" Runat=3D"server"></asp:LinkButton> </ItemTemplate> </asp:TemplateColumn>
In your ItemCommand event handler: dim Args(2) as string =3D cstr(e.CommandName).Split("|") dim ProductID as integer =3D cint(Args(0)) dim ProductColor as string =3D Args(1) dim ProductSize as integer =3D cint(Args(2))
HTH,
-E
|

 Rank: Guest Groups: Guest
Joined: 9/17/2007 Posts: 11,670 Points: -1,200
|
Date parsed: 05/10/2007 17:43:58 Date: Fri, 05 Oct 2007 17:43:58 -0000
Hi,
I understand the code for passing a parameter of one field item from a button using the command argument. What I need to do is pass three fields. For example
My button code currently is as follows:
Inside a data grid
<asp:TemplateColumn> <ItemTemplate> <asp:LinkButton id=linkButton CommandArgument='< %#databinder.eval(Container.dataitem, "intProductID") %>' Text="Buy" Runat="server"></asp:LinkButton> </ItemTemplate> </asp:TemplateColumn>
My codebehind is
Private Sub itemInfo_itemCommand(ByVal source As Object, ByVal e As System.web.UI.WebControls.DataGridCommandEventArgs) Handles itemInfo.ItemCommand 'The command arguement of the button that was clicked 'In the datagrid contains the productID Dim intProductID As Integer = e.CommandArgument 'Add the product to the shopping cart ShoppingCart.AddProduct(intProductID)
End Sub
ShoppingCart.AddProduct(intProductID) is in a class document and is as follows
Public Shared Function AddProduct(ByVal intProductID As Integer)
' Create the connection object Dim connection As New SqlConnection(connectionString) ' Create and initialize the command object Dim command As New SqlCommand("AddProductToCart", connection) command.CommandType = CommandType.StoredProcedure ' Add an input parameter and supply a value for it command.Parameters.Add("@CartID", SqlDbType.Char, 36) command.Parameters("@CartID").Value = shoppingCartID ' Add an input parameter and supply a value for it command.Parameters.Add("@intProductID", SqlDbType.Int) command.Parameters("@intProductID").Value = intProductID
' Open the connection, execute the command, and close the connection Try connection.Open() command.ExecuteNonQuery() Finally connection.Close() End Try End Function
Now I not only need to pass IntProductID but also size and color. How will I create three parameters using a button?
Would love ideas
Thanks LK
|