Checkbox Column Not Appearing

Discussion in 'ASP .Net' started by Ben, Dec 31, 2007.

  1. Ben

    Ben Guest

    Hi,

    I'm designing a c# page and trying to add a checkbox column to a
    GridView, I've added a Template Row (as described at:
    http://aspnet.4guysfromrolla.com/articles/052406-1.aspx) and in the
    Edit Templates dragged a Checkbox into the Item Template.

    The new column shows up, but it's empty...no checkbox appears. Any
    ideas? here's the source if it helps:


    <ContentTemplate>
    <asp:GridView ID="gridIssues" runat="server"
    AllowSorting="True" CellPadding="4"
    ForeColor="#333333" GridLines="None"
    OnSorting="gridIssues_Sorting" Style="font-size: 10pt;
    font-family: arial"
    OnDataBinding="gridIssues_DataBinding"
    OnDataBound="gridIssues_DataBound"
    OnRowDataBound="gridIssues_RowDataBound" DataKeyNames="MonitorID">
    <FooterStyle BackColor="#5D7B9D" Font-Bold="True"
    ForeColor="White" />
    <RowStyle BackColor="#F7F6F3" ForeColor="#333333" /
    >

    <EditRowStyle BackColor="#999999" />
    <SelectedRowStyle BackColor="#E2DED6" Font-
    Bold="True" ForeColor="#333333" />
    <PagerStyle BackColor="#284775" ForeColor="White"
    HorizontalAlign="Center" />
    <HeaderStyle BackColor="#5D7B9D" Font-Bold="True"
    ForeColor="White" />
    <AlternatingRowStyle BackColor="White"
    ForeColor="#284775" />
    <Columns>
    <asp:TemplateField>
    <ItemTemplate>
    <asp:CheckBox ID="CheckBox1"
    runat="server" />
    </ItemTemplate>
    </asp:TemplateField>
    </Columns>
    </asp:GridView>
    </ContentTemplate>


    btw, I'm not setting a Data Source in the designer... in my code, I
    load a DataView into memory and then bind it to the GridView... not
    sure if that changes something...

    Thanks so much!!
     
    Ben, Dec 31, 2007
    #1
    1. Advertising

  2. Ben

    Ben Guest

    On Dec 31 2007, 11:07 am, Ben <> wrote:
    > Hi,
    >
    > I'm designing a c# page and trying to add a checkbox column to a
    > GridView, I've added a Template Row (as described at:http://aspnet.4guysfromrolla.com/articles/052406-1.aspx) and in the
    > Edit Templates dragged a Checkbox into the Item Template.
    >
    > The new column shows up, but it's empty...no checkbox appears.  Any
    > ideas?  here's the source if it helps:
    >
    > <ContentTemplate>
    >                 <asp:GridView ID="gridIssues" runat="server"
    > AllowSorting="True" CellPadding="4"
    >                     ForeColor="#333333" GridLines="None"
    > OnSorting="gridIssues_Sorting" Style="font-size: 10pt;
    >                     font-family: arial"
    > OnDataBinding="gridIssues_DataBinding"
    > OnDataBound="gridIssues_DataBound"
    > OnRowDataBound="gridIssues_RowDataBound" DataKeyNames="MonitorID">
    >                     <FooterStyle BackColor="#5D7B9D" Font-Bold="True"
    > ForeColor="White" />
    >                     <RowStyle BackColor="#F7F6F3" ForeColor="#333333" /
    >
    >                     <EditRowStyle BackColor="#999999" />
    >                     <SelectedRowStyle BackColor="#E2DED6" Font-
    > Bold="True" ForeColor="#333333" />
    >                     <PagerStyle BackColor="#284775" ForeColor="White"
    > HorizontalAlign="Center" />
    >                     <HeaderStyle BackColor="#5D7B9D" Font-Bold="True"
    > ForeColor="White" />
    >                     <AlternatingRowStyle BackColor="White"
    > ForeColor="#284775" />
    >                     <Columns>
    >                         <asp:TemplateField>
    >                             <ItemTemplate>
    >                                 <asp:CheckBox ID="CheckBox1"
    > runat="server" />
    >                             </ItemTemplate>
    >                         </asp:TemplateField>
    >                     </Columns>
    >                 </asp:GridView>
    >             </ContentTemplate>
    >
    > btw, I'm not setting a Data Source in the designer... in my code, I
    > load a DataView into memory and then bind it to the GridView... not
    > sure if that changes something...
    >
    > Thanks so much!!


    I found out my issue, in case someone else runs into it... I was
    replacing each cell's text with a 'decoded' html... since some of my
    columns had hypertext in there and I wanted it to be parsed -- I guess
    it was screwing up the TemplateField...not sure why...maybe there's a
    better way? ...for now I skipped the cell that has the checkbox and it
    solved the issue:


    protected void gridIssues_RowDataBound(object sender,
    GridViewRowEventArgs e)
    {

    if (e.Row.RowType == DataControlRowType.DataRow)
    {
    for (int i = 1; i < e.Row.Cells.Count; i++) //<----
    changed i to a 1 instead of 0, so it skips the first checkbox column
    {
    e.Row.Cells.Text =
    Server.HtmlDecode(e.Row.Cells.Text);
    }
    }
    }
     
    Ben, Jan 2, 2008
    #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. carlos perez
    Replies:
    0
    Views:
    417
    carlos perez
    Jun 8, 2004
  2. Gregory Rampton

    Convert an MS Access Yes/No column to a checkbox column in C# datagrid

    Gregory Rampton, Aug 6, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    199
    Gregory Rampton
    Aug 6, 2003
  3. Kris Oye
    Replies:
    1
    Views:
    222
    Yosias Selemon
    Jul 30, 2003
  4. jmhmaine
    Replies:
    0
    Views:
    291
    jmhmaine
    Jan 20, 2005
  5. jmhmaine
    Replies:
    2
    Views:
    310
    Steven Cheng[MSFT]
    Jan 21, 2005
Loading...

Share This Page