1

我无法弄清楚如何在 ITemplate 中使用我的 imagebutton(见下文)将按钮的相应行数据(ItemID)附加为查询字符串。

我的 ITemplate 中的 ImageButton:

ImageButton select_button = new ImageButton();
select_button.ID = "select_button";
select_button.ImageUrl = "~/Files/System/Icons/highlighter.png";
select_button.CommandName = "Select";
select_button.ToolTip = "Select";
container.Controls.Add(select_button);

我应该在 imagebutton 的 OnClick 事件中处理它(如果是这样,有没有办法获取按钮所在的行)或者我可以在 GridView 事件(rowbinding、rowseleted、rowcommand 等)中处理它?

我很乐意应要求详细说明我的代码。^ ^

4

1 回答 1

1

您可以在事件CommandArgument中的按钮控件的属性中设置 ID 。RowDataBound一旦你有了一个 ID,你就可以用它来跟踪行。

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        DataRow dr = ((DataRowView)e.Row.DataItem).Row;
        ((Button)e.Row.FindControl("select_button")).CommandArgument = dr["IdColumn"].ToString();
    }
}
于 2011-06-07T05:20:00.123 回答