• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4008
  • Last Modified:

SelectedValue is empty in DropDownList when updating in EditItemTemplate of FormView

I have a formview where data is entered.  Within the formview's InsertItemTemplate a DropDownList is populated from an EntityDataSource.  I fill out the form with all values and select Insert(linkbutton).  The data is inserted appropriately and then I have the mode changed to ReadOnly(ItemTemplate).  The formview is set to have edit capabilities.  When I click Edit the formview sends me to the EditItemTemplate with all of the correct data in the fields, including the DropDownList.  Whether I make a different selection or leave the selection as is and select Update, an error is thrown because there is no value in the SelectedValue property of the DropDownList: <Error while setting property 'AG_ddl_Reviewer.ReviewerID': ' is not a valid value for Int32.'.>  

What is happening is the dropdownlist is losing it's value's(SelectedValue, DataValue, TextValue) when it changes to the EditItemTemplate, however, it displays the DataTextFields in the DropDownList appropriately.  I even traced this in the ItemUpdating event(Please See Attached ScreenShot).  How can I fix this?  
0
Kyle_BCBSLA
Asked:
Kyle_BCBSLA
  • 7
  • 4
  • 2
2 Solutions
 
tcullerCommented:
The only thing I can think of off the top of my head is to directly inherit from and override the original class. As always there are other ways of doing this, but I recommend at least giving the following a shot:

    public class zDropDownList : System.Web.UI.WebControls.DropDownList
    {
        // ... Your other code ...
 
        private System.Web.UI.WebControls.ListItem _currentValue;
 
        public System.Object CurrentValue
        {
            get { return _currentValue; }
            set { /*Add code to change the actual selected value to maintain consistency, or make this field read-only and omit this part.*/ }
        }
        protected override void OnSelectedIndexChanged(System.EventArgs evArgs)
        {
            this._currentValue = this.SelectedItem;
            base.OnSelectedIndexChanged(evArgs);
        }
    }

Open in new window

0
 
dacITCommented:
I run into this sort of thing with the viewstate is disabled. Have you looked at that?
0
 
Kyle_BCBSLAAuthor Commented:
dacIT: EnableViewState = true on both the dropdownlist control and the formview.  

Take a look at question ID "24369736".  I have all of the code that I have there.  See if you guys can make any sense of this.  

tculler: I will try your suggestion tomorrow morning when I get back into the office.  I'm not quite understanding what you are trying to do there.  

Thanks to both of you for suggestions!  
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Kyle_BCBSLAAuthor Commented:
tculler: I can really use your help!  I cannot figure out what you were attempting to suggest above.  Below you will find my .aspx code for the FormView.  It includes the insert, edit, and readOnly templates.  The DropDownLists exist in both the insert and edit templates.  

