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

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

Left by web development company at 8/14/2009 7:06 AM
Gravatar
Hey, that was interesting,

I had the same problem but couldn't figure out the problem. but with the diplay none everthing is solved.

Thanks for writing about it

Your comment:



 (will not be displayed)


 
 
 
 
 

Live Comment Preview:

 
«November»
SunMonTueWedThuFriSat
25262728293031
1234567
891011121314
15161718192021
22232425262728
293012345