Help with DropDownList controlling FormView


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][email protected]) 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
 
Ad

Advertisements

G

Gregory A. Beamer

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][email protected]) 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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top