troubleshooting Question

Formview Values Disappear

Avatar of DEWebWorks
DEWebWorks asked on
ASP.NETVisual Basic.NET
2 Comments1 Solution794 ViewsLast Modified:
Hi all,

I've been fighting with this formview control all day. In editmode, I have a combo box and a couple of radiobuttonlist items. I finally have them populating correctly and when I click the save button, those items disappear from my update query. I've had a similar problem before and fought it so long that I finally just made a form and manually bound the data. Surely, that's not the right answer. Previously, I tried to manually add those parameters back to my updateParameters list, but when I do, all of my other items disappear. If I have to manually add all of my parameters, then why do I even have a formview control???

Below is my code. Any help is greatly appreciated.

ASPX page:
<asp:FormView runat="server" ID="frmShareClass" DataSourceID="dsShareClass" Width="100%" DataKeyNames="shareClassID, feederFundID">
            <table width="100%" class="SalesDeskItem">
                <td valign="top" width="50%">
                    <table width="100%">
                        <td class="SalesDeskLabel">Share Class Name:</td>
                        <td class="SalesDeskItem"><telerik:RadTextBox runat="server" ID="txtShareClassName" Text='<%# Bind("shareClassName") %>' /></td>
                        <td class="SalesDeskLabel">Minimum Initial Investment:</td>
                        <td class="SalesDeskItem"><telerik:RadNumericTextBox runat="server" ID="txtMinimumInitialInvestment" Text='<%# Bind("minimumInitialInvestment")%>' /></td>
                        <td class="SalesDeskLabel">Minimum Additional Investment:</td>
                        <td class="SalesDeskItem"><telerik:RadNumericTextBox runat="server" ID="txtMinimumAdditionalInvestment" Text='<%# Bind("minimumAdditionalInvestment")%>' /></td>
                        <td class="SalesDeskLabel">Accepting New Investments:</td>
                        <td class="SalesDeskItem">
                            <asp:RadioButtonList runat="server" ID="cboAcceptingNewInvestments" RepeatDirection="Horizontal" SelectedValue='<%# Bind("acceptingNewInvestments")%>'>
                                <asp:ListItem Value="True" Text="Yes" />
                                <asp:ListItem Value="False" Text="No" />
                            <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator2" ControlToValidate="cboAcceptingNewInvestments" ErrorMessage="Accepting New Investments" Text="Please choose Yes or No" />
                        <td class="SalesDeskLabel">Currency:</td>
                        <td class="SalesDeskItem">
                            <asp:RadioButtonList runat="server" ID="cboCurrency" RepeatDirection="Horizontal">
                                <asp:ListItem Value="Dollar" Text="Dollar $" />
                                <asp:ListItem Value="Euro" Text="Euro €" />
                                <asp:ListItem Value="Yen" Text="Yen ¥" />
                                <asp:ListItem Value="Pound" Text="Pound £" />

    <asp:SqlDataSource runat="server" ID="dsShareClass" 
        SelectCommandType="StoredProcedure" SelectCommand="sp_Funds_Feeder_Share_Class" 
        UpdateCommandType="StoredProcedure" UpdateCommand="sp_Funds_Feeder_Share_Class">
            <asp:Parameter Name="Action" DefaultValue="SELECT" />
            <asp:QueryStringParameter Name="shareClassID" QueryStringField="shareClassID" />
            <asp:Parameter Name="Action" DefaultValue="UPDATE" />
            <asp:CookieParameter Name="lastUpdatedBy" CookieName="userName" />
            <asp:Parameter Name="holdbackPercentage" Type="Decimal" />
            <asp:Parameter Name="gatePercentage" Type="Decimal" />
            <asp:Parameter Name="minimumInitialInvestment" Type="Decimal" />
            <asp:Parameter Name="minimumAdditionalInvestment" Type="Decimal" />
    </asp:SqlDataSource> codebehind:
Protected Sub frmShareClass_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles frmShareClass.DataBound

        If frmShareClass.CurrentMode = FormViewMode.Edit Then

            '--- load the radcombo box
            Dim cboRedemptionFrequency As RadComboBox
            cboRedemptionFrequency = frmShareClass.FindControl("cboRedemptionFrequency")

            '--- select from the database
            Dim redemptionFrequency As String = CType(DataBinder.Eval(cboRedemptionFrequency.BindingContainer, "DataItem.redemptionFrequency").ToString, String)

            Dim theIndex As Integer

            theIndex = cboRedemptionFrequency.Items.FindItemIndexByText(redemptionFrequency)
            If IsNumeric(theIndex) Then
                cboRedemptionFrequency.SelectedIndex = theIndex
            End If

            Dim theListItem As ListItem

            '--- load currency item from db
            Dim cboCurrency As RadioButtonList
            cboCurrency = frmShareClass.FindControl("cboCurrency")
            Dim currency As String = CType(DataBinder.Eval(cboCurrency.BindingContainer, "DataItem.currency").ToString, String)

            theListItem = cboCurrency.Items.FindByValue(currency)
            If theListItem IsNot Nothing Then
                theListItem.Selected = True
                theListItem = Nothing
            End If

            '--- load high water mark
            Dim cboHighWaterMark As RadioButtonList
            cboHighWaterMark = frmShareClass.FindControl("cboHighWaterMark")
            Dim highWaterMark As Boolean = CType(DataBinder.Eval(cboHighWaterMark.BindingContainer, "DataItem.highWaterMark"), Boolean)
            theListItem = cboHighWaterMark.Items.FindByValue(highWaterMark)
            If theListItem IsNot Nothing Then
                theListItem.Selected = True
                theListItem = Nothing
            End If

            '--- load clawback
            Dim cboClawback As RadioButtonList
            cboClawback = frmShareClass.FindControl("cboClawback")
            Dim clawback As Boolean = CType(DataBinder.Eval(cboClawback.BindingContainer, "DataItem.clawback"), Boolean)
            theListItem = cboClawback.Items.FindByValue(clawback)
            If theListItem IsNot Nothing Then
                theListItem.Selected = True
                theListItem = Nothing
            End If

        End If

    End Sub
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 2 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros