vyclarks
vyclarks

Reputation: 878

Right syntax of CommandArgument of imagebutton

How can I pass more than one argument in ImageButton?

Materially:

<asp:ImageButton ID="ImageButton1" runat="server" OnCommand="ButtonDelete_Click" ImageUrl="ForumImages/invalid.gif" CommandArgument='<%#Eval("ID"+'-'+"USERNAME")%>' />

I wonder if the line below is wrong or not? I want to pass: both ID and USERNAME to ButtonDelete_Click Event in the code behind.

CommandArgument='<%#Eval("ID"+'-'+"USERNAME")%>'

But when I build this page, it has an error:

The server tag is not well formed.

Upvotes: 1

Views: 831

Answers (2)

शेखर
शेखर

Reputation: 17614

use like this

CommandArgument='<%#Eval("ID"+"-"+"USERNAME")%>'

Edit 1

 CommandArgument='<%#Eval("ID")+"-"+Eval("USERNAME")%>'

Upvotes: 1

Nitu Bansal
Nitu Bansal

Reputation: 3856

you can use like below

  CommandArgument='<%#Eval("ID") + ";" +Eval("USERNAME")%>'

in code there you will find arguments like below

   protected void gridview_RowCommand(object sender, GridViewCommandEventArgs e)
   {
  string[] arg = new string[2];
  arg = e.CommandArgument.ToString().Split(';');
  Session["ID"] = arg[0];
  Session["USERNAME"] = arg[1];

  }

Upvotes: 2

Related Questions