'System.Data.DataRowView' does not contain a property with the name 'ID'.

  • Thread starter Thread starter Monty
  • Start date Start date
M

Monty

[ASP.Net 2005]

Hi, I have a grid like so:
<asp:GridView ID="grdItemActivity" runat="server" ><Columns>

<asp:BoundField DataField="TransactionType" HeaderText="Type"
ReadOnly="True" />

<asp:BoundField DataField="DocumentNumber" HeaderText="Doc. No."
ReadOnly="True" />

<asp:BoundField DataField="Location" HeaderText="Location" ReadOnly="True"
/>

<asp:BoundField DataField="Quantity" HeaderText="Qty" ReadOnly="True" />

<asp:BoundField DataField="QuantityOnOrder" HeaderText="Committed"
ReadOnly="True" />

<asp:BoundField DataField="AmountPerUnit" HeaderText="Cost/Unit"
ReadOnly="True" />

<asp:BoundField DataField="DateAdded" HeaderText="Added" ReadOnly="True" />

<asp:BoundField DataField="DateModified" HeaderText="Modified"
ReadOnly="True" />

</Columns></asp:GridView>

Which I bind like so:

Dim oDS As System.Data.DataSet = Item.GetItemActivity(miItemID, Param1,
Param2)
grdItemActivity.DataSource = oDS '[have also tried: oDS.Tables(0) ]
grdItemActivity.DataBind()

On the DataBind(), I receive the error message "System.Data.DataRowView'
does not contain a property with the name 'ID'." That is correct, the
results don't have a field called "ID", but I'm not referencing any field
called ID in my GridView. WTH? I also tried removing ALL columns and setting
autogeneratecolumns = true, but I still get the same exact error. What am I
missing? TIA.
 
Hi Monty,

Please check if your GridView's declaration has specified property
"DataKeyNames", for example:

<asp:GridView ID="GridView1" DataKeyNames="ID" runat="server" ...


The fields specified in DataKeyNames will also be retrieved from data
source.

If this is not the case, I might need more code or a complete reproducible
project to further test this. Thanks.

Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
When I first created the grid I'd copied it from another grid and it did
have the value "DataKeyNames=ID", so I tried changing it to the name of the
correct key field (DataKeyNames="ItemID") and it gave me the same error
message, looking for the field "ID" (not "ItemID"). So I deleted the grid
and started from scratch (with nothing specified for the DataKeyNames
property) and still got the same error. So I removed all the columns and set
AutoGenerateColumns=True, like so:

<asp:GridView ID="grdItemActivity" runat="server" AutoGenerateColumns=true
/>

In this case it would run without error, but there was no grid created. So I
interrogated the DataSet object in the immediate pane at the time of
databinding to make sure it had values, and it does:

?oDS.Tables(0).Rows.Count
25
?oDS.Tables(0).Rows(3).Item(0)
3 {Integer}
?oDS.Tables(0).Rows(3).Item(2)
8 {Integer}
?oDS.Tables(0).Rows(3).Item(5)
20D {Decimal}

I also tried setting the datasource of the GridView to the specific Data
Table, but no luck:
grdItemActivity.DataSource = oDS.Tables(0)

The code for the binding looks like so:

Dim oDS As System.Data.DataSet = Item.GetItemActivity(miItemID, P1, P2)
grdItemActivity.DataSource = oDS '[also tried: oDS.Tables(0) ]
grdItemActivity.DataBind()

I could try using a DataSourceObject, but since this is just a read-only
list of items I was trying to avoid the overhead involved with it.

Thanks Walter.
 
Also note that if I do it as a repeater control rather than a gridview, it
works fine. It just seems to be with a GridView...

This works (though I'd rather have a gridview):

<asp:Repeater ID="Repeater1" runat="server"
Visible="true">
<HeaderTemplate>
<table>
<tr>
<th>Type</th>
<th>Doc. No.</th>
<th>Location</th>
<th>Qty</th>
<th>Created</th>
<th>Modified</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><%#Eval("TransactionType") %></td>
<td><%#Eval("DocumentNumber") %></td>
<td><%#Eval("Location") %></td>
<td align="right"><%#Eval("Quantity",
"{0:c}") %></td>
<td><%#Eval("DateAdded") %></td>
<td><%#Eval("DateModified") %></td>
</tr>
</ItemTemplate>
<footertemplate>
</table>
</footertemplate>
</asp:Repeater>
 
Hi Monty,

Unless you're substituting the built-in GridView control with a custom
GridView control in web.config via configuration such as:


<pages>
<tagMapping>
<add tagType="System.Web.UI.WebControls.GridView"
mappedTagType="myns.EmptyGridView,App_Code"/>
</tagMapping>
</pages>
</system.web>


I must say this is very strange since your code looks very clean and
simple.

Can you create a new WebForm, add a GridView, then bind it to a manually
created DataTable to see if it works:

DataTable dt = new DataTable();
dt.Columns.Add("Code");
dt.Rows.Add("code1");
GridView1.DataSource = dt;
GridView1.DataBind();


I'm also wondering if it can be reproduced on my side. Would you please
send me a copy of the code? Thanks.


Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Well, I created a new project, added a new grid, and copied over the
procedure that retrieves the data from the database and... it worked
perfectly. Same procedure, same database, everthing. So, I created a new,
simple blank page ~in my existing project~ and tried again and got the same
error. If I don't specify any columns and set autogeneratecolumns=true then
I do not receive an error, but there is no grid created. If I specify even a
single column (like below), I get this error message:

