larrystewart
asked on
Asp.net checkbox
I created a datagrid template with a checkbox. I have the checkbox bound to a data item in a sql database. As a troubleshooting process I created a textbox that is bound to the same data item. The textbox shows the value (true or false), but the checkbox is empty. Here is my code:
What could be causing the checkbox not to update?
Thank you
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" OnCheckedChanged="ToggleRo wSelection " AutoPostBack="True" runat="server" Style="position: static" Checked='<%# Eval("Blocked") %>' />
<asp:TextBox ID="TextBox1" runat="server" Style="position: static" Text='<%# Eval("Blocked") %>'
Width="95px"></asp:TextBox >
</ItemTemplate>
What could be causing the checkbox not to update?
Thank you
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" OnCheckedChanged="ToggleRo
<asp:TextBox ID="TextBox1" runat="server" Style="position: static" Text='<%# Eval("Blocked") %>'
Width="95px"></asp:TextBox
</ItemTemplate>
Hmm....it almost seems like the "Checked" property is having trouble converting the value of Blocked to a True or False value...you coudl create a public function in your codebehind and do this:
<asp:CheckBox ID="CheckBox1" OnCheckedChanged="ToggleRo wSelection " AutoPostBack="True" runat="server" Style="position: static" Checked='<%# StrBool2Int(Eval("Blocked" )) %>' />
and in the CodeBehind
Public Function StrBool2Int(ByVal strValue As String)
If strValue.Trim.ToUpper = "TRUE" Then
Return "1"
Else
Return "0"
End If
End Function
The 1 or the Zero will be interpreted to True or False.
<asp:CheckBox ID="CheckBox1" OnCheckedChanged="ToggleRo
and in the CodeBehind
Public Function StrBool2Int(ByVal strValue As String)
If strValue.Trim.ToUpper = "TRUE" Then
Return "1"
Else
Return "0"
End If
End Function
The 1 or the Zero will be interpreted to True or False.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
the field is a varchar so I pasted the code you suggested above, and I am receiving a syntax error.
ASKER
OK. I am using the option suggested by traxion, it is returing the 0 and 1 and designed, but the checkboxes are still empty.
Thank you
Thank you
Checked is a boolean property, so I suspect it would be happier using:
Public Function StrToBool(ByVal strValue As String)
If strValue.Trim.ToUpper = "TRUE" Then
Return true
Else
Return false
End If
End Function
Jim
Public Function StrToBool(ByVal strValue As String)
If strValue.Trim.ToUpper = "TRUE" Then
Return true
Else
Return false
End If
End Function
Jim
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
I figured out the issue, but comments from both responders were helpful so I am splitting the points. It turned out to be an issue with the some pre-render code that was being called.
thank you
thank you
My pleasure. Good luck.
Jim
Jim
You're welcome. Glad you got it figured out. :)
Jim