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
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.
Please advice.
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'.
Repeater1.Items[i].FindControl("Checkbox1")
Helping you always. Don't forget to click "Mark as Answer" on the post that helped you.
♠ ASP.NET Core Tutorials → Start from the Beginning and become an Expert in 30 days time ♠
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Member
37 Points
109 Posts
Understanding the logic behind checkboxes inside a repeater control
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
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. Please advice.
Participant
1253 Points
935 Posts
Re: Understanding the logic behind checkboxes inside a repeater 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'.
♠ ASP.NET Core Tutorials → Start from the Beginning and become an Expert in 30 days time ♠
Contributor
2150 Points
705 Posts
Re: Understanding the logic behind checkboxes inside a repeater control
Jan 24, 2019 09:13 AM|Jenifer Jiang|LINK
Hi callykalpana,
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:
https://docs.microsoft.com/en-us/dotnet/api/system.web.ui.page.findcontrol?view=netframework-4.7.2
Best Regards,
Jenifer
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Member
37 Points
109 Posts
Re: Understanding the logic behind checkboxes inside a repeater control
Jan 25, 2019 12:56 AM|callykalpana|LINK
Thanks for the guidance guys.