gridview中的运行时复选框 [英] runtime checkbox in gridview

查看:77
本文介绍了gridview中的运行时复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在gridview中使用了运行时复选框.Below是我的代码。

 protected void GridView1_RowDataBound(object sender,GridViewRowEventArgs e)
{
if(e.Row.RowType == DataControlRowType.Header)
{

}

if(e.Row.RowType == DataControlRowType.DataRow)
{
int i = Convert.ToInt16(ViewState [i]);
CheckBox chk = new CheckBox();
chk.ID =DynamicCheckBox+ e.Row.Cells [0] .Text;
//chk.Text = e.Row.Cells [3] .Text;
e.Row.Cells [0] .Controls.Add(chk);
}
}



现在,我必须检查选中了哪个复选框,以及那些选中的复选框按钮点击事件的gridview行。

怎么做?

解决方案

  foreach (GridViewRow grdRow   GridView1.Rows)
{
if (((CheckBox)grdRow.FindControl( DynamicCheckBox + grdRow。单元格[ 0 ]。文本))。已检查)
{
// 做点什么
}
}


你可以添加一个jquery点击按钮的处理程序。

 <   pre     lang   =  Javascript >  


('#button')。click(function(){

i have used runtime checkbox in gridview.Below is my code for that.

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
       {
           if (e.Row.RowType == DataControlRowType.Header)
           {

           }

           if (e.Row.RowType == DataControlRowType.DataRow)
           {
               int i = Convert.ToInt16(ViewState["i"]);
               CheckBox chk = new CheckBox();
               chk.ID = "DynamicCheckBox" + e.Row.Cells[0].Text;
               //chk.Text = e.Row.Cells[3].Text;
               e.Row.Cells[0].Controls.Add(chk);
           }
       }


now, i have to check which checkbox are checked, and those checkbox which are checked do something on that row of gridview on button click event.
how to do this?

解决方案

foreach (GridViewRow grdRow in GridView1.Rows)
{
    if (((CheckBox)grdRow.FindControl("DynamicCheckBox" +grdRow.Cells[0].Text)).Checked)
    { 
          // do something
     }
}


You can add a jquery click handler for the button.

<pre lang="Javascript">


('#button').click(function(){


这篇关于gridview中的运行时复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