databinding 'system.data.datarowview' does not contain a propertywith the name

H

hon123456

Dear all,

I try to use DropDownList in DetailsView. First , I set up
a sqlDataSource which is connected to a table named "Shipper". The
table has only two fields named Shipper_Code and
Shipper_Name. When I used Edit Template to edit EditItem Template. and
try to use Edit Databinding , but the Radio Button for Binding
Selected value and other value are all disabled.

So I try to use custom binding code expression, and I type in Bind
("Shipper_Code"). But when I try to run the program to open the
Details View Editing function , it returns the following error:

databinding 'system.data.datarowview' does not contain a property with
the name "Shipper_Code"

I have double check the Database field name and found it is correct.
The following is my code:

<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>

</div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:RMAConnectionString
%>"
DeleteCommand="DELETE FROM [RMA-Detail] WHERE [Dim_No] =
@Dim_No"
InsertCommand="INSERT INTO [RMA-Detail] ([Dim_No], [Shipper],
[RMA_No], [Gross_Weight], [Weight_Unit], [Cartons], [Packages],
[Total_Amount], [Currency]) VALUES (@Dim_No, @Shipper, @RMA_No,
@Gross_Weight, @Weight_Unit, @Cartons, @Packages, @Total_Amount,
@Currency)"
SelectCommand="SELECT [Dim_No], [Shipper], [RMA_No],
[Gross_Weight], [Weight_Unit], [Cartons], [Packages], [Total_Amount],
[Currency] FROM [RMA-Detail]"
UpdateCommand="UPDATE [RMA-Detail] SET [Shipper] = @Shipper,
[RMA_No] = @RMA_No, [Gross_Weight] = @Gross_Weight, [Weight_Unit] =
@Weight_Unit, [Cartons] = @Cartons, [Packages] = @Packages,
[Total_Amount] = @Total_Amount, [Currency] = @Currency WHERE [Dim_No]
= @Dim_No">
<DeleteParameters>
<asp:parameter Name="Dim_No" Type="String" />
</DeleteParameters>
<UpdateParameters>
<asp:parameter Name="Shipper" Type="String" />
<asp:parameter Name="RMA_No" Type="String" />
<asp:parameter Name="Gross_Weight" Type="Int64" />
<asp:parameter Name="Weight_Unit" Type="String" />
<asp:parameter Name="Cartons" Type="Int64" />
<asp:parameter Name="Packages" Type="Int64" />
<asp:parameter Name="Total_Amount" Type="Double" />
<asp:parameter Name="Currency" Type="String" />
<asp:parameter Name="Dim_No" Type="String" />
</UpdateParameters>
<InsertParameters>
<asp:parameter Name="Dim_No" Type="String" />
<asp:parameter Name="Shipper" Type="String" />
<asp:parameter Name="RMA_No" Type="String" />
<asp:parameter Name="Gross_Weight" Type="Int64" />
<asp:parameter Name="Weight_Unit" Type="String" />
<asp:parameter Name="Cartons" Type="Int64" />
<asp:parameter Name="Packages" Type="Int64" />
<asp:parameter Name="Total_Amount" Type="Double" />
<asp:parameter Name="Currency" Type="String" />
</InsertParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:RMAConnectionString2
%>"
SelectCommand="SELECT * FROM [RMA-Detail] WHERE ([Dim_No] =
@Dim_No)"
DeleteCommand="DELETE FROM [RMA-Detail] WHERE [Dim_No] =
@Dim_No"
InsertCommand="INSERT INTO [RMA-Detail] ([Dim_No], [Shipper],
[RMA_No], [Gross_Weight], [Weight_Unit], [Cartons], [Packages],
[Total_Amount], [Currency]) VALUES (@Dim_No, @Shipper, @RMA_No,
@Gross_Weight, @Weight_Unit, @Cartons, @Packages, @Total_Amount,
@Currency)"
UpdateCommand="UPDATE [RMA-Detail] SET [Shipper] = @Shipper,
[RMA_No] = @RMA_No, [Gross_Weight] = @Gross_Weight, [Weight_Unit] =
@Weight_Unit, [Cartons] = @Cartons, [Packages] = @Packages,
[Total_Amount] = @Total_Amount, [Currency] = @Currency WHERE [Dim_No]
= @Dim_No">
<SelectParameters>
<asp:ControlParameter ControlID="GridView1" Name="Dim_No"
PropertyName="SelectedValue" Type="String" />
</SelectParameters>
<DeleteParameters>
<asp:parameter Name="Dim_No" Type="String" />
</DeleteParameters>
<UpdateParameters>
<asp:parameter Name="Shipper" Type="String" />
<asp:parameter Name="RMA_No" Type="String" />
<asp:parameter Name="Gross_Weight" Type="Int64" />
<asp:parameter Name="Weight_Unit" Type="String" />
<asp:parameter Name="Cartons" Type="Int64" />
<asp:parameter Name="Packages" Type="Int64" />
<asp:parameter Name="Total_Amount" Type="Double" />
<asp:parameter Name="Currency" Type="String" />
<asp:parameter Name="Dim_No" Type="String" />
</UpdateParameters>
<InsertParameters>
<asp:parameter Name="Dim_No" Type="String" />
<asp:parameter Name="Shipper" Type="String" />
<asp:parameter Name="RMA_No" Type="String" />
<asp:parameter Name="Gross_Weight" Type="Int64" />
<asp:parameter Name="Weight_Unit" Type="String" />
<asp:parameter Name="Cartons" Type="Int64" />
<asp:parameter Name="Packages" Type="Int64" />
<asp:parameter Name="Total_Amount" Type="Double" />
<asp:parameter Name="Currency" Type="String" />
</InsertParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource3" runat="server"
ConnectionString="<%$ ConnectionStrings:RMAConnectionString4
%>"
SelectCommand="SELECT DISTINCT [Shipper_Code] FROM [Shipper]">
</asp:SqlDataSource>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AutoGenerateColumns="False" DataKeyNames ="Dim_No"
DataSourceID="SqlDataSource1" Height="31px"
onselectedindexchanged="GridView1_SelectedIndexChanged">
<Columns>
<asp:CommandField ShowDeleteButton="True"
ShowSelectButton="True" />
<asp:BoundField DataField="Dim_No" HeaderText="Dim_No"
SortExpression="Dim_No" />
<asp:BoundField DataField="Shipper" HeaderText="Shipper"
SortExpression="Shipper" />
<asp:BoundField DataField="RMA_No" HeaderText="RMA_No"
SortExpression="RMA_No" />
<asp:BoundField DataField="Gross_Weight"
HeaderText="Gross_Weight"
SortExpression="Gross_Weight" />
<asp:BoundField DataField="Weight_Unit"
HeaderText="Weight_Unit"
SortExpression="Weight_Unit" />
<asp:BoundField DataField="Cartons" HeaderText="Cartons"
SortExpression="Cartons" />
<asp:BoundField DataField="Packages"
HeaderText="Packages"
SortExpression="Packages" />
<asp:BoundField DataField="Total_Amount"
HeaderText="Total_Amount"
SortExpression="Total_Amount" />
<asp:BoundField DataField="Currency"
HeaderText="Currency"
SortExpression="Currency" />
</Columns>
</asp:GridView>
<asp:DetailsView ID="DetailsView1" runat="server"
AutoGenerateRows="False"
DataKeyNames="Dim_No" DataSourceID="SqlDataSource2"
Height="50px"
Width="125px" oniteminserted="DetailsView1_ItemInserted">
<Fields>
<asp:BoundField DataField="Dim_No" HeaderText="Dim_No"
ReadOnly="True"
SortExpression="Dim_No" />
<asp:TemplateField HeaderText="Shipper"
SortExpression="Shipper">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList4"
runat="server"
DataSourceID="SqlDataSource3"
DataTextField="Shipper_Code"
DataValueField="Shipper_Code"
SelectedValue='<%# Bind("Shipper_Code") %>'>