Can you see anything that can be wrong with this setup?  Another suggestion would be great!  
<asp:FormView ID="fv_NewProgression" runat="server" AllowPaging="True" DataKeyNames="ProgressionID"
                DataSourceID="eds_NewProgressionEntry" Visible="False" OnDataBound="fv_NewProgression_DataBound"
                OnItemUpdating="fv_NewProgression_ItemUpdating" OnItemInserting="fv_NewProgression_ItemInserting">
                <EditItemTemplate>
                    <table>
                        <tr>
                            <th style="text-align: right; width: 150px;">
                                &nbsp;Response ID:
                            </th>
                            <td style="width: 350px;">
                                <asp:TextBox ID="ResponseIDEditTextBox" runat="server" Enabled="False" Text='<%# Eval("ResponseID") %>'
                                    Width="175px" />
                            </td>
                            <th style="text-align: right; width: 150px;">
                                Sent to Adjuster:
                            </th>
                            <td style="width: 350px;">
                                <asp:CheckBox Enabled="true" ID="SentToAdjusterCheckBox" runat="server" Checked='<%# Bind("SentToAdjuster") %>' />
                            </td>
                        </tr>
                        <tr>
                            <th style="text-align: right; width: 150px;">
                                Case Closed:
                            </th>
                            <td style="width: 350px;">
                                <asp:CheckBox ID="ProgressionStatus_flgCheckBox" runat="server" Checked='<%# Bind("ProgressionStatus_flg") %>'
                                    Enabled="True" />
                            </td>
                            <th style="text-align: right; width: 150px;">
                                Date Sent:
                            </th>
                            <td style="width: 350px;">
                                <asp:TextBox Width="175px" ID="SentToAdjuster_dtTextBox" runat="server" Text='<%# Bind("SentToAdjuster_dt", "{0:d}") %>'
                                    Enabled="True" />
                                <cc1:CalendarExtender ID="SentToAdjuster_dtTextBox_CalendarExtender" runat="server"
                                    Enabled="True" TargetControlID="SentToAdjuster_dtTextBox">
                                </cc1:CalendarExtender>
                                &nbsp;
                                <asp:RegularExpressionValidator ID="validFormat_SentToAdjuster_dt" runat="server"
                                    ControlToValidate="SentToAdjuster_dtTextBox" ErrorMessage="*mm/dd/yyyy" Font-Bold="True"
                                    Font-Size="Large" SetFocusOnError="True" ValidationExpression="(0?[1-9]|1[012])[- /.](0?[1-9]|[12][0-9]|3[01])[- /.](19\d\d|20\d\d)"
                                    Display="Dynamic"></asp:RegularExpressionValidator>
                                <asp:CustomValidator ID="valid_SentToAdjuster_dt" runat="server" ErrorMessage="*Invalid Date"
                                    ControlToValidate="SentToAdjuster_dtTextBox" Display="Dynamic" ClientValidationFunction="validateNotFutureDate"
                                    Font-Bold="True" Font-Size="Large"></asp:CustomValidator>
                            </td>
                        </tr>
                        <tr>
                            <th style="text-align: right; width: 150px;">
                                Sequence ID:
                            </th>
                            <td style="width: 350px;">
                                <asp:TextBox ID="SeqIDTextBox" runat="server" Text='<%# Eval("SeqID") %>' Width="175px"
                                    Enabled="False" />
                            </td>
                            <th style="text-align: right; width: 150px;">
                                Completion Date:
                            </th>
                            <td style="width: 350px;">
                                <asp:TextBox Width="175px" ID="AdjusterComplete_dtTextBox" runat="server" Text='<%# Bind("AdjusterComplete_dt", "{0:d}") %>' />
                                <cc1:CalendarExtender ID="AdjusterComplete_dtTextBox_CalendarExtender" runat="server"
                                    Enabled="True" TargetControlID="AdjusterComplete_dtTextBox">
                                </cc1:CalendarExtender>
                                &nbsp;
                                <asp:RegularExpressionValidator ID="validFormat_AdjusterComplete_dt" runat="server"
                                    ControlToValidate="SentToAdjuster_dtTextBox" ErrorMessage="*mm/dd/yyyy" Font-Bold="True"
                                    Font-Size="Large" SetFocusOnError="True" ValidationExpression="(0?[1-9]|1[012])[- /.](0?[1-9]|[12][0-9]|3[01])[- /.](19\d\d|20\d\d)"
                                    Display="Dynamic"></asp:RegularExpressionValidator>
                                <asp:CustomValidator ID="valid_AdjusterComplete_dt" runat="server" ErrorMessage="*Invalid Date"
                                    ControlToValidate="AdjusterComplete_dtTextBox" ser Display="Dynamic" ClientValidationFunction="validateNotFutureDate"
                                    Font-Bold="True" Font-Size="Large"></asp:CustomValidator>
                            </td>
                        </tr>
                        <tr>
                            <th style="text-align: right; width: 150px;">
                                Reviewer:
                            </th>
                            <td style="width: 350px;">
                                <asp:DropDownList ID="ddl_ReviewerList_Edit" runat="server" 
                                    Width="181px" DataSourceID="eds_ReviewerList" DataTextField="Reviewer_desc" 
                                    DataValueField="ReviewerID" 
                                    SelectedValue='<%# Bind("AG_ddl_Reviewer.ReviewerID") %>' AutoPostBack="False">
                                </asp:DropDownList>
                                &nbsp;&nbsp;<asp:RequiredFieldValidator ID="valid_Reviewer" runat="server" ErrorMessage="*Required"
                                    Font-Size="Large" ControlToValidate="ddl_ReviewerList_Edit" InitialValue="Select"
                                    SetFocusOnError="True" Display="Dynamic" Font-Bold="True"></asp:RequiredFieldValidator>
                            </td>
                            <th style="text-align: right; width: 150px;">
                                Response Letter:
                            </th>
                            <td style="width: 350px;">
                                <asp:TextBox Width="175px" ID="ResponseLetter_dtTextBox" runat="server" Text='<%# Bind("ResponseLetter_dt", "{0:d}") %>' />
                                <cc1:CalendarExtender ID="ResponseLetter_dtTextBox_CalendarExtender" runat="server"
                                    Enabled="True" TargetControlID="ResponseLetter_dtTextBox">
                                </cc1:CalendarExtender>
                                &nbsp;
                                <asp:RegularExpressionValidator ID="validFormat_ResponseLetter_dt" runat="server"
                                    ControlToValidate="SentToAdjuster_dtTextBox" ErrorMessage="*mm/dd/yyyy" Font-Bold="True"
                                    Font-Size="Large" SetFocusOnError="True" ValidationExpression="(0?[1-9]|1[012])[- /.](0?[1-9]|[12][0-9]|3[01])[- /.](19\d\d|20\d\d)"
                                    Display="Dynamic"></asp:RegularExpressionValidator>
                                <asp:CustomValidator ID="valid_ResponseLetter_dt" runat="server" ErrorMessage="*Invalid Date"
                                    ControlToValidate="ResponseLetter_dtTextBox" Display="Dynamic" ClientValidationFunction="validateNotFutureDate"
                                    Font-Bold="True" Font-Size="Large"></asp:CustomValidator>
                            </td>
                        </tr>
                        <tr>
                            <th style="text-align: right; width: 150px;">
                                Decision:
                            </th>
                            <td style="width: 350px;">
                                <asp:DropDownList ID="ddl_Decision_Edit" runat="server" Width="181px" 
                                    SelectedValue='<%# Bind("AG_ddl_Decision.DecisionID") %>' DataSourceID="eds_NewProgressionEntry_Decision"
                                    DataTextField="Decision_desc" DataValueField="DecisionID">
                                </asp:DropDownList>
                                &nbsp;
                                <asp:Label ID="valid_decision_label" runat="server" Font-Bold="True" Font-Size="Large"
                                    ForeColor="Red" Text="*Required" Visible="False"></asp:Label>
                            </td>
                            <th style="text-align: right; width: 150px;">
                                Appeal Receipt Date:
                            </th>
                            <td style="width: 350px;">
                                <asp:TextBox Width="175px" ID="AppealReceipt_dtTextBox" runat="server" Text='<%# Eval("AppealReceipt_dt", "{0:d}") %>'
                                    Enabled="False" />
                            </td>
                        </tr>
                        <tr>
                            <th style="text-align: right; width: 150px;">
                                Comments:
                            </th>
                            <td colspan="3" style="width: 350px;">
                                <asp:TextBox ID="CommentTextBox" runat="server" Wrap="true" TextMode="MultiLine"
                                    Width="675px" Height="102px" Text='<%# Bind("Comment") %>' />
                            </td>
                        </tr>
                        <tr>
                            <td colspan="4" style="text-align: center;">
                                <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update"
                                    Text="Update" />
                                &nbsp;<asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False"
                                    CommandName="Cancel" Text="Cancel" />
                            </td>
                        </tr>
                    </table>
                </EditItemTemplate>
                <InsertItemTemplate>
                    <table>
                        <tr>
                            <th style="text-align: right; width: 150px;">
                                Response ID:
                            </th>
                            <td style="width: 350px;">
                                <asp:TextBox ID="ResponseIDTextBox" runat="server" Enabled="False" Text='<%# Bind("ResponseID") %>'
                                    Width="175px" OnDataBinding="ResponseIDTextBox_DataBinding" />
                            </td>
                            <th style="text-align: right; width: 150px;">
                                Sent to Adjuster:
                            </th>
                            <td style="width: 350px;">
                                <asp:CheckBox CausesValidation="true" ID="SentToAdjusterCheckBox" runat="server"
                                    Checked='<%# Bind("SentToAdjuster") %>' />
                            </td>
                        </tr>
                        <tr>
                            <th style="text-align: right; width: 150px;">
                                Case Closed:
                            </th>
                            <td style="width: 350px;">
                                <asp:CheckBox ID="ProgressionStatus_flgCheckBox" runat="server" Checked='<%# Bind("ProgressionStatus_flg") %>' />
                            </td>
                            <th style="text-align: right; width: 150px;">
                                Date Sent:
                            </th>
                            <td style="width: 350px;">
                                <asp:TextBox Width="175px" ID="SentToAdjuster_dtTextBox" runat="server" Text='<%# Bind("SentToAdjuster_dt") %>' />
                                <cc1:CalendarExtender ID="SentToAdjuster_dtTextBox_CalendarExtender" runat="server"
                                    Enabled="True" TargetControlID="SentToAdjuster_dtTextBox">
                                </cc1:CalendarExtender>
                                &nbsp;
                                <asp:RegularExpressionValidator ID="validFormat_SentToAdjuster_dt" runat="server"
                                    ControlToValidate="SentToAdjuster_dtTextBox" ErrorMessage="*mm/dd/yyyy" Font-Bold="True"
                                    Font-Size="Large" SetFocusOnError="True" ValidationExpression="(0?[1-9]|1[012])[- /.](0?[1-9]|[12][0-9]|3[01])[- /.](19\d\d|20\d\d)"
                                    Display="Dynamic"></asp:RegularExpressionValidator>
                                <asp:CustomValidator ID="required_SentToAdjuster_dt" runat="server" ErrorMessage="*Required"
                                    ControlToValidate="SentToAdjuster_dtTextBox" ClientValidationFunction="validateSentToAdjuster_dt"
                                    Display="Dynamic" ValidateEmptyText="True" Font-Bold="True" Font-Size="Large"></asp:CustomValidator>
                                <asp:CustomValidator ID="valid_SentToAdjuster_dt" runat="server" ErrorMessage="*Invalid Date"
                                    ControlToValidate="SentToAdjuster_dtTextBox" Display="Dynamic" ClientValidationFunction="validateNotFutureDate"
                                    Font-Bold="True" Font-Size="Large"></asp:CustomValidator>
                            </td>
                        </tr>
                        <tr>
                            <th style="text-align: right; width: 150px;">
                                Sequence ID:
                            </th>
                            <td style="width: 350px;">
                                <asp:TextBox ID="SeqIDTextBox" runat="server" Text='<%# Bind("SeqID") %>' Width="175px" />
                                &nbsp;<%--<asp:RequiredFieldValidator ID="valid_SeqID" runat="server" ControlToValidate="SeqIDTextBox"
                                    Display="Dynamic" ErrorMessage="*Required" Font-Bold="True" Font-Size="Large"></asp:RequiredFieldValidator>--%>
                                <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ErrorMessage="*Numeric Only"
                                    ControlToValidate="SeqIDTextBox" Display="Dynamic" Font-Bold="True" Font-Size="Large"
                                    ValidationExpression="^[0-9]*$"></asp:RegularExpressionValidator>
                            </td>
                            <th style="text-align: right; width: 150px;">
                                Completion Date:
                            </th>
                            <td style="width: 350px;">
                                <asp:TextBox Width="175px" ID="AdjusterComplete_dtTextBox" runat="server" Text='<%# Bind("AdjusterComplete_dt") %>' />
                                <cc1:CalendarExtender ID="AdjusterComplete_dtTextBox_CalendarExtender" runat="server"
                                    Enabled="True" TargetControlID="AdjusterComplete_dtTextBox">
                                </cc1:CalendarExtender>
                                &nbsp;
                                <asp:RegularExpressionValidator ID="validFormat_AdjusterComplete_dt" runat="server"
                                    ControlToValidate="AdjusterComplete_dtTextBox" ErrorMessage="*mm/dd/yyyy" Font-Bold="True"
                                    Font-Size="Large" ValidationExpression="(0?[1-9]|1[012])[- /.](0?[1-9]|[12][0-9]|3[01])[- /.](19\d\d|20\d\d)"
                                    Display="Dynamic"></asp:RegularExpressionValidator>
                                <asp:CustomValidator ID="valid_AdjusterComplete_dt" runat="server" ErrorMessage="*Invalid Date"
                                    ControlToValidate="AdjusterComplete_dtTextBox" Display="Dynamic" ClientValidationFunction="validateNotFutureDate"
                                    Font-Bold="True" Font-Size="Large"></asp:CustomValidator>
                            </td>
                        </tr>
                        <tr>
                            <th style="text-align: right; width: 150px;">
                                Reviewer:
                            </th>
                            <td style="width: 350px;">
                                <asp:DropDownList ID="ddl_ReviewerList" runat="server" DataSourceID="eds_ReviewerList"
                                    Width="181px" DataTextField="Reviewer_desc" DataValueField="ReviewerID" SelectedValue='<%# Bind("AG_ddl_Reviewer.ReviewerID") %>'
                                    OnDataBound="ddl_ReviewerList_DataBound">
                                </asp:DropDownList>
                                &nbsp;&nbsp;<asp:RequiredFieldValidator ID="valid_Reviewer" runat="server" ErrorMessage="*Required"
                                    Font-Size="Large" ControlToValidate="ddl_ReviewerList" InitialValue="Select"
                                    SetFocusOnError="True" Display="Dynamic" Font-Bold="True"></asp:RequiredFieldValidator>
                            </td>
                            <th style="text-align: right; width: 150px;">
                                Response Letter:
                            </th>
                            <td style="width: 350px;">
                                <asp:TextBox Width="175px" ID="ResponseLetter_dtTextBox" runat="server" Text='<%# Bind("ResponseLetter_dt") %>' />
                                <cc1:CalendarExtender ID="ResponseLetter_dtTextBox_CalendarExtender" runat="server"
                                    Enabled="True" TargetControlID="ResponseLetter_dtTextBox">
                                </cc1:CalendarExtender>
                                &nbsp;
                                <asp:RegularExpressionValidator ID="validFormat_ResponseLetter_dt" runat="server"
                                    ControlToValidate="ResponseLetter_dtTextBox" ErrorMessage="*mm/dd/yyyy" Font-Bold="True"
                                    Font-Size="Large" ValidationExpression="(0?[1-9]|1[012])[- /.](0?[1-9]|[12][0-9]|3[01])[- /.](19\d\d|20\d\d)"
                                    Display="Dynamic"></asp:RegularExpressionValidator>
                                <asp:CustomValidator ID="valid_ResponseLetter_dt" runat="server" ErrorMessage="*Invalid Date"
                                    ControlToValidate="ResponseLetter_dtTextBox" Display="Dynamic" ClientValidationFunction="validateNotFutureDate"
                                    Font-Bold="True" Font-Size="Large"></asp:CustomValidator>
                            </td>
                        </tr>
                        <tr>
                            <th style="text-align: right; width: 150px;">
                                Decision:
                            </th>
                            <td style="width: 350px;">
                                <asp:DropDownList ID="ddl_Decision" runat="server" DataSourceID="eds_NewProgressionEntry_Decision"
                                    DataTextField="Decision_desc" DataValueField="DecisionID" Width="181px" SelectedValue='<%# Bind("AG_ddl_Decision.DecisionID") %>'
                                    OnDataBound="ddl_Decision_DataBound">
                                </asp:DropDownList>
                                &nbsp;
                                <asp:Label ID="valid_decision_label" runat="server" Font-Bold="True" Font-Size="Large"
                                    ForeColor="Red" Text="*Invalid Decision" Visible="False"></asp:Label>
                                <asp:RequiredFieldValidator ID="valid_SeqID0" runat="server" ControlToValidate="ddl_Decision"
                                    Display="Dynamic" ErrorMessage="*Required" Font-Bold="True" Font-Size="Large"
                                    InitialValue="Select"></asp:RequiredFieldValidator>
                            </td>
                            <th style="text-align: right; width: 150px;">
                                Appeal Receipt Date:
                            </th>
                            <td style="width: 350px;">
                                <asp:TextBox CausesValidation="true" Width="175px" ID="AppealReceipt_dtTextBox" runat="server"
                                    Text='<%# Bind("AppealReceipt_dt") %>' />
                                <cc1:CalendarExtender ID="AppealReceipt_dtTextBox_CalendarExtender" runat="server"
                                    Enabled="True" TargetControlID="AppealReceipt_dtTextBox">
                                </cc1:CalendarExtender>
                                &nbsp;
                                <asp:RegularExpressionValidator ID="validFormat_AppealReceipt_dt" runat="server"
                                    ControlToValidate="AppealReceipt_dtTextBox" ErrorMessage="*mm/dd/yyyy" Font-Bold="True"
                                    Font-Size="Large" ValidationExpression="(0?[1-9]|1[012])[- /.](0?[1-9]|[12][0-9]|3[01])[- /.](19\d\d|20\d\d)"
                                    Display="Dynamic"></asp:RegularExpressionValidator>
                                <asp:RequiredFieldValidator ID="required_AppealReceipt" runat="server" ControlToValidate="AppealReceipt_dtTextBox"
                                    ErrorMessage="*Required" Font-Bold="True" Font-Size="Large" Display="Dynamic"></asp:RequiredFieldValidator>
                                <asp:CustomValidator ID="valid_AppealReceipt_dt" runat="server" ErrorMessage="*Invalid Date"
                                    ControlToValidate="AppealReceipt_dtTextBox" Display="Dynamic" ClientValidationFunction="validateNotFutureDate"
                                    Font-Bold="True" Font-Size="Large"></asp:CustomValidator>
                            </td>
                        </tr>
                        <tr>
                            <th style="text-align: right; width: 150px;">
                                Comments:
                            </th>
                            <td colspan="3" style="width: 350px;">
                                <asp:TextBox ID="CommentTextBox" runat="server" Wrap="true" TextMode="MultiLine"
                                    Width="675px" Height="102px" Text='<%# Bind("Comment") %>' />
                            </td>
                        </tr>
                        <tr>
                            <td colspan="4" align="center">
                                <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert"
                                    Text="Insert" />
                                &nbsp;<asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False"
                                    CommandName="Cancel" Text="Cancel" />
                                <cc1:ConfirmButtonExtender ID="InsertCancelButton_ConfirmButtonExtender" runat="server"
                                    ConfirmText="Are you sure you want to Cancel? All form entries will be lost!"
                                    Enabled="True" TargetControlID="InsertCancelButton">
                                </cc1:ConfirmButtonExtender>
                            </td>
                        </tr>
                    </table>
                </InsertItemTemplate>
                <ItemTemplate>
                    <table>
                        <tr>
                            <th style="text-align: right; width: 150px;">
                                Response ID:
                            </th>
                            <td style="width: 350px;">
                                <asp:Label ID="ResponseIDLabel" runat="server" Text='<%# Bind("ResponseID") %>' />
                            </td>
                            <th style="text-align: right; width: 150px;">
                                Sent to Adjuster:
                            </th>
                            <td style="width: 350px;">
                                <asp:CheckBox ID="SentToAdjusterCheckBox" runat="server" Checked='<%# Bind("SentToAdjuster") %>'
                                    Enabled="false" />
                            </td>
                        </tr>
                        <tr>
                            <th style="text-align: right; width: 150px;">
                                Case Closed:
                            </th>
                            <td style="width: 350px;">
                                <asp:CheckBox ID="ProgressionStatus_flgCheckBox" runat="server" Checked='<%# Bind("ProgressionStatus_flg") %>'
                                    Enabled="false" />
                            </td>
                            <th style="text-align: right; width: 150px;">
                                Date Sent:
                            </th>
                            <td style="width: 350px;">
                                <asp:Label ID="SentToAdjuster_dtLabel" runat="server" Text='<%# Bind("SentToAdjuster_dt", "{0:d}") %>' />
                            </td>
                        </tr>
                        <tr>
                            <th style="text-align: right; width: 150px;">
                                Sequence ID:
                            </th>
                            <td style="width: 350px;">
                                <asp:Label ID="SeqIDLabel" runat="server" Text='<%# Bind("SeqID") %>' />
                            </td>
                            <th style="text-align: right; width: 150px;">
                                Completion Date:
                            </th>
                            <td style="width: 350px;">
                                <asp:Label ID="AdjusterComplete_dtLabel" runat="server" Text='<%# Bind("AdjusterComplete_dt", "{0:d}") %>' />
                            </td>
                        </tr>
                        <tr>
                            <th style="text-align: right; width: 150px;">
                                Reviewer:
                            </th>
                            <td style="width: 350px;">
                                <asp:Label ID="AG_ddl_ReviewerLabel" runat="server" Text='<%# Bind("AG_ddl_Reviewer.Reviewer_desc") %>' />
                            </td>
                            <th style="text-align: right; width: 150px;">
                                Response Letter:
                            </th>
                            <td style="width: 350px;">
                                <asp:Label ID="ResponseLetter_dtLabel" runat="server" Text='<%# Bind("ResponseLetter_dt", "{0:d}") %>' />
                            </td>
                        </tr>
                        <tr>
                            <th style="text-align: right; width: 150px;">
                                Decision:
                            </th>
                            <td style="width: 350px;">
                                <asp:Label ID="AG_ddl_DecisionLabel" runat="server" Text='<%# Bind("AG_ddl_Decision.Decision_desc") %>' />
                            </td>
                            <th style="text-align: right; width: 150px;">
                                Appeal Receipt Date:
                            </th>
                            <td style="width: 350px;">
                                <asp:Label ID="AppealReceipt_dtLabel" runat="server" Text='<%# Bind("AppealReceipt_dt", "{0:d}") %>' />
                            </td>
                        </tr>
                        <tr>
                            <th style="text-align: right; width: 150px;">
                                Comments:
                            </th>
                            <td colspan="3" style="width: 350px;">
                                <asp:TextBox ID="TextBox2" runat="server" Wrap="true" BackColor="Silver" TextMode="MultiLine"
                                    Width="675px" Text='<%# Bind("Comment") %>' Height="102px" ReadOnly="True" />
                            </td>
                        </tr>
                        <tr>
                            <th style="text-align: right; width: 150px;">
                                Last Updated:
                            </th>
                            <td style="width: 350px;">
                                <asp:Label ID="LastUpdate_dtLabel" runat="server" Text='<%# Bind("LastUpdate_dt", "{0:d}") %>' />
                            </td>
                            <th style="text-align: right; width: 150px;">
                                Entered By:
                            </th>
                            <td style="width: 350px;">
                                <asp:Label ID="UpdatedByLabel" runat="server" Text='<%# Bind("UpdatedBy") %>' />
                            </td>
                        </tr>
                        <tr>
                            <td colspan="4" style="text-align: center;">
                                <asp:LinkButton ID="btn_NewProgression" runat="server" CausesValidation="True" CommandName="New">New</asp:LinkButton>
                                &nbsp;<asp:LinkButton ID="btn_EditProgression" runat="server" CausesValidation="true"
                                    CommandName="Edit">Edit</asp:LinkButton>
                            </td>
                        </tr>
                    </table>
                </ItemTemplate>
                <PagerSettings Position="Top" />
            </asp:FormView>
            <asp:EntityDataSource ID="eds_NewProgressionEntry_Decision" runat="server" ConnectionString="name=AppealsEntities"
                DefaultContainerName="AppealsEntities" EntitySetName="AG_ddl_Decision" EntityTypeFilter="AG_ddl_Decision"
                Where="it.DisplayStatus_flg = true">
            </asp:EntityDataSource>
            <asp:EntityDataSource ID="eds_ReviewerList" runat="server" ConnectionString="name=AppealsEntities"
                DefaultContainerName="AppealsEntities" EntitySetName="AG_ddl_Reviewer" Where="it.DisplayStatus_flg = true">
            </asp:EntityDataSource>

