Help with DropDownList controlling FormView

  • Thread starter Thread starter David C
  • Start date Start date
D

David C

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
 
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! |
*******************************************
 
Back
Top