Problem with checkbox binding in DetailsView
-
Hi. I have a detailsview with a checkbox. This checkbox´s state should be determined from a ObjectDataSource which "fills" the detailsview. And, if the checkbox´s state is changed by the user, the ObjectDataSource´s UpdateMethod should of course save this new state. Problem is, that i dont know how to bind this checfield, since the 'Checked' attribute only takes true/false, and my data is in xml. Therefore i only have "true"/"false" data as strings. So how do i bind this checkbox state? And save the new state when the user changes it? Thanks alot!
-
Hi. I have a detailsview with a checkbox. This checkbox´s state should be determined from a ObjectDataSource which "fills" the detailsview. And, if the checkbox´s state is changed by the user, the ObjectDataSource´s UpdateMethod should of course save this new state. Problem is, that i dont know how to bind this checfield, since the 'Checked' attribute only takes true/false, and my data is in xml. Therefore i only have "true"/"false" data as strings. So how do i bind this checkbox state? And save the new state when the user changes it? Thanks alot!
what is the data type of your field you want to bind?
-
what is the data type of your field you want to bind?
-
The data type is string. The field contains "false" or "true". And should be bound to the checkbox´ checked attribute which takes boolean. Thanks!
Try This
Checked='<%#(Eval("Field").ToString() == "true" ? true : false) %>'
-
Try This
Checked='<%#(Eval("Field").ToString() == "true" ? true : false) %>'
Thanks alot! But it did not solve my problem. With this solution, i can DISPLAY the correct data (if the box are checked or not). But when the user updates the data (changes the checked state), the ObjectDataSource´s UpdateMethod sees the field as null. Is there a workaround on this? :)
-
Thanks alot! But it did not solve my problem. With this solution, i can DISPLAY the correct data (if the box are checked or not). But when the user updates the data (changes the checked state), the ObjectDataSource´s UpdateMethod sees the field as null. Is there a workaround on this? :)
<UpdateParameters>
<asp:ControlParameter ControlID="CheckBox1" Name="Field"
PropertyName="Checked" Type="String" />
</UpdateParameters> -
<UpdateParameters>
<asp:ControlParameter ControlID="CheckBox1" Name="Field"
PropertyName="Checked" Type="String" />
</UpdateParameters> -
Thanks. But I cant get it to work. Can you please post the full example including the DetailsView and CheckBox tags? Thanks alot! :)
try something like this? make sure in the prerender event you have soemthing like this.. CheckBox chkdnslive = (CheckBox)detailsView.FindControl("chkDNSLive"); chkdnslive.Checked = true; //default to true