Open in new window

0
 
tcullerCommented:
What I am suggesting is happening is what we call a race-condition. Because using windows Forms employs the use of threading so heavily, I'm guessing the values are being destroyed and/or changed unexpectedly by other threads. My code is simply overriding the event responsible for changing the selected value, and storing it BEFORE invoking the base implementation, hopefully maintaining a reliable reference to the actually selected object.

Honestly, I've never really used ASP.NET, but I am an expert in C# Programming. As far as I can see, there is nothing wrong with your ASP.NET code, though I am no expert in that particular area.
0
 
Kyle_BCBSLAAuthor Commented:
Okay guys.  I have a workaround...  It is not exactly the functionality that I need but it is at least working.  What I did was "DISABLE" the ViewState.  I have a good feeling that there may be a problem with entity datasources.  My DropDownList(child to formview) is bound to an EntityDataSource.  The parent FormView control is also bound to an EntityDataSource.  It seems that I can keep track of multiple ViewStates that are bound to more than one EntityDataSource, but this is also what is causing my DropDownList control to lose it's values.  

Now, with ViewState disabled, when I get to the Item_Updating event I can find the DropDownList control and get it's selected value.  For whatever reason, I have to manually pull the selected value out and force it through because the Bind() does not work.  I get the following error: "Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control."  What is odd is that the DropDownList control is bound to the EntityDataSource, but I think it may seem like it isn't bound because it is not tracking ViewState.  Nonetheless, I have the code workaround below for pulling the proper value out of the DropDownList.  

