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

  • Thread starter Thread starter hon123456
  • Start date Start date
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>
 
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>
 
Back
Top