</asp:DropDownList>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<
%# Bind("Shipper") %>'></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%#
Bind("Shipper") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="RMA_No" HeaderText="RMA_No"
SortExpression="RMA_No" />
<asp:BoundField DataField="Gross_Weight"
HeaderText="Gross_Weight"
SortExpression="Gross_Weight" />
<asp:BoundField DataField="Weight_Unit"
HeaderText="Weight_Unit"
SortExpression="Weight_Unit" />
<asp:BoundField DataField="Cartons" HeaderText="Cartons"
SortExpression="Cartons" />
<asp:BoundField DataField="Packages"
HeaderText="Packages"
SortExpression="Packages" />
<asp:BoundField DataField="Total_Amount"
HeaderText="Total_Amount"
SortExpression="Total_Amount" />
<asp:BoundField DataField="Currency"
HeaderText="Currency"
SortExpression="Currency" />
<asp:CommandField ShowEditButton="True"
ShowInsertButton="True" />
</Fields>
</asp:DetailsView>
<asp:DropDownList ID="DropDownList3" runat="server"
DataSourceID="SqlDataSource3" DataTextField="Shipper_Code"
DataValueField="Shipper_Code">
</asp:DropDownList>
</form>
</body>
</html>
 
C

Coskun Sunali [MVP]

Hi,

The data you bind to the DropDownList is assigned to each ListItem
respectively when the DataBind event occurs. However, you are trying to use
"Bind" within the "EditItemTemplate" of the DetailsView. That means that
ASP.NET is looking for that field within the DataItem assigned to the
DetailsView by SqlDataSource2. And SqlDataSource2 does not have such a field
called "Shipper_Code".

