I have a DropDownList inside a FormView. When I enter the Edit mode and attempt to make a selection the selection reverts back to the original value due to enabling AutoPostBack. If I set AutoPostBack to false then the value stays. But I have a TextBox that needs to display the selected value as soon as it's selected, so I think I need the AutoPostBack to be True. How can I keep the selected value in the DropDownList while at the same time displaying the newly selected value OnSelectedIndexChanged?
Here's the FormView markup:
<asp:FormView runat="server"
ID="fvPhaudDets"
DataSourceID="sdsFvPhaudDets"
DataKeyNames="Id"
OnItemUpdated="fvPhaudDets_OnItemUpdated"
OnItemDeleted="fvPhaudDets_OnItemDeleted"
OnDataBound="fvPhaudDets_OnDataBound"
OnItemCommand="fvPhaudDets_OnItemCommand">
<ItemTemplate>
<h3>Details</h3>
<div class="row">
<div class="col-xs-12 col-sm-1 col-md-1 col-lg-1 form-group">
<strong>ID</strong><br />
<asp:Label Text='<%# Eval("Id") %>' runat="server" ID="IdLabel" CssClass="form-control" />
</div>
<div class="row">
<div class="col-xs-12 col-sm-9 col-md-10 col-lg-10 form-group">
<asp:Label ID="qQOpClsCallLbl" runat="server" AssociatedControlID="QOpClsCallLabel" Text="Did the representative open and close the call appropriately?*"></asp:Label>
</div>
<div class="col-xs-12 col-sm-3 col-md-2 col-lg-2 form-group">
<asp:Label Text='<%# Bind("QOpClsCallScore") %>' runat="server" ID="QOpClsCallLabel" CssClass="form-control text-center" />
</div>
</div>
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 form-group">
<asp:LinkButton runat="server" Text="Edit" CommandName="Edit" ID="EditButton" CausesValidation="False" CssClass="btn btn-primary" />
</div>
</div>
</ItemTemplate>
<EditItemTemplate>
<h3>Editing</h3>
<div class="row">
<div class="col-xs-12 col-sm-1 col-md-1 col-lg-1 form-group">
<strong>ID</strong><br />
<asp:Label Text='<%# Eval("Id") %>' runat="server" ID="IdLabel1" CssClass="form-control" BackColor="#f5deb3" />
</div>
<div class="row">
<div class="col-xs-12 col-sm-9 col-md-10 col-lg-10 form-group">
<asp:Label ID="qQOpClsCallLbl" runat="server" AssociatedControlID="QOpClsCallDdl" Text="Did the representative open and close the call appropriately?*"></asp:Label>
</div>
<div class="col-xs-12 col-sm-3 col-md-2 col-lg-2 form-group">
<asp:DropDownList SelectedValue='<%# Bind("QOpClsCall") %>' runat="server" ID="QOpClsCallDdl" AutoPostBack="True" DataSourceID="sdsScrGrp1" CssClass="form-control text-center" AppendDataBoundItems="True" DataTextField="Score" DataValueField="Id" OnSelectedIndexChanged="QOpClsCallTextBox_OnSelectedIndexChanged" />
</div>
</div>
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 form-group">
<asp:LinkButton runat="server" Text="Update" CommandName="Update" ID="UpdateButton" CausesValidation="True" CssClass="btn btn-success" OnClick="UpdateButton_OnClick" />
<asp:LinkButton runat="server" Text="Cancel" CommandName="Cancel" ID="UpdateCancelButton" CausesValidation="False" CssClass="btn btn-danger" />
</div>
</div>
</EditItemTemplate>
</asp:FormView>
Here's the data source for the DropDownList:
<asp:SqlDataSource
ID="sdsScrGrp1"
runat="server"
ConnectionString='<%$ ConnectionStrings:DefaultConnection %>'
SelectCommand="SELECT Id, Score FROM [SgScores] WHERE ScoreGroupId = 3">
</asp:SqlDataSource>
Here's the code for the OnSelectedIndexChanged event:
protected void QOpClsCallTextBox_OnSelectedIndexChanged(object sender, EventArgs e)
{
DropDownList opscall = fvPhaudDets.FindControl("QOpClsCallDdl") as DropDownList;
q1.Text = opscall.SelectedValue;
GetScore();
}