|
 |
aspx thread: <HeaderTemplate> - LoadTemplate
Message #1 by "Dean Santillan" <webmaster@5...> on Sat, 25 May 2002 07:51:33
|
|
Hi,
I am trying to load a template into the datalist control by using the
following code.
Can anyone tell me what is wrong with this code. Itb is not loading
anything in at all. No errors as well.
View.ascx..............
private void BindData()
{
Config NewConfig = (Config) HttpContext.Current.Items["Settings"];
Sections NewSection = new Sections();
dlDisplaySections.DataSource = NewSection.ViewSections
(NewConfig.SiteData.SiteID);
////// This where I initiate it but nothing is happening
dlDisplaySections.HeaderTemplate = this.LoadTemplate
("~/AdminEvolusys/Controls/Sections/Header.ascx");
///
dlDisplaySections.DataBind();
}
Thanks
Dean Santillan
Message #2 by "Mingkun Goh" <mangokun@h...> on Sun, 26 May 2002 05:16:32
|
|
Two things you must make sure:
- Your .ascx file really exist (i guess so, in your case)
- Your .ascx file is of the proper format
Look under the the VS.NET Documentation for
'Creating Templates Dynamically in a DataList Web Server Control'
Message #3 by "Dean Santillan" <webmaster@5...> on Sun, 26 May 2002 14:40:01 +0900
|
|
No I did that and it doesnt work as well. But when you have a template what
the vs.net documentation is saying that you cannot have a code behind file
which is what i need.
What i am trying to do is get to a datalistitem in the datalist but
everytime i do it says that is no items or value is null. So I thought i
would try the templates. But they dont work as well so i really have no
idea.
here is where i want to get to.
I am trying to access the highleted control in a datalist. I have tried so
many things but it keeps on saying to me there are no
controls in the dlDisplaySections datalist control when there are. How can I
access it. I really have no idea now.
ctrl0:dlDisplaySections System.Web.UI.WebControls.DataList 4612 76
ctrl0:dlDisplaySections:ctrl0
System.Web.UI.WebControls.DataListItem 316 0
ctrl0:dlDisplaySections:ctrl0:ctrl0
System.Web.UI.LiteralControl 8 0
// this one i need to get to
ctrl0:dlDisplaySections:ctrl0:LbID System.Web.UI.WebControls.Label 71 0
Thanks
Dean
-----Original Message-----
From: Mingkun Goh [mailto:mangokun@h...]
Sent: Sunday, May 26, 2002 5:17 AM
To: ASP+
Subject: [aspx] Re: <HeaderTemplate> - LoadTemplate
Two things you must make sure:
- Your .ascx file really exist (i guess so, in your case)
- Your .ascx file is of the proper format
Look under the the VS.NET Documentation for
'Creating Templates Dynamically in a DataList Web Server Control'
Message #4 by "Mingkun Goh" <mangokun@h...> on Tue, 28 May 2002 06:49:30
|
|
Here is some sample code which I hope can be of use to you.
Private Sub DataList1_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataListItemEventArgs) Handles
DataList1.ItemDataBound
If Not IsNothing(e.Item.FindControl("lblPriceRange")) Then
Dim Hotelrow As DataRow = dsHotel.Tables(0).Rows
(e.Item.ItemIndex)
' Cast the control to its specific type
Dim labelPriceRange As Label = CType(e.Item.FindControl
("lblPriceRange"), Label)
' Change any of its properties
labelPriceRange.Text = Hotelrow("Price_Range")
End If
End Sub
lblPriceRange will be the id of a Web Form Control in the DataList Item
Template.
Other ways to debug your code:
1. Put a label outside your datalist.
DataBinding yout DataList is not neccessary.
Set the label's Text to the Row Count of your DataSource.
Confirm that there are actually some rows in it.
2. Always check DataList.SelectedIndex <> -1 before doing anything, or
else you will be trying to reference a invalid object.
|
|
 |