如何在不使用foreach()的情况下使用复选框从gridview获取数据 [英] how to fetch data from gridview using checkbox without using foreach()

查看:86
本文介绍了如何在不使用foreach()的情况下使用复选框从gridview获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在GridView的itemtemplate中有一个textBox和Checkbox,并希望使用checkbox事件从gridview的textBox中获取数据.但是,当我单击第一次迭代时,它工作正常,但是对于第二次迭代,即当另一行时包含未选中的复选框会导致问题.
我添加了一个if条件用于检查,否则为unchecked.对于,第一次迭代效果很好,但是,如果未选中第二个复选框,则为其余迭代提供了else条件.任何人都可以给我一些建议.

关于
NANKi

I have A textBox and Checkbox in itemtemplate inside GridView and want to fetch the data from textBox in the gridview using checkbox event.But,When I click on first iteration it works fine but,For second iteration i.e,when the other row containing checkbox which is not checked causes problem.
i have added a if condition for checked and else for unchecked.For,First iteration serves good but,if when second checkbox is not checked it gives else condition for the remaining iterations.Can Anyone give me some suggestion.

with regards
NANKi

推荐答案

Nandakishore
请查看以下各项是否对您有用-
Nandakishore
please see if the following works for you -
protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
   TextBox tb = ((Control)sender).NamingContainer.FindControl("TextBox1") as TextBox;
   string requiredtext = tb.Text;
}


用您的文本框控件的ID替换"TextBox1".


Substitute "TextBox1" with the ID of your textbox control.


如果您的复选框较少,请尝试if条件.

if(checkboxid.checked == true)
{

代码在这里

}
If u have less checkboxes try if condition.

if(checkboxid.checked==true)
{

Code Goes Here

}


这篇关于如何在不使用foreach()的情况下使用复选框从gridview获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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