Results 1 to 2 of 2

Thread: Finding a label value within a datagrid

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2005
    Posts
    1

    Exclamation Finding a label value within a datagrid

    I know this is C# code, but even if someone can provide a VB.NET example, that would be fine. I have a Label as a TemplateColumn in my Datagrid. When I do a watch on e.Item.Cells[3].Text, I can see the Header come back as Completed Date. But I can never see any of the items, even though they do show up in the datagrid! So, my basic question is how can I get the value of the label within the datagrid? Below is my itemdatabound event, as well as my datgrid layout. Thanks for looking. I am desperate now...it seems so simple...

    Code:
    		private void _dgProjectEvent_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
    		{
    			if((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
    			{
    				CheckBox chk = (CheckBox)e.Item.FindControl("chkComplete");
    				Label lbl = (Label) e.Item.Cells[3].FindControl("_lblCompletedDate");
    				if(lbl.Text=="")
    				{
    					chk.Visible=true;
    				}
    			}
    		}
    Code:
    					<asp:DataGrid CellPadding="5" CellSpacing="3" HeaderStyle-HorizontalAlign="Center" HeaderStyle-CssClass="BodyTextBold"
    							AutoGenerateColumns="False" CssClass="BodyText" id="_dgProjectEvent" runat="server">
    							<Columns>
    								<asp:TemplateColumn ItemStyle-HorizontalAlign="Center">
    									<HeaderTemplate>
    										Event
    									</HeaderTemplate>
    									<ItemTemplate>
    										<table width="100%" height="100%">
    											<tr>
    												<td class="BodyText" bgcolor='<%# DataBinder.Eval(Container.DataItem,"BackGroundColor").ToString()%>'>
    													<%# DataBinder.Eval(Container.DataItem,"EventName") %>
    													<asp:Label Visible=False ID="_lblEventID" Text='<%# DataBinder.Eval(Container.DataItem,"EventID") %>' runat="server"/>
    												</td>
    											</tr>
    										</table>
    									</ItemTemplate>
    								</asp:TemplateColumn>
    								<asp:TemplateColumn ItemStyle-HorizontalAlign="Center">
    									<HeaderTemplate>
    										Lead Time
    									</HeaderTemplate>
    									<ItemTemplate>
    										<asp:Label text= '<%# DataBinder.Eval(Container.DataItem,"LeadTime") %>' id="_lblLeadTime" runat="server">
    										</asp:Label>
    									</ItemTemplate>
    								</asp:TemplateColumn>
    								<asp:TemplateColumn>
    									<HeaderTemplate>
    										Est. Completion Date
    									</HeaderTemplate>
    									<ItemTemplate>
    										<asp:Label text= '<%# Convert.ToDateTime(DataBinder.Eval(Container.DataItem,"EstimatedCompletionDate")).ToShortDateString() %>' id="_lblEstimatedCompletionDate" runat="server">
    										</asp:Label>
    									</ItemTemplate>
    								</asp:TemplateColumn>
    								<asp:TemplateColumn ItemStyle-HorizontalAlign="Center">
    									<HeaderTemplate>
    										Completed Date
    									</HeaderTemplate>
    									<ItemTemplate>
    										<asp:Label text= '<%# ReturnDateValue(DataBinder.Eval(Container.DataItem,"CompletedDate").ToString()) %>' id="_lblCompletedDate" runat="server">
    										</asp:Label>
    									</ItemTemplate>
    								</asp:TemplateColumn>
    								<asp:BoundColumn DataField="PartyResponsible" HeaderText="Responsible Party" />
    								<asp:TemplateColumn>
    									<HeaderTemplate>
    										Corrective Action
    									</HeaderTemplate>
    									<ItemTemplate>
    										<a onclick="window.open('c_action.aspx?p=<%# DataBinder.Eval(Container.DataItem,"ProjectID") %>&ev=<%# DataBinder.Eval(Container.DataItem,"EventID") %>&id=<%# ReturnCorrectiveActionQueryString(DataBinder.Eval(Container.DataItem,"CorrectiveActionTypeID").ToString()) %>')" href="#">
    											<%# ReturnCorrectiveActionURLDisplay(DataBinder.Eval(Container.DataItem,"CorrectiveActionName")) %>
    										</a>
    									</ItemTemplate>
    								</asp:TemplateColumn>
    								<asp:TemplateColumn ItemStyle-HorizontalAlign="Center">
    									<HeaderTemplate>
    										Complete
    									</HeaderTemplate>
    									<ItemTemplate>
    										<%=_string%>
    										<asp:CheckBox Runat="server" ID="chkComplete"></asp:CheckBox>
    									</ItemTemplate>
    								</asp:TemplateColumn>
    							</Columns>
    						</asp:DataGrid>

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Finding a label value within a datagrid

    Try doing this in the ItemDataBound event. Unless you have a good reason for putting it in the ItemCreated event.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width