I have the following code in my aspx page
<
body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
DataSourceID="SqlDataSource1" DataTextField="PageName" DataValueField="HTML"
OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" >
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:GenericCMSConnectionString %>"
SelectCommand="SELECT [PageName], [HTML] FROM [T_Pages]"
DeleteCommand="DELETE FROM [T_Pages] WHERE [PageName] = @PageName"
InsertCommand="INSERT INTO [T_Pages] ([PageName], [HTML]) VALUES (@PageName, @HTML)"
UpdateCommand="UPDATE [T_Pages] SET [HTML] = @HTML WHERE [PageName] = @PageName">
<DeleteParameters>
<asp:Parameter Name="PageName" Type="String" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="HTML" Type="String" />
<asp:Parameter Name="PageName" Type="String" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="PageName" Type="String" />
<asp:Parameter Name="HTML" Type="String" />
</InsertParameters>
</asp:SqlDataSource>
<CE:Editor ID="Editor1" runat="server"
OnPostBackCommand="Editor1_PostBackCommand">
</CE:Editor>
</div>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</form>
and this code in the code behind
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
Editor1.Text = DropDownList1.SelectedItem.Value;
Label1.Text =
"Working on...." + DropDownList1.SelectedItem.Text;
}
protected void Editor1_PostBackCommand(object sender, CommandEventArgs e)
{
this.SqlDataSource1.UpdateParameters["PageName"].DefaultValue = DropDownList1.SelectedItem.Text;
this.SqlDataSource1.UpdateParameters["HTML"].DefaultValue = Editor1.Text;
this.SqlDataSource1.Update();
//this.SqlDataSource1.UpdateParameters.Clear();
this.Label1.Text = "saved to...." + DropDownList1.SelectedItem.Text;
}
Problem:
When the user hits the save button on the CuteEditor the dropdownlist always returns to the top item on the list. When I was developing, I didn't notice the problem because I was only saving at the end of my changes. However, when my wife started testing the system she would make little changes and then hit save and make another change and hit save (saving her work incrementally as she goes). The problem is that if you are not carefully, when you hit save the second time you are saving the work back to another page (the top page of the dropdownlist).
Question: Why is the dropdownlist returning back to SelectedItem index 0? What would be the best approach to stop this?