Home > ASP.Net > Pass Multiple values in CommandArgument and Get them

Pass Multiple values in CommandArgument and Get them


Hi all,

try this example to Multiple values in CommandArgument and get these values with Gridview control

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns = "false">
    <Columns>
        <asp:TemplateField>
        <ItemTemplate>
         <asp:Button ID="Button1" runat="server" Text='<%#Eval("CustomerID")%>'
          CommandArgument= '<%#Eval("PostalCode") + "," + Eval("City") + "," + Eval("Country") %>' OnClick = "Button1_Click" />
        </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>

so now to get these values you need to do the following :-

protected void Button1_Click(object sender, EventArgs e)
{
    Button btn = (Button)sender;
    string[] CommandArgument = btn.CommandArgument.Split(',');
    string CommandArgument1 = CommandArgument[0];
    string CommandArgument2 = CommandArgument[1];
    string CommandArgument3 = CommandArgument[2];
}

Hope this helps

Good Luck

Advertisements
Categories: ASP.Net
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: