gridview复选框无法正常工作 [英] gridview checkbox not working

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

问题描述

当我再次创建新的Web表单时,代码工作正常。但当我添加其他代码的文件

上传它不再工作。似乎代码不起作用如果在网页表单中添加其他代码

???





for(int i = 0; i< GridView1.Rows.Count; i ++)

{

CheckBox chkDelete =(CheckBox)GridView1.Rows [i] .Cells [0] .FindControl(chkSelect);

if(chkDelete!= null)

{



if(chkDelete.Checked)

{

strID = GridView1.Rows [i] .Cells [1] .Text;

idCollection。添加(strID);

}

}

}





the code worked when i created a new web form again. but when i added other codes for file
uploading it doesnt work anymore. it seems that the code does not work if add other codes in
the web form ???


for (int i = 0; i < GridView1.Rows.Count; i++)
{
CheckBox chkDelete = (CheckBox)GridView1.Rows[i].Cells[0].FindControl("chkSelect");
if (chkDelete != null)
{

if (chkDelete.Checked)
{
strID = GridView1.Rows[i].Cells[1].Text;
idCollection.Add(strID);
}
}
}


<Columns>
                       <asp:TemplateField>
                       <ItemTemplate>
              <asp:CheckBox ID="chkSelect" runat="server" />
             </ItemTemplate>

                       </asp:TemplateField>
                   </Columns>

推荐答案

这将有所帮助,试试这个

this will be helpful, try this
for (int i = 0; i < GridView1.Rows.Count; i++)
{
     CheckBox chkDelete = (CheckBox)GridView1.Rows[i].FindControl("chkSelect");
     
     if (chkDelete != null)
     {
          if (chkDelete.Checked)
          {
               Label myLabel = (Label)GridView1.Rows[i].FindControl("TEXT_CONTROL_ID");
               idCollection.Add(myLabel.Text);
          }
     }
}


这篇关于gridview复选框无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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