I now know the cause of this problem but not the solution. The column 2
is a TemplateColumn populated with data but e.Item.Cells[2].Text
returns empty string. All other cells which are databond return correct
values. This seems to be a fundamental misunderstandig on my behalf.
Any idea how can I solve this?
[quoted text, click to view] bkasmai@gmail.com wrote:
> This is driving me crazy. I need to hide rows that a particular cell is
> zero. On debuggng I fiound out that ItemDataBound fires for header only
> and not for Item and AlternatingItem
> private void grdSelectionList_ItemDataBound(object sender,
> System.Web.UI.WebControls.DataGridItemEventArgs e)
> {
> if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
> ListItemType.AlternatingItem )
> {
> if (e.Item.Cells[2].Text == "0")
> {
> e.Item.Visible = false;
> }
> }
>
> Any help on this will be appreciated.
Found the solution! For TemplateColumn the FindControl must be used:
Label lbl = (Label)e.Item.Cells[2].FindControl("label_ID");
if (lbl.Text == "0")
{
e.Item.Visible = false;
}
[quoted text, click to view] bkasmai@gmail.com wrote:
> I now know the cause of this problem but not the solution. The column 2
> is a TemplateColumn populated with data but e.Item.Cells[2].Text
> returns empty string. All other cells which are databond return correct
> values. This seems to be a fundamental misunderstandig on my behalf.
> Any idea how can I solve this?
>
> bkasmai@gmail.com wrote:
> > This is driving me crazy. I need to hide rows that a particular cell is
> > zero. On debuggng I fiound out that ItemDataBound fires for header only
> > and not for Item and AlternatingItem
> > private void grdSelectionList_ItemDataBound(object sender,
> > System.Web.UI.WebControls.DataGridItemEventArgs e)
> > {
> > if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
> > ListItemType.AlternatingItem )
> > {
> > if (e.Item.Cells[2].Text == "0")
> > {
> > e.Item.Visible = false;
> > }
> > }
> >
> > Any help on this will be appreciated.
Don't see what you're looking for? Try a search.