Checkbox Column Not Appearing
am 31.12.2007 18:07:48 von 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:
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">
ForeColor="White" />
>
Bold="True" ForeColor="#333333" />
HorizontalAlign="Center" />
ForeColor="White" />
ForeColor="#284775" />
runat="server" />
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!!
Re: Checkbox Column Not Appearing
am 02.01.2008 16:58:43 von Ben
On Dec 31 2007, 11:07=A0am, 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.4guysfr=
omrolla.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. =A0Any
> ideas? =A0here's the source if it helps:
>
>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
erver"
> AllowSorting=3D"True" CellPadding=3D"4"
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ForeColor=3D"#333333" GridLines=3D=
"None"
> OnSorting=3D"gridIssues_Sorting" Style=3D"font-size: 10pt;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 font-family: arial"
> OnDataBinding=3D"gridIssues_DataBinding"
> OnDataBound=3D"gridIssues_DataBound"
> OnRowDataBound=3D"gridIssues_RowDataBound" DataKeyNames=3D"MonitorID">
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
Font-Bold=3D"True"
> ForeColor=3D"White" />
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
reColor=3D"#333333" /
>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
" />
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
DED6" Font-
> Bold=3D"True" ForeColor=3D"#333333" />
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
ForeColor=3D"White"
> HorizontalAlign=3D"Center" />
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
Font-Bold=3D"True"
> ForeColor=3D"White" />
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
White"
> ForeColor=3D"#284775" />
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
Box ID=3D"CheckBox1"
> runat=3D"server" />
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
> =A0 =A0 =A0 =A0 =A0 =A0
>
> 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 =3D 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 =3D
Server.HtmlDecode(e.Row.Cells[i].Text);
}
}
}