--
Coskun Sunali
Microsoft MVP - ASP.NET
http://sunali.com
http://propeople.dk

hon123456 said:
Dear all,

I try to use DropDownList in DetailsView. First , I set up
a sqlDataSource which is connected to a table named "Shipper". The
table has only two fields named Shipper_Code and
Shipper_Name. When I used Edit Template to edit EditItem Template. and
try to use Edit Databinding , but the Radio Button for Binding
Selected value and other value are all disabled.

So I try to use custom binding code expression, and I type in Bind
("Shipper_Code"). But when I try to run the program to open the
Details View Editing function , it returns the following error:

databinding 'system.data.datarowview' does not contain a property with
the name "Shipper_Code"

I have double check the Database field name and found it is correct.
The following is my code:

<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>

</div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:RMAConnectionString
%>"
DeleteCommand="DELETE FROM [RMA-Detail] WHERE [Dim_No] =
@Dim_No"
InsertCommand="INSERT INTO [RMA-Detail] ([Dim_No], [Shipper],
[RMA_No], [Gross_Weight], [Weight_Unit], [Cartons], [Packages],
[Total_Amount], [Currency]) VALUES (@Dim_No, @Shipper, @RMA_No,
@Gross_Weight, @Weight_Unit, @Cartons, @Packages, @Total_Amount,
@Currency)"
SelectCommand="SELECT [Dim_No], [Shipper], [RMA_No],
[Gross_Weight], [Weight_Unit], [Cartons], [Packages], [Total_Amount],
[Currency] FROM [RMA-Detail]"
UpdateCommand="UPDATE [RMA-Detail] SET [Shipper] = @Shipper,
[RMA_No] = @RMA_No, [Gross_Weight] = @Gross_Weight, [Weight_Unit] =
@Weight_Unit, [Cartons] = @Cartons, [Packages] = @Packages,
[Total_Amount] = @Total_Amount, [Currency] = @Currency WHERE [Dim_No]
= @Dim_No">
<DeleteParameters>
<asp:parameter Name="Dim_No" Type="String" />
</DeleteParameters>
<UpdateParameters>
<asp:parameter Name="Shipper" Type="String" />
<asp:parameter Name="RMA_No" Type="String" />
<asp:parameter Name="Gross_Weight" Type="Int64" />
<asp:parameter Name="Weight_Unit" Type="String" />
<asp:parameter Name="Cartons" Type="Int64" />
<asp:parameter Name="Packages" Type="Int64" />
<asp:parameter Name="Total_Amount" Type="Double" />
<asp:parameter Name="Currency" Type="String" />
<asp:parameter Name="Dim_No" Type="String" />
</UpdateParameters>
<InsertParameters>
<asp:parameter Name="Dim_No" Type="String" />
<asp:parameter Name="Shipper" Type="String" />
<asp:parameter Name="RMA_No" Type="String" />
<asp:parameter Name="Gross_Weight" Type="Int64" />
<asp:parameter Name="Weight_Unit" Type="String" />
<asp:parameter Name="Cartons" Type="Int64" />
<asp:parameter Name="Packages" Type="Int64" />
<asp:parameter Name="Total_Amount" Type="Double" />
<asp:parameter Name="Currency" Type="String" />
</InsertParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:RMAConnectionString2
%>"
SelectCommand="SELECT * FROM [RMA-Detail] WHERE ([Dim_No] =
@Dim_No)"
DeleteCommand="DELETE FROM [RMA-Detail] WHERE [Dim_No] =
@Dim_No"
InsertCommand="INSERT INTO [RMA-Detail] ([Dim_No], [Shipper],
[RMA_No], [Gross_Weight], [Weight_Unit], [Cartons], [Packages],
[Total_Amount], [Currency]) VALUES (@Dim_No, @Shipper, @RMA_No,
@Gross_Weight, @Weight_Unit, @Cartons, @Packages, @Total_Amount,
@Currency)"
UpdateCommand="UPDATE [RMA-Detail] SET [Shipper] = @Shipper,
[RMA_No] = @RMA_No, [Gross_Weight] = @Gross_Weight, [Weight_Unit] =
@Weight_Unit, [Cartons] = @Cartons, [Packages] = @Packages,
[Total_Amount] = @Total_Amount, [Currency] = @Currency WHERE [Dim_No]
= @Dim_No">
<SelectParameters>
<asp:ControlParameter ControlID="GridView1" Name="Dim_No"
PropertyName="SelectedValue" Type="String" />
</SelectParameters>
<DeleteParameters>
<asp:parameter Name="Dim_No" Type="String" />
</DeleteParameters>
<UpdateParameters>
<asp:parameter Name="Shipper" Type="String" />
<asp:parameter Name="RMA_No" Type="String" />
<asp:parameter Name="Gross_Weight" Type="Int64" />
<asp:parameter Name="Weight_Unit" Type="String" />
<asp:parameter Name="Cartons" Type="Int64" />
<asp:parameter Name="Packages" Type="Int64" />
<asp:parameter Name="Total_Amount" Type="Double" />
<asp:parameter Name="Currency" Type="String" />
<asp:parameter Name="Dim_No" Type="String" />
</UpdateParameters>
<InsertParameters>
<asp:parameter Name="Dim_No" Type="String" />
<asp:parameter Name="Shipper" Type="String" />
<asp:parameter Name="RMA_No" Type="String" />
<asp:parameter Name="Gross_Weight" Type="Int64" />
<asp:parameter Name="Weight_Unit" Type="String" />
<asp:parameter Name="Cartons" Type="Int64" />
<asp:parameter Name="Packages" Type="Int64" />
<asp:parameter Name="Total_Amount" Type="Double" />
<asp:parameter Name="Currency" Type="String" />
</InsertParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource3" runat="server"
ConnectionString="<%$ ConnectionStrings:RMAConnectionString4
%>"
SelectCommand="SELECT DISTINCT [Shipper_Code] FROM [Shipper]">
</asp:SqlDataSource>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AutoGenerateColumns="False" DataKeyNames ="Dim_No"
DataSourceID="SqlDataSource1" Height="31px"
onselectedindexchanged="GridView1_SelectedIndexChanged">
<Columns>
<asp:CommandField ShowDeleteButton="True"
ShowSelectButton="True" />
<asp:BoundField DataField="Dim_No" HeaderText="Dim_No"
SortExpression="Dim_No" />
<asp:BoundField DataField="Shipper" HeaderText="Shipper"
SortExpression="Shipper" />
<asp:BoundField DataField="RMA_No" HeaderText="RMA_No"
SortExpression="RMA_No" />
<asp:BoundField DataField="Gross_Weight"
HeaderText="Gross_Weight"
SortExpression="Gross_Weight" />
<asp:BoundField DataField="Weight_Unit"
HeaderText="Weight_Unit"
SortExpression="Weight_Unit" />
<asp:BoundField DataField="Cartons" HeaderText="Cartons"
SortExpression="Cartons" />
<asp:BoundField DataField="Packages"
HeaderText="Packages"
SortExpression="Packages" />
<asp:BoundField DataField="Total_Amount"
HeaderText="Total_Amount"
SortExpression="Total_Amount" />
<asp:BoundField DataField="Currency"
HeaderText="Currency"
SortExpression="Currency" />
</Columns>
</asp:GridView>
<asp:DetailsView ID="DetailsView1" runat="server"
AutoGenerateRows="False"
DataKeyNames="Dim_No" DataSourceID="SqlDataSource2"
Height="50px"
Width="125px" oniteminserted="DetailsView1_ItemInserted">
<Fields>
<asp:BoundField DataField="Dim_No" HeaderText="Dim_No"
ReadOnly="True"
SortExpression="Dim_No" />
<asp:TemplateField HeaderText="Shipper"
SortExpression="Shipper">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList4"
runat="server"
DataSourceID="SqlDataSource3"
DataTextField="Shipper_Code"
DataValueField="Shipper_Code"
SelectedValue='<%# Bind("Shipper_Code") %>'>

