GridView中的按钮如何向触发的方法中传递多个参数

来源:百度知道 编辑:UC知道 时间:2024/05/10 19:04:05
GridView中自定义行中有一个ImageButton按钮,代码如下:
<asp:ImageButton ID="ImageButton1" runat="server" CausesValidation="False" ImageUrl="~/images/sq.jpg"

OnCommand="ResponseInfo" CommandArgument='<%# Eval("User_ID") %>' />
我想通过单击这个按钮后触发后台的ResponseInfo方法,但是如果用以上的方法可以正常执行,但是我希望传递多个参数,

那我该怎么做呀?

ResponseInfo方法代码如下:
protected void ResponseInfo(object sender, CommandEventArgs e)
{
string UserID= e.CommandArgument.ToString();
Response.Write("您选择的ID号是" + UserID);
}
以上代码我只是传递了一个参数,请问传递多个参数我应该怎么修改前后台代码呀?

例如传递Eval("User_Name")这个参数。

不要用imagebutton来绑定方法,可以用GridView_RowCommand事件来执行.
在GridView中加几个label让它的值等于你需要的如
<asp:Label Text='<%# Eval("User_ID") %>' id="label1"/>
<asp:Label Text='<%# Eval("User_Name") %>' id="label2"/>

在imagebutton上,要设置CommandName="自定的" commandargument="<%# ((GridViewRow)Container).RowIndex %>"

然后在GridView_RowCommand事件中来获取当前点击行的数据.
if (e.CommandName.ToString() == "自定的")
{
int index = Convert.ToInt32(e.CommandArgument);
GridViewRow row = GridViewRow .Rows[index];
Label label1= (Label)row.FindControl(("label1"));
Label label2= (Label)row.FindControl(("label2"));
Response.Write("您选择的ID号是" + label1.Text);
Response.Write("您选择的用户名是" + label2.Text);
}