Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why does DataList Create Literal Controls???

Status
Not open for further replies.

MrCSharp

IS-IT--Management
Jun 7, 2005
59
CA
Does anyone know why when you create a control(Link Button)in the SelectedItemTemplate of a datalist it become a Literal Control. I am trying to do a FindControl() on the controls in the SelectedItem but it wont find them, i populate a list of all the controls id and they show up blank(they do show up), I also add the type of the control and they are Literals but all the controls created in the ItemTemplate show/act normal.

Heres the code if that helps:

Code:
								<SelectedItemTemplate>						ID:
								<%# DataBinder.Eval(Container.DataItem,"ID") %>
								<br>
								<br>
								Description:
								<%# DataBinder.Eval(Container.DataItem,"DocumentDescription") %>
								<br>
								<br>
								Details:
								<%# DataBinder.Eval(Container.DataItem,"Details") %>
								<br>
								<br>
								FileType:
								<%# DataBinder.Eval(Container.DataItem,"FileType") %>
								<br>
								<br>
								Difficulty:
								<%# DataBinder.Eval(Container.DataItem,"DiffDescription") %>
								<br>
								<br>
								<asp:HyperLink ID="hlView1" Runat="server" Target="_blank" NavigateUrl="default.aspx" Enabled="True">View</asp:HyperLink>
									|
									<asp:LinkButton ID="btndetails1" Runat="server" text="Show Details" CommandName="select" Enabled="False"></asp:LinkButton>
									|
									<asp:LinkButton ID="btnComment1" Runat="server" text="Comment"></asp:LinkButton>
								</SelectedItemTemplate>

								<ItemTemplate>
									<%# DataBinder.Eval(Container.DataItem,"DocumentDescription") %>
									<asp:Image ID=diff ImageUrl='<%# DataBinder.Eval(Container.DataItem,"Image") %>' Runat=server ImageAlign=Right>
									</asp:Image>
									<BR>
									<asp:HyperLink ID="hlView2" Runat="server" Target="_blank" NavigateUrl="default.aspx" Enabled="True">View</asp:HyperLink>
									|
									<asp:LinkButton ID="btnDetails2" Runat="server" text="Show Details" CommandName="select"></asp:LinkButton>
									|
									<asp:LinkButton ID="btnComment2" Runat="server" text="Comment"></asp:LinkButton>
								</ItemTemplate>
The code behind:
Code:
		private void dlDocumentList_ItemDataBound(object sender, DataListItemEventArgs e)
		{
			int fNum	= 0;
			fileType fType;
			if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) {
				HyperLink hl= (HyperLink)e.Item.FindControl("hlView2");
				fNum  = (int)dsDocumentList1.Tables[0].Rows[e.Item.ItemIndex]["ID"];
				fType = (fileType)dsDocumentList1.Tables[0].Rows[e.Item.ItemIndex]["FileTypeNum"];
				hl.NavigateUrl = GetUrl(fNum,fType);				
			}
			if (e.Item.ItemType == ListItemType.SelectedItem) 
			{
				HyperLink hl= (HyperLink)e.Item.FindControl("hlView1");
				fNum  = (int)dsDocumentList1.Tables[0].Rows[e.Item.ItemIndex]["ID"];
				fType = (fileType)dsDocumentList1.Tables[0].Rows[e.Item.ItemIndex]["FileTypeNum"];
				hl.NavigateUrl = GetUrl(fNum,fType);				
			}			
		}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top