The functionality that I am losing is that when I move from the ItemTemplate to the EditItemTemplate the DropDownList reverts back to index 0 because I cannot use Bind() for 2-way databinding...  Any ideas?  

Thanks for your much needed assistance!  :)    
//DropDownList Control  ".aspx"
//As you will notice below, my Bind() is commented out
<asp:DropDownList ID="ddl_ReviewerList_Edit" runat="server" 
                                    Width="181px" DataSourceID="eds_ReviewerList" DataTextField="Reviewer_desc" 
                                    DataValueField="ReviewerID" EnableViewState="False">
                                    <%--SelectedValue='<%# Bind("AG_ddl_Reviewer.ReviewerID") %>'>--%> 
                                </asp:DropDownList>
 
//Item_Updating Event  ".cs"
//As you can see below, I tried to get the old value.  Since viewstate is disabled 
//the old value is not kept in memory which is why I have it commented out.  
protected void fv_NewProgression_ItemUpdating(object sender, FormViewUpdateEventArgs e)
        {
            DropDownList reviewer = (DropDownList)fv_NewProgression.FindControl("ddl_ReviewerList_Edit");
 
            //string a = e.OldValues["AG_ddl_Reviewer.ReviewerID"].ToString();
 
            e.NewValues["AG_ddl_Reviewer.ReviewerID"] = reviewer.SelectedValue;
        }

