?
Solved

Insede of ItemDataBound

Posted on 2006-03-29
4
Medium Priority
?
263 Views
Last Modified: 2008-01-09
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

0
Comment
Question by:Yurich
  • 2
  • 2
4 Comments
 
LVL 10

Accepted Solution

by:
orbulat earned 2000 total points
ID: 16329249
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
    }
}
0
 
LVL 21

Author Comment

by:Yurich
ID: 16329314
thanks,

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

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

any ideas?

regs,
yurich
0
 
LVL 21

Author Comment

by:Yurich
ID: 16329372
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
0
 
LVL 10

Expert Comment

by:orbulat
ID: 16329500
great that u've solved this!
thanks a lot :-)
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Screencast - Getting to Know the Pipeline
Suggested Courses
Course of the Month15 days, 6 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question