DataBinding: 'System.Data.DataRowView' does not contain a property with the
name 'ID'.

That's correct, there is no "ID" column, but who is looking for one?

<asp:GridView ID="GridView1" runat="server" DataKeyNames="ItemID" >
<Columns>
<asp:BoundField DataField=DateModified />
</Columns>
</asp:GridView>

Anyway, I've been able to jerry-rig a grid by using a repeater control, and
I think I'm just going to have to run with that for a while... unless you
have any last thoughts on it? Thanks.
 
OK, I think I figured it out. In my Theme/Skin for the project, I've defined
a gridview (template) with css style tags, etc. One of the attributes set on
that gridview in my skin is 'DataKeyNames="ID"'. I guess the property in the
Skin is not being overridden by the property set on the actual GridView.
Shouldn't it be?
 
Hi Monty,

Thanks very much for your information. I haven't thought about the skin
files.

According to the MSDN library:

#ASP.NET Themes and Skins Overview
http://msdn2.microsoft.com/en-us/library/ykzx33wh(VS.80).aspx
<quote>
If a control setting is defined in both the control and the theme, the
control settings from the theme override any page settings on the control.
This strategy enables the theme to create a consistent look across pages,
even if controls on the pages already have individual property settings.
</quote>

This means the setting in a skin file will override setting on the control.

Thanks again for sharing your experience here. This will sure benefit the
community.


Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi, I am also encountering the same problem too. I too look at the skin.css but it nevers mention anything. I am still getting that error.In the grid view, I named the Datakeysname as: termsID(exact as my database col) as I need to make use of this such that when I insert a new records into the database,it will automatically increment. And i also needs it for delete and updating of records since my termsID will not be displayed in the grid view.May i know how to resolve it? It gt to do with my stored procedure and database.cs? I am using C# btw,thks!
[ASP.Net 2005]

Hi, I have a grid like so:
<asp:GridView ID="grdItemActivity" runat="server" ><Columns>

<asp:BoundField DataField="TransactionType" HeaderText="Type"
ReadOnly="True" />

<asp:BoundField DataField="DocumentNumber" HeaderText="Doc. No."
ReadOnly="True" />

<asp:BoundField DataField="Location" HeaderText="Location" ReadOnly="True"
/>

<asp:BoundField DataField="Quantity" HeaderText="Qty" ReadOnly="True" />

<asp:BoundField DataField="QuantityOnOrder" HeaderText="Committed"
ReadOnly="True" />

<asp:BoundField DataField="AmountPerUnit" HeaderText="Cost/Unit"
ReadOnly="True" />

<asp:BoundField DataField="DateAdded" HeaderText="Added" ReadOnly="True" />

<asp:BoundField DataField="DateModified" HeaderText="Modified"
ReadOnly="True" />

</Columns></asp:GridView>

Which I bind like so:

Dim oDS As System.Data.DataSet = Item.GetItemActivity(miItemID, Param1,
Param2)
grdItemActivity.DataSource = oDS '[have also tried: oDS.Tables(0) ]
grdItemActivity.DataBind()

On the DataBind(), I receive the error message "System.Data.DataRowView'
does not contain a property with the name 'ID'." That is correct, the
results don't have a field called "ID", but I'm not referencing any field
called ID in my GridView. WTH? I also tried removing ALL columns and setting
autogeneratecolumns = true, but I still get the same exact error. What am I
missing? TIA.
On Tuesday, August 21, 2007 4:41 AM wawan wrote:
Hi Monty,

Please check if your GridView's declaration has specified property
"DataKeyNames", for example:

<asp:GridView ID="GridView1" DataKeyNames="ID" runat="server" ...


The fields specified in DataKeyNames will also be retrieved from data
source.

If this is not the case, I might need more code or a complete reproducible
project to further test this. Thanks.

Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
On Tuesday, August 21, 2007 10:59 AM Monty wrote:
When I first created the grid I'd copied it from another grid and it did
have the value "DataKeyNames=ID", so I tried changing it to the name of the
correct key field (DataKeyNames="ItemID") and it gave me the same error
message, looking for the field "ID" (not "ItemID"). So I deleted the grid
and started from scratch (with nothing specified for the DataKeyNames
property) and still got the same error. So I removed all the columns and set
AutoGenerateColumns=True, like so:

<asp:GridView ID="grdItemActivity" runat="server" AutoGenerateColumns=true
/>

In this case it would run without error, but there was no grid created. So I
interrogated the DataSet object in the immediate pane at the time of
databinding to make sure it had values, and it does:

?oDS.Tables(0).Rows.Count
25
?oDS.Tables(0).Rows(3).Item(0)
3 {Integer}
?oDS.Tables(0).Rows(3).Item(2)
8 {Integer}
?oDS.Tables(0).Rows(3).Item(5)
20D {Decimal}

I also tried setting the datasource of the GridView to the specific Data
Table, but no luck:
grdItemActivity.DataSource = oDS.Tables(0)

The code for the binding looks like so:

Dim oDS As System.Data.DataSet = Item.GetItemActivity(miItemID, P1, P2)
grdItemActivity.DataSource = oDS '[also tried: oDS.Tables(0) ]
grdItemActivity.DataBind()

I could try using a DataSourceObject, but since this is just a read-only
list of items I was trying to avoid the overhead involved with it.

Thanks Walter.


news:[email protected]...
 
Back
Top