Insede of ItemDataBound

Hello I have a datagrid with template items - it's fairely simple, one column of checkboxes, and three columns of the labels (one label in one column). It's implemented like that (that's for one column):

<asp:TemplateColumn HeaderText="Item Description">
      <HeaderTemplate>
            <asp:Label Runat="server" ID="Label16">Item Description</asp:Label>
      </HeaderTemplate>
      <ItemTemplate>
            <asp:Label ID="lblDescription" Runat="server" Width="250">
                  <%# DataBinder.Eval( Container.DataItem, "description" ) %>
            </asp:Label>
      </ItemTemplate>
</asp:TemplateColumn>

and everything works fine.

I need to do some changes depending on to what my labels are bound - enabling or disable checkboxes in the first column - and I'm trying to check it like that:

if( (( Label )e.Item.Cells[ 3 ].Controls[ 1 ]).Text != someTextContro.Text ) { ... }

inside ItemDataBound and it is always empty... I checked MSDN and it's said this event is called AFTER the item is bound, so presumable if the item IS bound, controls inside this item should be bound as well and should contain some data... Yet it's not working this way.

I can suggest that controls inside the item are bound later, but what do I do in this case?? What is the event I can use to enable/disable my controls depending on what my controls inside items were bound to.

Thanks,
Yurich

LVL 21
YurichAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

orbulatCommented:
u can simply do so

1. go to design view of your datagrid, in "Properties" ,click "Events" tab, double click "ItemDataBound"
2. this will bring you to code behind
3. then u do sth. like this-->

if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
    DataRowView dv = (DataRowView)e.Item.DataItem;
    Label lblDescription= (Label)e.Item.FindControl("lblDescription");
    lblDescription.Text = dv["description"];
    //then do your modification
    if (lblDescription.Text == "")
    {
         //xxxxx
    }
}

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
YurichAuthor Commented:
thanks,

I have exception "specified cast is not valid" on this line:

DataRowView dv = ( DataRowView )e.Item.DataItem;

any ideas?

regs,
yurich
YurichAuthor Commented:
OK,
found how to do it:

System.Data.Common.DbDataRecord ddr = ( System.Data.Common.DbDataRecord )e.Item.DataItem;
string ecert = ddr[ "description" ].ToString();

All credit goes to you as you pointed to the right direction and I was completely stuck :)

Thank you
orbulatCommented:
great that u've solved this!
thanks a lot :-)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.