Help with DropDownList controlling FormView

Discussion in 'ASP .Net' started by David C, Jun 12, 2009.

  1. David C

    David C Guest

    I have an asp.net page that has a DropDownList that Controls the display of
    a particular record in a FormView. It works fine except for when I add or
    delete a record in the FormView then the DropDownList is not showing the new
    selection and it retains the selection of the deleted record until I
    completely leave the page and come back. I would like some help on what I
    need to do/change to make this work. Page and code samples are below.
    Thanks.

    David

    <asp:DropDownList ID="ddlTicklerID" runat="server" AutoPostBack="True"
    DataSourceID="SqlvwTicklerPick" DataTextField="SubText"
    DataValueField="TicklerID">
    </asp:DropDownList>

    DropDownList SqlDataSource is shown below.
    <asp:SqlDataSource ID="SqlvwTicklerPick" runat="server"
    ConnectionString="<%$ ConnectionStrings:FiledataConnectionString %>"
    ProviderName="<%$
    ConnectionStrings:FiledataConnectionString.ProviderName %>"
    SelectCommand="SELECT [TicklerID], [SeqNo], [Subfile], [SubText]
    FROM [vw_TicklerPick] WHERE ([FileNumber]=@txtFileNumber) ORDER BY [SeqNo]">
    <SelectParameters>
    <asp:ControlParameter ControlID="txtFileNumber"
    PropertyName="Text" Type="Int32" Name="txtFileNumber" />
    </SelectParameters>
    </asp:SqlDataSource>



    FormView SqlDataSource has the following parameters that link it to the
    DropDown selection.
    <SelectParameters>
    <asp:ControlParameter ControlID="txtFileNumber"
    PropertyName="Text" Type="Int32" Name="txtFileNumber" />
    <asp:ControlParameter ControlID="ddlTicklerID"
    PropertyName="SelectedValue" Type="Int32" Name="ddlTicklerID" />
    </SelectParameters>

    I have tried all of the events below to refresh the DropDownList but the
    list is not changing.

    Protected Sub SqlContractTicklerFile_Deleted(ByVal sender As Object,
    ByVal e As System.Web.UI.WebControls.SqlDataSourceStatusEventArgs)
    SqlvwTicklerPick.DataBind()
    ddlTicklerID.DataBind()
    End Sub

    Protected Sub BtnDeleteTickler_Command(ByVal sender As Object, ByVal e
    As System.Web.UI.WebControls.CommandEventArgs)
    SqlvwTicklerPick.DataBind()
    ddlTicklerID.DataBind()
    End Sub

    Protected Sub fvTickler_ItemUpdated(ByVal sender As Object, ByVal e As
    System.Web.UI.WebControls.FormViewUpdatedEventArgs)
    SqlvwTicklerPick.DataBind()
    ddlTicklerID.DataBind()
    fvTickler.DataBind()
    End Sub
     
    David C, Jun 12, 2009
    #1
    1. Advertising

  2. "David C" <> wrote in
    news:u#:

    > I have an asp.net page that has a DropDownList that Controls the
    > display of a particular record in a FormView. It works fine except for
    > when I add or delete a record in the FormView then the DropDownList is
    > not showing the new selection and it retains the selection of the
    > deleted record until I completely leave the page and come back. I
    > would like some help on what I need to do/change to make this work.
    > Page and code samples are below. Thanks.
    >
    > David
    >
    > <asp:DropDownList ID="ddlTicklerID" runat="server"
    > AutoPostBack="True"
    > DataSourceID="SqlvwTicklerPick" DataTextField="SubText"
    > DataValueField="TicklerID">
    > </asp:DropDownList>
    >
    > DropDownList SqlDataSource is shown below.
    > <asp:SqlDataSource ID="SqlvwTicklerPick" runat="server"
    > ConnectionString="<%$ ConnectionStrings:FiledataConnectionString %>"
    > ProviderName="<%$
    > ConnectionStrings:FiledataConnectionString.ProviderName %>"
    > SelectCommand="SELECT [TicklerID], [SeqNo], [Subfile],
    > [SubText]
    > FROM [vw_TicklerPick] WHERE ([FileNumber]=@txtFileNumber) ORDER BY
    > [SeqNo]">
    > <SelectParameters>
    > <asp:ControlParameter ControlID="txtFileNumber"
    > PropertyName="Text" Type="Int32" Name="txtFileNumber" />
    > </SelectParameters>
    > </asp:SqlDataSource>
    >
    >
    >
    > FormView SqlDataSource has the following parameters that link it to
    > the DropDown selection.
    > <SelectParameters>
    > <asp:ControlParameter ControlID="txtFileNumber"
    > PropertyName="Text" Type="Int32" Name="txtFileNumber" />
    > <asp:ControlParameter ControlID="ddlTicklerID"
    > PropertyName="SelectedValue" Type="Int32" Name="ddlTicklerID" />
    > </SelectParameters>
    >
    > I have tried all of the events below to refresh the DropDownList but
    > the list is not changing.
    >
    > Protected Sub SqlContractTicklerFile_Deleted(ByVal sender As
    > Object,
    > ByVal e As System.Web.UI.WebControls.SqlDataSourceStatusEventArgs)
    > SqlvwTicklerPick.DataBind()
    > ddlTicklerID.DataBind()
    > End Sub
    >
    > Protected Sub BtnDeleteTickler_Command(ByVal sender As Object,
    > ByVal e
    > As System.Web.UI.WebControls.CommandEventArgs)
    > SqlvwTicklerPick.DataBind()
    > ddlTicklerID.DataBind()
    > End Sub
    >
    > Protected Sub fvTickler_ItemUpdated(ByVal sender As Object, ByVal
    > e As
    > System.Web.UI.WebControls.FormViewUpdatedEventArgs)
    > SqlvwTicklerPick.DataBind()
    > ddlTicklerID.DataBind()
    > fvTickler.DataBind()
    > End Sub



    You have to repopulate the dropdown any time you add or delete. Take the
    code, most likely in Page_Load, that loads the DropDownList and refactor
    it into its own method. You can then call it on any Delete or Add
    functionality.


    --
    Gregory A. Beamer
    MVP; MCP: +I, SE, SD, DBA

    Twitter: @gbworld
    Blog: http://gregorybeamer.spaces.live.com

    *******************************************
    | Think outside the box! |
    *******************************************
     
    Gregory A. Beamer, Jun 15, 2009
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Scott Allen
    Replies:
    0
    Views:
    500
    Scott Allen
    Sep 13, 2004
  2. Neil
    Replies:
    1
    Views:
    1,614
    =?Utf-8?B?U3JpZGhhcg==?=
    Nov 16, 2005
  3. Martin
    Replies:
    1
    Views:
    2,919
    Martin
    Jun 27, 2006
  4. Chris

    Formview within Formview

    Chris, May 19, 2007, in forum: ASP .Net
    Replies:
    0
    Views:
    584
    Chris
    May 19, 2007
  5. Lagrange
    Replies:
    1
    Views:
    582
    Lagrange
    Jan 17, 2009
Loading...

Share This Page