I have a gridview with multiple rows, each has a Update button and I need to pass 2 values when someone clicks on Update button. Aside from packing the arguments inside CommandArgument separated by commas (archaic and not elegant), how would I pass more than one argument?
<asp:LinkButton ID="UpdateButton" runat="server" CommandName="UpdateRow" CommandArgument="arg_value" Text="Update and Insert" OnCommand="CommandButton_Click" ></asp:LinkButton>
As a note, the values can't be retrieved from any controls on the page, so I am presently not seeking any design solutions.
Multiple values will be passed by concatenating multiple values using a Character separator such as Comma, Pipe, etc. and later inside the Button Click event, the values will be split and populated into an Array.
The CommandArgument property complements the CommandName property by allowing you to provide any additional information about the command to perform. For example, you can set the CommandName property to Sort and set the CommandArgument property to Ascending to specify a command to sort in ascending order.
You can pass semicolon separated values as command argument and then split the string and use it.
<asp:TemplateField ShowHeader="false"> <ItemTemplate> <asp:LinkButton ID="lnkCustomize" Text="Customize" CommandName="Customize" CommandArgument='<%#Eval("IdTemplate") + ";" +Eval("EntityId")%>' runat="server"> </asp:LinkButton> </ItemTemplate> </asp:TemplateField>
at server side
protected void gridview_RowCommand(object sender, GridViewCommandEventArgs e) { string[] arg = new string[2]; arg = e.CommandArgument.ToString().Split(';'); Session["IdTemplate"] = arg[0]; Session["IdEntity"] = arg[1]; Response.Redirect("Samplepage.aspx"); }
Hope it helps!!!!
After poking around it looks like Kelsey is correct.
Just use a comma or something and split it when you want to consume it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With