0

我有两个 ASP.NET 网格视图,其中包含一个图像按钮,它们都调用一个 Edit On-click 事件。On-click 事件如下所示:

protected void Edit(object sender, EventArgs e)
{
    ImageButton ibtn1 = sender as ImageButton;

    using (GridViewRow row = (GridViewRow)((ImageButton)sender).Parent.Parent)
    {
        txtMessageID.ReadOnly = true;
        txtMessageID.Text = row.Cells[2].Text;
        txtReference.Text = row.Cells[6].Text;
        buttonClicked.Text = ibtn1.ID.ToString();
        popup.Show();
    }
}

其唯一目的是触发 ModalDialogBox,并单击网格视图中的关键项目。我的问题是其中一个网格没有 Cells[6](参考),因此会倒下。我需要做的是在这个单元格周围包装一个语句,检查按钮单击来自哪个网格(ID)。

我没有使用 Row-command,因为这不允许从多个网格调用单个方法。我的问题是如何从在此方法中单击的图像按钮获取网格 ID(见上文)?

4

1 回答 1

0

最终使用了 Gridview 的 RowCommand,然后使用以下内容来获取我需要的内容:

rotected void Edit(object sender, GridViewCommandEventArgs e) { ImageButton ibtn1 = sender as ImageButton;

    GridView grd = sender as GridView;

    string gridName = grd.ClientID;

    string buttonId = e.CommandName;

    using (GridViewRow row = (GridViewRow)((ImageButton)e.CommandSource).NamingContainer)
    {
        txtMessageID.ReadOnly = true;
        txtMessageID.Text = row.Cells[2].Text;
        if (gridName == "grdMessageDups")
        {
            txtReference.Text = row.Cells[6].Text;
        }
        buttonClicked.Text = ibtn1.ID.ToString();
        popup.Show();
    }
}
于 2013-06-19T11:11:21.467 回答