Click here to Skip to main content
15,889,651 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted

Nandakishore
please see if the following works for you -
C#
protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
   TextBox tb = ((Control)sender).NamingContainer.FindControl("TextBox1") as TextBox;
   string requiredtext = tb.Text;
}

Substitute "TextBox1" with the ID of your textbox control.
 
Share this answer
 
v2
If u have less checkboxes try if condition.

if(checkboxid.checked==true)
{

Code Goes Here

}
 
Share this answer
 
Comments
Nandakishore G N 4-Feb-12 5:55am    
No.I have even tried what you have said.But,I have to maintain both TextBox And CheckBox to fetch Data.But,I have To Show Message For even Under Unchecked Condition.
OriginalGriff 4-Feb-12 5:57am    
Reasons for my vote of one:
1) Please, read the question.It is not about a single checkbox, it is about multiple checkboxes.
2) You do not need to use "==true" when you are checking against a boolean value.
Prasad Guduri 4-Feb-12 15:34pm    
Thanks for Your Suggestion Original Griff...!!!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900