Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / October 2007

Tip: Looking for answers? Try searching our database.

passing more then one parameter in CommandArgument

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Me LK - 05 Oct 2007 18:43 GMT
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
tomisarobot@gmail.com - 05 Oct 2007 21:31 GMT
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.
Elroyskimms - 06 Oct 2007 01:39 GMT
> Hi,
>
[quoted text clipped - 64 lines]
> Thanks
> LK

<asp:TemplateColumn>
<ItemTemplate>
<asp:LinkButton
    id=linkButton
    CommandArgument='<%# databinder.eval(Container.dataitem,
"intProductID") & "|" & databinder.eval(Container.dataitem,
"charProductColor") & "|" & databinder.eval(Container.dataitem,
"intProductSize")  %>' Text="Buy"
Runat="server"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateColumn>

In your ItemCommand event handler:
dim Args(2) as string = cstr(e.CommandName).Split("|")
dim ProductID as integer = cint(Args(0))
dim ProductColor as string = Args(1)
dim ProductSize as integer = cint(Args(2))

HTH,

-E

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.