如标题所示,如何在 gridview 按钮中使用模态弹出扩展器。
在gridview内部,按钮只是一个带有图像的普通按钮(我没有使用编辑模板添加按钮)。
现在我所做的是(根据在线资源),我在 gridview 上添加一个事件,这就是这个。
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
(e.Row.FindControl("lnkEdit") as Button).Attributes.Add("onClick", "ShowEditModal('" + ID + "');");
}
}
Showeditmodal函数是一个在html页面上的javascript函数,但问题是,我如何能够从gridview中的不同行获取不同的ID,以根据ID弹出正确的模式?
最佳答案
可以通过e.Row.Cells
获取
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
int idColumnNumber=1; // number of your id column
int id=Convert.ToInt32(e.Row.Cells[idColumnNumber].Text);
(e.Row.FindControl("lnkEdit") as Button).Attributes.Add("onClick", "ShowEditModal('" + id + "');");
}
}
关于javascript - 如何在 gridview 图像按钮内使用模态弹出扩展器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32793836/