wieders
wieders

Reputation: 31

Controls in TemplateFields not displaying in GridView

I have a gridview with one boundfield that is filled in the code-behind after the user makes some selections from a dropdown. This is filled fine, but I also have two other columns with checkboxes in TemplateFields. These are never displayed in this gridview. Here's the aspx:

<asp:UpdatePanel ID="clientServerUpdatePanel" runat="server">
        <ContentTemplate>
            <asp:GridView ID="clientServerGridView" runat="server" AutoGenerateColumns="False">
                <Columns>
                    <asp:BoundField HeaderText="Operating System" DataField="OS" />
                    <asp:TemplateField HeaderText="Client" >
                        <asp:ItemTemplate>
                            <asp:CheckBox runat="server" ID="clientCheckBox" Checked="false" />
                        </asp:ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Server">
                        <asp:ItemTemplate>
                            <asp:Checkbox runat="server" ID="serverCheckBox" Checked="false" />
                        </asp:ItemTemplate>
                    </asp:TemplateField>
                </Columns>
            </asp:GridView>
        </ContentTemplate>
    </asp:UpdatePanel>

Here's the relavent code-behind which is placed in a click event handler:

Dim dt As DataTable = New DataTable()
dt.Columns.Add(New DataColumn("OS", System.Type.GetType("System.String")))

For Each OSItem As ListItem In Me.defaultOSesListBox.Items
    If Not OSItem.Selected Then
        Continue For
    End If

    Dim dr As DataRow = dt.NewRow()
    Dim os As String = OSItem.Text
    dr("OS") = os
    dt.Rows.Add(dr)
Next

Me.clientServerGridView.DataSource = dt
Me.clientServerGridView.DataBind()

Does anyone have an idea what the root of my problem is?

EDIT: I needed to have the checkboxes wrapped in

<ItemTemplate>

instead of

<asp:ItemTemplate>

Upvotes: 0

Views: 2092

Answers (1)

wieders
wieders

Reputation: 31

I found the issue. I had the checkboxes wrapped in

<asp:ItemTemplate>

when it should have been

<ItemTemplate>  

Issue was immediately fixed when I made this change.

Upvotes: 2

Related Questions