By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,396 Members | 2,501 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,396 IT Pros & Developers. It's quick & easy.

Checkbox Column Not Appearing

P: n/a
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!!
Dec 31 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Ben
On Dec 31 2007, 11:07*am, Ben <benm5...@gmail.comwrote:
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[i].Text =
Server.HtmlDecode(e.Row.Cells[i].Text);
}
}
}
Jan 2 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.