Checking a checkbox based upon a table field

Discussion in 'ASP .Net Datagrid Control' started by William Gower, May 17, 2004.

  1. 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>
     
    William Gower, May 17, 2004
    #1
    1. Advertising

  2. 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]



    "William Gower" <> wrote in message
    news:...
    >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>
    >
    >
     
    Ken Cox [Microsoft MVP], May 17, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Moe Sizlak
    Replies:
    3
    Views:
    510
    Mike Smith
    Jul 20, 2004
  2. glorfindel
    Replies:
    1
    Views:
    140
    Samuel Kim
    Feb 19, 2005
  3. Joey Pang
    Replies:
    4
    Views:
    563
    Joey Pang
    Jun 13, 2005
  4. Scott Gordo
    Replies:
    1
    Views:
    174
    Kyle Peterson
    Mar 23, 2006
  5. Replies:
    4
    Views:
    99
Loading...

Share This Page