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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can a DataList HeaderTemplate bound Items from the DataSource? 1

Status
Not open for further replies.

Alcar

Programmer
Sep 10, 2001
595
US
Greetings all,

I am using a DataList to recreate an order form. I have some Header information and then the Order Details. I am trying to DataBind the Header information in the HeaderTemplate and I get no result. (no errors either)

Eg:

<asp:DataList id=&quot;dlOrders&quot; runat=&quot;server&quot; Width=&quot;100%&quot;>
<HeaderTemplate>
<asp:Label ID=&quot;lblOrderNumber&quot; Runat=&quot;server&quot;><%# DataBinder.Eval(Container.DataItem, &quot;OrderNumber&quot;).ToString()%></asp:Label>
</HeaderTemplate>

and I get absolutely nothing. ANYHOO... I was wondering if I could work around this...
Or should I just re-think my datasource structure...

Jelly-beans for helpers =)
Daren J. Lahey
Just another computer guy...
If you are unsure of forum etiquette check here FAQ796-2540
 
Try it without the .ToString and see if it will just display the number.

BRAVO btw! You've correctly spelled ANYHOO!
:D

D'Arcy
 
No, the header doesn't work like that... since the databinding is, in effect, a loop -- a vertical one at that.

If you need to adjust the appearance of your header, use the onItemDataBound event, and tell him:

if e.item.itemType = listItemType.Header then
e.item.cells(0).text = &quot;header1&quot;
e.item.cells(1).text = &quot;header2&quot;
'and so on
end if

Anywho, I hope that helps! ;-)
paul
penny1.gif
penny1.gif
 
Paul is at the top of the list here and it shows he spells anyWHO right.

Paul I looked thru some of my old code and what I did is probably massively innefficient but.. I used the databinder for the headers.


<HeaderTemplate>
<asp:Label id=Label1 runat=&quot;server&quot; Text='<%# DataBinder.Eval(DataSet11, &quot;Tables[Employees].DefaultView.[0].EmployeeID&quot;) %>'>
</asp:Label>
</HeaderTemplate>


I didn't specify the Container which is what the list is bound to but used the dataset itself instead.
Just thought I would add that to the pile That'l do donkey, that'l do
[bravo] Mark
If you are unsure of forum etiquette check here faq796-2540
 
Extremely interesting Mark. What index is passed to choose the right Dataview? Is it the same as the DataSetIndex passed by the datalist events?
Eg:

DataList_DoEdit(Object sender, DataGridCommandEventArgs e)
{
int dsIndex = (int)e.Item.DataSetIndex;
}
Daren J. Lahey
Just another computer guy...
If you are unsure of forum etiquette check here FAQ796-2540
 
Not sure I understand the question. Or what I was doing when I wrote that actually.

This only works when the table only has one row or when a column is the exact same throughout as it would be for an id in a details section for example.

I use the HTML view as little as possible, VS doesn't seem to like it much.
When I put this together I added a label to the header section of the datalist and then hit the databinding button. From there I just chose the options I wanted.

In the page_load event I made sure the datalist I was using was filled... and the villagers danced!

Not sure if I cleared anything up on that let me know. That'l do donkey, that'l do
[bravo] Mark
If you are unsure of forum etiquette check here faq796-2540
 
Here it is:

System.Data.DataRowView DataView[int recordIndex]

It returns a DataRowView that you can access through the recordIndex (equal to the DataSetIndex).

Et voila'!

So if we have a DataSet that filles the DataList, we can access it through the:

<%# DataBinder.Eval(DataSetID, &quot;Tables[TableName].DefaultView.[recordIndex].FieldName&quot;) %>

Thanks Mark!
Daren J. Lahey
Just another computer guy...
If you are unsure of forum etiquette check here FAQ796-2540
 
glad to help That'l do donkey, that'l do
[bravo] Mark
If you are unsure of forum etiquette check here faq796-2540
 
I think I am short of stars...

Anyhowl... let me draw one

*stiks his tongue out*

there!! Are ya happy now? =) Daren J. Lahey
Just another computer guy...
If you are unsure of forum etiquette check here FAQ796-2540
 
lol yup I can sleep better now That'l do donkey, that'l do
[bravo] Mark
If you are unsure of forum etiquette check here faq796-2540
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top