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!

Binding this data to a datagrid

Status
Not open for further replies.

Kalisto

Programmer
Joined
Feb 18, 2003
Messages
997
Location
GB
The code below fails, but I cannot see why. In debug mode, the data is all present and correct in my dataset, but all other fields in my html work.

can anyone see whats up ?

My Query is
Code:
string strCommand = "Select r.pkRoom, r.nRoomNumber, r.strRoomName, rate.curRate, r.nSleeps,r.strDescription, ";
strCommand += "r.blEnsuite, r.blDisabled, r.strType from ";
strCommand+= "tblRooms r join tblRates rate on r.nRate = rate.pkRate";

my offending html is
Code:
<ItemTemplate>
  <asp:Label id="curRate" Runat="server" text='<% DataBinder.Eval(Container,"DataItem.curRate") %>'/>
</ItemTemplate>

I can look at the colums attribute of my datatable, and there is a column called curRate in there.

But when I execure the code, I get an error at the HTML
The Error says
DataBinder.Eval: 'System.Data.Common.DbDataRecord' does not contain a property with the name curRate.

This is doing my head in, please someone help me so I can go home and get to the pub before it closes !

K

 
Hi:

Use this instead of what u have written:

<ItemTemplate>
<asp:Label id="curRate" Runat="server" text='<% DataBinder.Eval(Container.DataItem,"curRate") %>'/>
</ItemTemplate>

I think this should work

Cheers

RB
 
Nope, that don't work either.

what property in the Datasource should contain the names (in case I am wrong in my assumption that it is right ?
 
You need the databinding # sign in there:

<%# CType(Container.DataItem, DataRowView)("curRate") %>

That's assuming your DataSource is a DataTable.

If it's a DataReader, then the CType object type should be IDataRecord, and so on.

You should avoid using DataBinder.Eval whenever possible to avoid the Late Binding performance penalty.

Some Google info on that:

Good Luck!

-p

penny.gif
penny.gif

The answer to getting answered -- faq855-2992
 
So my html is now

<asp:Label id="curRate" Runat="server" text='<%#IDataRecord.Item(Container.DataItem, DataRowView)("curRate") %>'/>

and I get Compiler Error Message: Compiler Error Message: CS0103: The name 'DataRowView' does not exist in the class or namespace 'ASP.RoomAdmin_aspx'

Apologies for being a pain, but I don't have any books, and have never been on a training course on any of this, so it's all self taught
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top