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

Datalist: what am I missing here? 1

Status
Not open for further replies.

coco86

Programmer
Joined
Mar 13, 2002
Messages
296
Location
DE
I'm trying to create a datalist for an ASP.NET page. I get multiple rows in the list but they all contain the same data...the first record.

i.e.
White
White
White
White
White

and so on and so on. It should be

White
Green
Carson
O'Leary
Straight


I've tried creating a datagrid using the same dataset and I get all the rows the way I'm supposed to. I've also tried creating a different page in a different project with a different table in a different database...same problem. So I'm pretty sure it's not the data.

Is there a setting I've missed somewhere?



-Coco

[auto]
 
Can we see the code where you set up the DataBinding/DataSource?
 
The datasource is a dataset that I let VS create for me. I'm using the authors table from Pubs in SQL server. I just dragged and dropped the table to create the Connection and dataAdapter objects and then generated the dataset.

I set the datasource of the datalist and the datagrid in the properties and then in the page load event I have:


Me.SqlDataAdapter1.Fill(Me.DataSet11)
Me.DataList1.DataBind()
Me.DataGrid1.DataBind()

(once again, the datagrid works fine and it uses the same dataset)

-Coco

[auto]
 
for the datalist, have you set the
DataTextField
and
DataValueField

for the list?

--------------------------
"two wrongs don't make a right, but three lefts do" - the unknown sage
 
I'm not sure where those properties are located. I did add a label to the item template. It's databinding properties are set to have the bindable property be text and using simple binding, the text property is bound to the au_lname field of the dataset.

-Coco

[auto]
 
Nevermind my last post, in my haste I misread the post.

Can you post the ItemTemplate code (from the .aspx markup)? Maybe you're referencing the first element of the DataSource or something by mistake.
 
Ok, here it is:


<asp:DataList id=DataList1 DataMember="authors" DataSource="<%# DataSet11 %>" runat="server" Width="100%" DataKeyField="au_id">
<HeaderTemplate>
<asp:Label id="Label2" runat="server" Font-Bold="True">Last Name</asp:Label>
</HeaderTemplate>
<ItemTemplate>
<asp:Label id=Label1 Width="50%" runat="server" Height="100%" Text='<%# DataBinder.Eval(DataSet11, "Tables[authors].DefaultView.[0].au_Lname") %>'>
</asp:Label>
</ItemTemplate>
</asp:DataList>


-Coco

[auto]
 
Try:
Code:
<asp:Label id=Label1 Width="50%" runat="server" Height="100%" Text='<%# DataBinder.Eval(Container.DataItem, "au_Lname") %>'>
 
WOO-HOO!!! [2thumbsup]

It worked! Thanks!

Now can you tell me why the other doesn't?

-Coco

[auto]
 
Because "you're referencing the first element of the DataSource or something by mistake". ;-)
 
okaaaay...

because of this...DefaultView.[0]?

-Coco

[auto]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top