Click here to Skip to main content
15,906,816 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I m binding the checkbox control to the grid view dynamically. Multiple columns and rows in my grid view. I have to refer the checkbox which is placed in grid view columns and rows that if it is checked or not in code behind. I m using Master pages too. Any Idea?????????
Posted
Updated 16-May-14 19:26pm
v2
Comments
j snooze 16-May-14 16:50pm    
Your question and explanation are unclear. You are trying to add a checkbox to a placeholder or you are trying to access a checkbox inside a gridview? Which is it?
R@M-ITcian 17-May-14 1:26am    
I have added check box control dynamically. But now my problem access it
karthik Udhayakumar 17-May-14 1:29am    
post your code dear:)
R@M-ITcian 17-May-14 1:34am    
Public Sub AddCheckBox()<br>
For Each row As GridViewRow In gv.Rows<br>
For i = 0 To dtop.Rows.Count - 1<br>
If row.RowType = DataControlRowType.DataRow Then<br>
Dim cb As New CheckBox<br>
<br>
row.Cells(i + 2).Controls.Add(cb)<br>
End If<br>
Next<br>
Next<br>
End Sub<br>
 <br>
Protected Sub Page_PreLoad(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreLoad<br>
If (Not IsPostBack) Then<br>
Dim dtop As DataTable = BOLayer.GetDTable("")<br>
For j = 0 To dtop.Rows.Count - 1<br>
Dim tf As New TemplateField()<br>
Dim cb As New CheckBox<br>
tf.HeaderText = "" & dtop.Rows(j)(0) & ""<br>
gv.Columns.Add(tf)<br>
Next<br>
End If<br>
End Sub.

For this in click event i want to check the checkbox state by access t
j snooze 19-May-14 9:02am    
What I've done in the past (right or wrong, I don't know) is when I add a dynamic control I store the control id in delimited list hidden field so in your case.<br>
Add a hidden field and<br>
HiddenControl1.value += cb.ClientId + "|" <br>
or whatever your preferred delimiter is just so you know its client id, put this right after you add it to your placeholder.
Then to get the control on postback you should be able to reference the control per the <br>

Dim CheckboxIds() as string = HiddenControl1.Value.Split("|")<br>
Then loop through and get the checkboxes<br>
Request.Form(CheckboxIds(i)).<br>
 <br>
Sorry this is not a full code sample, but to give you an idea of how to get at the dynamic controls on postback.

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