Hi Phillip.
Your code is a major step forward, thanks again. The binding (of the
SelectedValue) for the DropDownLists was missing, so I have added that. I've
also improved the NULL handling (which was implemented as UNIONs in the SQL
select statements to work around limitations of ASP.NET Beta 2) now that
AppendDataBoundItems works properly, see the revised code below.
Editing the dependent DropDownList (DDL2E) works well. However, attempts to
change the product (DDL1I) fail, even if the same dependent value is valid
for both old and new products. The error reported is similar to previously:
Server Error in '/TestWeb' Application.
--------------------------------------------------------------------------------
Databinding methods such as Eval(), XPath(), and Bind() can only be used in
the context of a databound control.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code.
Exception Details: System.InvalidOperationException: Databinding methods
such as Eval(), XPath(), and Bind() can only be used in the context of a
databound control.
A similar error is reported when inserting data also.
<asp
etailsView ID="View1" runat="Server" DataSourceID="Sql1"
DataKeyNames="ID"
DefaultMode="ReadOnly" AutoGenerateRows="false" EmptyDataText="
No record found "
AutoGenerateInsertButton="true" AutoGenerateEditButton="true"
AllowPaging="true" >
<Fields>
<asp:BoundField DataField="ID" HeaderText="Ref."
SortExpression="ID" InsertVisible="false"
ReadOnly="true" />
<asp:TemplateField HeaderText="Product Ref.">
<InsertItemTemplate>
<asp
ropDownList ID="DDL1I" runat="server"
DataSourceID="SqlProductTypeI" DataTextField="ProductRef" SelectedValue='<%#
Bind("ProductRef") %>'
DataValueField="ProductRef" AutoPostBack="true"
AppendDataBoundItems="true"><asp:ListItem></asp:ListItem></asp
ropDownList>
<asp:SqlDataSource runat="server"
ID="SqlProductTypeI"
SelectCommand="SELECT [ProductRef] FROM
[ProductType] Order by [ProductRef]"
ConnectionString="<%$ ConnectionStrings:Test %>">
</asp:SqlDataSource>
</InsertItemTemplate>
<EditItemTemplate>
<asp
ropDownList ID="DDL1E" runat="server"
DataSourceID="SqlProductTypeE" DataTextField="ProductRef" SelectedValue='<%#
Bind("ProductRef") %>'
DataValueField="ProductRef" AutoPostBack="true"
AppendDataBoundItems="true"><asp:ListItem></asp:ListItem></asp
ropDownList>
<asp:SqlDataSource runat="server"
ID="SqlProductTypeE"
SelectCommand="SELECT [ProductRef] FROM
[ProductType] Order by [ProductRef]"
ConnectionString="<%$ ConnectionStrings:Test %>">
</asp:SqlDataSource>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="ProductRef" runat="Server" Text='<%#
Bind("ProductRef") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Dependent Type">
<InsertItemTemplate>
<asp
ropDownList ID="DDL2I" runat="server"
DataSourceID="SqlDependentTypeI" DataTextField="ID" SelectedValue='<%#
Bind("DependentType") %>'
DataValueField="ID"
AppendDataBoundItems="true"><asp:ListItem></asp:ListItem></asp
ropDownList>
<asp:SqlDataSource runat="server"
ID="SqlDependentTypeI"
SelectCommand="SELECT [ID] FROM [DependentType]
WHERE [ProductRef]=@ProductRef"
ConnectionString="<%$ ConnectionStrings:Test %>">
<SelectParameters>
<asp:ControlParameter ControlID="DDL1I"
Name="ProductRef" PropertyName="SelectedValue" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
</InsertItemTemplate>
<EditItemTemplate>
<asp
ropDownList ID="DDL2E" runat="server"
DataSourceID="SqlDependentTypeE" DataTextField="ID" SelectedValue='<%#
Bind("DependentType") %>'
DataValueField="ID"
AppendDataBoundItems="true"><asp:ListItem></asp:ListItem></asp
ropDownList>
<asp:SqlDataSource runat="server"
ID="SqlDependentTypeE"
SelectCommand="SELECT [ID] FROM [DependentType]
WHERE [ProductRef]=@ProductRef"
ConnectionString="<%$ ConnectionStrings:Test %>">
<SelectParameters>
<asp:ControlParameter ControlID="DDL1E"
Name="ProductRef" PropertyName="SelectedValue" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="DependentType" runat="Server"
Text='<%# Bind("DependentType") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="DependentDetails"
HeaderText="Dependent Details" SortExpression="DependentDetails" />
</Fields>
</asp
etailsView>
<asp:SqlDataSource runat="server" ID="Sql1"
SelectCommand="SELECT [ID], [ProductRef], [DependentType],
[DependentDetails] FROM [MainTable] ORDER BY [ID] DESC"
UpdateCommand="UPDATE [MainTable] SET [ProductRef]=@ProductRef,
[DependentType]=@DependentType, [DependentDetails]=@DependentDetails WHERE
[ID] = @Original_ID"
InsertCommand="INSERT INTO [MainTable] ([ProductRef],
[DependentType], [DependentDetails]) SELECT @ProductRef, @DependentType,
@DependentDetails"
ConnectionString="<%$ ConnectionStrings:Test %>"
OldValuesParameterFormatString="Original_{0}">
<UpdateParameters>
<asp
arameter Name="ID" Type="Int32" />
<asp
arameter Name="ProductRef"
ConvertEmptyStringToNull="true" />
<asp
arameter Name="DependentType"
ConvertEmptyStringToNull="true" />
<asp
arameter Name="DependentDetails"
ConvertEmptyStringToNull="true" />
</UpdateParameters>
<InsertParameters>
<asp
arameter Name="ProductRef"
ConvertEmptyStringToNull="true" />
<asp
arameter Name="DependentType"
ConvertEmptyStringToNull="true" />
<asp
arameter Name="DependentDetails"
ConvertEmptyStringToNull="true" />
</InsertParameters>
</asp:SqlDataSource>