2015-09-26 12 views
1

作为标题,如何在gridview按钮中使用模态弹出扩展器。如何在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功能是一个JavaScript函数的HTML页面上,但事情是,我是如何抓住从不同的行不同的ID在GridView,弹出基于ID的正确模式?

+0

实际的ID是什么怎么做呢?它是来自GridView的其中一列的值吗? –

+0

是的。你是对的,仅仅是一个价值 –

+0

然后在下面看到我的答案。 –

回答

0

您可以通过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 + "');"); 

       } 
      } 
相关问题