</asp:DropDownList>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<
%# Bind("Shipper") %>'></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%#
Bind("Shipper") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="RMA_No" HeaderText="RMA_No"
SortExpression="RMA_No" />
<asp:BoundField DataField="Gross_Weight"
HeaderText="Gross_Weight"
SortExpression="Gross_Weight" />
<asp:BoundField DataField="Weight_Unit"
HeaderText="Weight_Unit"
SortExpression="Weight_Unit" />
<asp:BoundField DataField="Cartons" HeaderText="Cartons"
SortExpression="Cartons" />
<asp:BoundField DataField="Packages"
HeaderText="Packages"
SortExpression="Packages" />
<asp:BoundField DataField="Total_Amount"
HeaderText="Total_Amount"
SortExpression="Total_Amount" />
<asp:BoundField DataField="Currency"
HeaderText="Currency"
SortExpression="Currency" />
<asp:CommandField ShowEditButton="True"
ShowInsertButton="True" />
</Fields>
</asp:DetailsView>
<asp:DropDownList ID="DropDownList3" runat="server"
DataSourceID="SqlDataSource3" DataTextField="Shipper_Code"
DataValueField="Shipper_Code">
</asp:DropDownList>
</form>
</body>
</html>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,962
Messages
2,570,134
Members
46,692
Latest member
JenniferTi

Latest Threads

Top