Last post Jan 25, 2019 12:56 AM by callykalpana
Jan 23, 2019 12:17 AM|callykalpana|LINK
Hi, I have got a repeater control of which one column is designated for checkboxes only. I was not able to get the checkbox ID to appear in the code behind until I found this code
CheckBox chk = (CheckBox)Repeater1.Items[i].FindControl("Checkbox1");
Label1.Text = "hello";
I understand that we are casting the checkbox within the repeater control to a checkbox object, but I would like to understand the logic behind it. I am pretty new to .Net and web forms, so would need to do some learning on the controls within another control.
Jan 23, 2019 03:20 PM|yogyogi|LINK
In ASP.NET Web forms the checkbox, textbox, repeater are classes. You inorder to get an instance of a particular control. like repeater in your case, you have to find that control and cast it.
The code below is finding the 'Checkbox1' control by name. And then it is casted to 'Checkbox'.
Jan 24, 2019 09:13 AM|Jenifer Jiang|LINK
Just as yogyogi has explained, in webforms, the control like checkbox, textbox or the label are always the classes.
And when you want to find the specific one, you should use the function .FindControl to find it by its id.
For more about .FindControl, you could refer to the official document:
Jan 25, 2019 12:56 AM|callykalpana|LINK
Thanks for the guidance guys.