|
|
|
start date: Mon, 20 Aug 2007 23:18:40 -0400,
posted on: microsoft.public.dotnet.framework.aspnet
back
| Thread Index |
|
1
Monty am
|
|
2
(Walter Wang [MSFT])
|
|
3
Monty am
|
|
4
(Walter Wang [MSFT])
|
'System.Data.DataRowView' does not contain a property with the name 'ID'.
[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.
Date:Mon, 20 Aug 2007 23:18:40 -0400
Author:
|
RE: 'System.Data.DataRowView' does not contain a property with the name 'ID'.
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 (wawang@online.microsoft.com, 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.
Date:Tue, 21 Aug 2007 08:41:40 GMT
Author:
|
Re: 'System.Data.DataRowView' does not contain a property with the name 'ID'.
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.
""Walter Wang [MSFT]"" wrote in message
news:OrdVg884HHA.2340@TK2MSFTNGHUB02.phx.gbl...
> 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 (wawang@online.microsoft.com, 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.
>
Date:Tue, 21 Aug 2007 10:59:48 -0400
Author:
|
Re: 'System.Data.DataRowView' does not contain a property with the name 'ID'.
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 (wawang@online.microsoft.com, 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.
Date:Wed, 22 Aug 2007 09:12:35 GMT
Author:
|
|
|