Open in new window

0
 
dacITCommented:
You probably already know this, but with bound controls and no viewstate, you can manually load the data into the control in the page_init event. Then the "selected" will work properly after the page loads since the values are already in the control now. The viewstate is where it normally gets the control's list of values, then it does binding or selecting just before rendering.
0
 
Kyle_BCBSLAAuthor Commented:
I did not exactly know that, however, I do understand it.  Yet, the data is populating the DropDownList and it always did properly.  What happened was it would lose the "SelectedValue" when ItemUpdating.  With ViewState disabled it does not, but when loading the EditTemplate the DropDownList does not remember the selectedvalue because now I cannot use the SelectedValue = '<%# Bind("ReviewerID") %>'  functionality for 2-way databinding.  This causes the user to make a new selection from the dropdownlist every time they choose to update the record.  
0
 
dacITCommented:
I suspect that your data for the drop down list is being populated after the Init event which is why the selected value isn't working. Check to see when it gets it's data, and if possible change that to the init event it should work for you.
0
 
Kyle_BCBSLAAuthor Commented:
Guys:

Just to update you.  I have been working on this issue.  I think that my best route will be to figure out a way to manipulate the values by storing the value I need in a session variable and passing it into the ddl control's SelectedValue property in the prerender event.  I will keep you posted as this moves forward and post a final solution.  

