![]() |
| ||
| Accessing ItemTemplate server control properties in a gridview I have a gridview that has a couple of Label server controls nested inside an ItemTemplate. I want to assign their Text value when each row is databound (I'm using Profile properties so I have to get the user and their profile to get the values). <asp:GridView ID="grdUsers" runat="server" AllowPaging="True" AutoGenerateColumns="False" DataKeyNames="UserName,UserID" DataMember="DefaultView" DataSourceID="dsUsers" EmptyDataText="There are no users"> I'm using the gridview's RowDataBound event to do the label.Text assignment protected void grdUsers_RowDataBound(object sender, GridViewRowEventArgs e) It's failing and giving me an error message stating that lastName is null. What am I doing wrong here? Any and all assistance is much appreciated. Thanks in advance. |
| ||
| Re: Accessing ItemTemplate server control properties in a gridview You need to bind the labels text to some field value like Text='<%#Bind(ColumnName) %>' Since you are not binding i suppose you are getting the error for null values in lblLastName,lblFirstName |
| ||
| Re: Accessing ItemTemplate server control properties in a gridview Another thought: Do you allow NULL value in your database for LastName field? If yes then you need to handle tat NULL in your code. Postmaster <snipped> |
| All times are GMT -4. The time now is 11:32 pm. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC