Checking a checkbox based upon a table field

W

William Gower

I have a template column in my grid that displays a checkbox. I would like
to have the box checked if a field in the table that the grid is based upon
has a "C" in the field. How do I do that?


<asp:TemplateColumn HeaderText="Close">
<ItemTemplate>
<asp:CheckBox Runat="server" id="close"></asp:Checkbox>
</ItemTemplate>
</asp:TemplateColumn>
 
K

Ken Cox [Microsoft MVP]

Hi William,

You can use a helper function. Just pass it the value, test if it is a "C"
and get back a boolean:


<asp:TemplateColumn HeaderText="Crew Chief?">
<HeaderStyle HorizontalAlign="Center" Width="40px"
VerticalAlign="Middle"></HeaderStyle>
<ItemTemplate>
<asp:checkbox id="chkChief" runat="server"
AutoPostBack="True"
Checked='<%# SetCheckValue(Container.DataItem("StringValue"))%>'>
</asp:checkbox>
</ItemTemplate>
</asp:TemplateColumn>


Function SetCheckValue _
(ByVal strValue As String) As Boolean
If IsNothing(strValue) Then
Return False
Else
' Look for the exact string
' such as "C" here.
' I'm using "Item 4"
If strValue = "Item 4" Then
Return True
Else
Return False
End If
End If
End Function

Does this help?

Ken
Microsoft MVP [ASP.NET]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top