Thanks for all of your help!  
-Kyle
0
 
Kyle_BCBSLAAuthor Commented:
I solved it.  I will post the solution tomorrow.  I'm going home!  WooHoo!
0
 
Kyle_BCBSLAAuthor Commented:
First thing that you need to do is add a hiddenLabel field on your ItemTemplate.  Make sure that the field is set to visible, otherwise, you cannot get the value out of the bound field(it will be hidden in the code behind).
---------------------------------------------------------------------------------
<asp:Label ID="AG_ddl_DecisionLabel" runat="server" Text='<%# Bind("AG_ddl_Decision.Decision_desc") %>' />
<asp:Label ID="hiddenDecisionID" runat="server" Text='<%# Bind("AG_ddl_Decision.DecisionID") %>' onprerender="hiddenDecisionID_PreRender" />
---------------------------------------------------------------------------------
As you can see, these are both labels that are visible on my form.  They are both binding to the Decision.  However, the reason I have 2 is because the value that I need is the DecisionID which is the SelectedValue for my DropDownList.  Using the hiddenDecisionID label I can now pull this value.  Please notice the event being called is the onprerender.  I found that after the page has been rendered there seems to be no event that can be used to pull the value out of the label's text field when the 'EDIT' button is clicked.  The prerender event is called after all controls have been bound, but before the page is visible by the user.  So, in the hiddenDecisionID control's prerender event I can now grab the value from the label and store it into a variable.  In this case I am using Session variables which I think I will ultimately store it in Cache.  See the code below...
---------------------------------------------------------------------------------
        protected void hiddenDecisionID_PreRender(object sender, EventArgs e)
        {
            Session["DecisionID"] = ((Label)sender).Text;    //Store text value into Session Variable
            ((Label)sender).Visible = false;   //HIDE the label
        }
