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>
<asparameter Name="Dim_No" Type="String" />
</DeleteParameters>
<UpdateParameters>
<asparameter Name="Shipper" Type="String" />
<asparameter Name="RMA_No" Type="String" />
<asparameter Name="Gross_Weight" Type="Int64" />
<asparameter Name="Weight_Unit" Type="String" />
<asparameter Name="Cartons" Type="Int64" />
<asparameter Name="Packages" Type="Int64" />
<asparameter Name="Total_Amount" Type="Double" />
<asparameter Name="Currency" Type="String" />
<asparameter Name="Dim_No" Type="String" />
</UpdateParameters>
<InsertParameters>
<asparameter Name="Dim_No" Type="String" />
<asparameter Name="Shipper" Type="String" />
<asparameter Name="RMA_No" Type="String" />
<asparameter Name="Gross_Weight" Type="Int64" />
<asparameter Name="Weight_Unit" Type="String" />
<asparameter Name="Cartons" Type="Int64" />
<asparameter Name="Packages" Type="Int64" />
<asparameter Name="Total_Amount" Type="Double" />
<asparameter 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>
<asparameter Name="Dim_No" Type="String" />
</DeleteParameters>
<UpdateParameters>
<asparameter Name="Shipper" Type="String" />
<asparameter Name="RMA_No" Type="String" />
<asparameter Name="Gross_Weight" Type="Int64" />
<asparameter Name="Weight_Unit" Type="String" />
<asparameter Name="Cartons" Type="Int64" />
<asparameter Name="Packages" Type="Int64" />
<asparameter Name="Total_Amount" Type="Double" />
<asparameter Name="Currency" Type="String" />
<asparameter Name="Dim_No" Type="String" />
</UpdateParameters>
<InsertParameters>
<asparameter Name="Dim_No" Type="String" />
<asparameter Name="Shipper" Type="String" />
<asparameter Name="RMA_No" Type="String" />
<asparameter Name="Gross_Weight" Type="Int64" />
<asparameter Name="Weight_Unit" Type="String" />
<asparameter Name="Cartons" Type="Int64" />
<asparameter Name="Packages" Type="Int64" />
<asparameter Name="Total_Amount" Type="Double" />
<asparameter 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>
<aspetailsView 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>
<aspropDownList ID="DropDownList4"
runat="server"
DataSourceID="SqlDataSource3"
DataTextField="Shipper_Code"
DataValueField="Shipper_Code"
SelectedValue='<%# Bind("Shipper_Code") %>'>
</aspropDownList>
</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>
</aspetailsView>
<aspropDownList ID="DropDownList3" runat="server"
DataSourceID="SqlDataSource3" DataTextField="Shipper_Code"
DataValueField="Shipper_Code">
</aspropDownList>
</form>
</body>
</html>
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>
<asparameter Name="Dim_No" Type="String" />
</DeleteParameters>
<UpdateParameters>
<asparameter Name="Shipper" Type="String" />
<asparameter Name="RMA_No" Type="String" />
<asparameter Name="Gross_Weight" Type="Int64" />
<asparameter Name="Weight_Unit" Type="String" />
<asparameter Name="Cartons" Type="Int64" />
<asparameter Name="Packages" Type="Int64" />
<asparameter Name="Total_Amount" Type="Double" />
<asparameter Name="Currency" Type="String" />
<asparameter Name="Dim_No" Type="String" />
</UpdateParameters>
<InsertParameters>
<asparameter Name="Dim_No" Type="String" />
<asparameter Name="Shipper" Type="String" />
<asparameter Name="RMA_No" Type="String" />
<asparameter Name="Gross_Weight" Type="Int64" />
<asparameter Name="Weight_Unit" Type="String" />
<asparameter Name="Cartons" Type="Int64" />
<asparameter Name="Packages" Type="Int64" />
<asparameter Name="Total_Amount" Type="Double" />
<asparameter 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>
<asparameter Name="Dim_No" Type="String" />
</DeleteParameters>
<UpdateParameters>
<asparameter Name="Shipper" Type="String" />
<asparameter Name="RMA_No" Type="String" />
<asparameter Name="Gross_Weight" Type="Int64" />
<asparameter Name="Weight_Unit" Type="String" />
<asparameter Name="Cartons" Type="Int64" />
<asparameter Name="Packages" Type="Int64" />
<asparameter Name="Total_Amount" Type="Double" />
<asparameter Name="Currency" Type="String" />
<asparameter Name="Dim_No" Type="String" />
</UpdateParameters>
<InsertParameters>
<asparameter Name="Dim_No" Type="String" />
<asparameter Name="Shipper" Type="String" />
<asparameter Name="RMA_No" Type="String" />
<asparameter Name="Gross_Weight" Type="Int64" />
<asparameter Name="Weight_Unit" Type="String" />
<asparameter Name="Cartons" Type="Int64" />
<asparameter Name="Packages" Type="Int64" />
<asparameter Name="Total_Amount" Type="Double" />
<asparameter 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>
<aspetailsView 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>
<aspropDownList ID="DropDownList4"
runat="server"
DataSourceID="SqlDataSource3"
DataTextField="Shipper_Code"
DataValueField="Shipper_Code"
SelectedValue='<%# Bind("Shipper_Code") %>'>
</aspropDownList>
</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>
</aspetailsView>
<aspropDownList ID="DropDownList3" runat="server"
DataSourceID="SqlDataSource3" DataTextField="Shipper_Code"
DataValueField="Shipper_Code">
</aspropDownList>
</form>
</body>
</html>