ASP.NET CheckBox inside Datagrid returns Checked=false in Postback, if the column is not visible.

In one of ASP.NET pages I've used CheckBox column inside Datagrid, and  on some condition the column containing checkbox was invisible 
TemplateColumn.Visible=false
On postback my code tried to read if  control is checked, and it always returned  chk.Checked=false.

It seems that it is done by design and  invisible CheckBox does not have ViewState["Checked"].


As it suggested in the link Invisible column won't be rendered to the client.(http://www.velocityreviews.com/forums/t93577)-aspnet-datagrid-template-column-when-inivisible.html):

Make the column invisible with css rule display:none.

posted @ Wednesday, October 11, 2006 11:06 AM

Print

Comments on this entry:

# re: ASP.NET CheckBox inside Datagrid returns Checked=false in Postback, if the column is not visible.

Left by Cedd Burge at 5/30/2007 4:02 AM
Gravatar
I have just come across this very annoying problem myself. Did you find an easy solution to it?

# re: ASP.NET CheckBox inside Datagrid returns Checked=false in Postback, if the column is not visible.

Left by Michael Freidgeim at 5/30/2007 12:10 PM
Gravatar
As it suggested in the link http://www.velocityreviews.com/forums/t93577-aspnet-datagrid-template-column-when-inivisible.html

Make the column invisible with css rule display:none.

# re: ASP.NET CheckBox inside Datagrid returns Checked=false in Postback, if the column is not visible.

Left by I have the same problem at 11/14/2007 6:11 AM
Gravatar
My code is like this.. it say check box checked is false.

----------

Protected Sub CheckNow(ByVal sender As Object, ByVal e As System.EventArgs) Handles button2.Click
recipient_list.Text = ""
Dim I As Long
For I = 0 To friends.Items.Count - 1
Dim CurrentCheckBox As CheckBox
CurrentCheckBox = friends.Items(I).FindControl("ChkSelect")
'recipient_list.Text & = friends.Items(I).ItemIndex & CurrentCheckBox.text.ToString() & "-" & CurrentCheckBox.checked.ToString() & "<br>"
recipient_list.Text & = CurrentCheckBox.text.ToString() & "-" & CurrentCheckBox.Checked.ToString()

Next
End Sub

Your comment:



 (will not be displayed)


 
 
 
Please add 6 and 2 and type the answer here:
 

Live Comment Preview:

 
«December»
SunMonTueWedThuFriSat
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910