Checkbox Column Not Appearing

B

Ben

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!!
 
B

Ben

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);
}
}
}
 

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,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top