asp.net and C#
here I have the columns from a gridview control
when the user clicks either button i need to pass the values for CaseID, CaseworkerID, EventDate and Code to a stored procedure
but how do i pass multiple parameters to my onclick method ????
<columns>
<asp:BoundField DataField="CaseID" HeaderText="CaseID" Visible = "False" />
<asp:BoundField DataField="caseworkerID" HeaderText="CwID" Visible = "False" />
<asp:BoundField DataField="CaseWorker" HeaderText="Case Worker" />
<asp:BoundField DataField="EventDate" HeaderText="Event Date" />
<asp:BoundField DataField="Code" HeaderText="Code" />
<asp:TemplateField HeaderText="ADD">
<ItemTemplate>
<asp:Button ID="AddUnit" runat="server" Text=" +1 " onserverclick="AddUnit_Click"/>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="TotalUnits" HeaderText="Total Units" />
<asp:TemplateField HeaderText="DDT">
<ItemTemplate>
<asp:Button ID="DdtUnit" runat="server" Text=" -1 " onserverclick="DdtUnit_Click"/>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="EventType" HeaderText="Event Type" />
<asp:BoundField DataField="UnitCost" HeaderText="Unit Cost" />
<asp:BoundField DataField="TotalCost" HeaderText="Total Cost"/>
EDIT:
so I now have this
<ItemTemplate>
<asp:Button ID="AddUnit" runat="server" Text=" +1 "
CommandName="AddUnit"
CommandArgument='<%# Eval("CaseID")+ ";" + Eval("caseworkerID")+ ";" + Eval("EventDate")+ ";" + Eval("Code")%>'/>
</ItemTemplate>
thats a good start
Pretty much what you want to do is create a commandargument thats deliminated by a special character(s). When you handle the event, pull out the command argument from the event (e) and split it. (As utkarshs answer shows, use the gridviews rowcommand event, not an onclick)
This can cause issues if the commandargument data actually contains the same character you used for a deliminator. Just one suggestion though (we do this sometimes when we know someting like a productId won’t contain a pipe (|) )
EDIT:
So your button should be something like…
Then in your code behind where your grid id is
gridId