---------------------------------------------------------------------------------
I now have a variable that I can use to pass that value to the EditItemTemplate.  Again, I want my control to be bound before I tell it what value to display as being selected so I add a prerender event for the DropDownList that exists in the EditItemTemplate.  This event sets the DDL's SelectedValue to the Session Variables value displaying the appropriate value that was rendered in the ItemTemplate.  
---------------------------------------------------------------------------------
protected void ddl_Decision_PreRender(object sender, EventArgs e)
        {
            ((DropDownList)sender).SelectedValue = Session["DecisionID"].ToString();
        }
---------------------------------------------------------------------------------
And finally, most importantly...  Since I am now tracking the values for the DDL control and not the formview, I will need to tell it what value was selected and manually force the update.  Here is where it is done, in the formview's ItemUpdating event:
---------------------------------------------------------------------------------
        protected void fv_NewProgression_ItemUpdating(object sender, FormViewUpdateEventArgs e)
        {
            DropDownList decision = (DropDownList)fv_NewProgression.FindControl("ddl_Decision");
            e.NewValues["AG_ddl_Decision.DecisionID"] = decision.SelectedValue;
        }
---------------------------------------------------------------------------------
NOTE: For creating and using Session Variables you must create a Global.asax page.  In the Session Start event is where you create your variable.  I set it to NULL initially because I have not given it a value until what is posted above...  See below:
---------------------------------------------------------------------------------
protected void Session_Start(object sender, EventArgs e)
        {
            Session["DecisionID"] = null;
        }
       
---------------------------------------------------------------------------------
---------------------------------------------------------------------------------

Although this is sort of a work-around, it is the only effective way of getting this scenario to work properly.  I hope this is helpful for others that encounter this problem.  Good Luck!  
------------------------.ASPX PAGE------------------------
<asp:Label ID="AG_ddl_DecisionLabel" runat="server" Text='<%# Bind("AG_ddl_Decision.Decision_desc") %>' />
<asp:Label ID="hiddenDecisionID" runat="server" Text='<%# Bind("AG_ddl_Decision.DecisionID") %>' onprerender="hiddenDecisionID_PreRender" />
 
 
 
------------------------.CS PAGE------------------------
        protected void fv_NewProgression_ItemUpdating(object sender, FormViewUpdateEventArgs e)
        {
            DropDownList reviewer = (DropDownList)fv_NewProgression.FindControl("ddl_ReviewerList");
            DropDownList decision = (DropDownList)fv_NewProgression.FindControl("ddl_Decision");
 
            //string a = e.OldValues["AG_ddl_Reviewer.ReviewerID"].ToString();
            //string b = e.NewValues["AG_ddl_Reviewer.ReviewerID"].ToString();
 
            e.NewValues["AG_ddl_Reviewer.ReviewerID"] = reviewer.SelectedValue;
            e.NewValues["AG_ddl_Decision.DecisionID"] = decision.SelectedValue;
            e.NewValues["UpdatedBy"] = User.Identity.Name.ToString().Substring(7);
            e.NewValues["LastUpdate_dt"] = DateTime.Now.ToString();
        }
 
        protected void ddl_Decision_PreRender(object sender, EventArgs e)
        {
            ((DropDownList)sender).SelectedValue = Session["DecisionID"].ToString();
        }
 
        protected void hiddenDecisionID_PreRender(object sender, EventArgs e)
        {
            Session["DecisionID"] = ((Label)sender).Text;
            ((Label)sender).Visible = false;
        }

Open in new window

0
 
dacITCommented:
Good job!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 7
  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now