Solved

Need to reload a combobox after an insert of a formview

Posted on 2011-02-14
4
1,490 Views
Last Modified: 2012-05-11
I have a formview that is loaded when the user selects a value from the combobox. One of the options in the formview is to add a new item which inserts it into the database. At that point I need to refresh the combobox. I know I can do it from codebehind but is there a way to just have that datasource the combobox is loaded to re-fire?

example
cboLender with datasource sqlDataSource1

formview with Datasource sqlDataSource2
   this one loads based on the SelectedValue of the combobox
When a new item is inserted in the formview I want sqlDataSource1 to re-fire so that it will load the newly inserted item.
0
Comment
Question by:md0333
  • 2
  • 2
4 Comments
 
LVL 10

Expert Comment

by:himanshut
ID: 34893791
in your aspx page, for your combobox add AutoPostback="true" and OnSelectedIndexChange ="ComboBox1_SelectedIndexChanged"

then in your code behind :-

private void ComboBox1_SelectedIndexChanged(object sender, System.EventArgs e)
  {
if(ComboBox1.Item.SelectedValue == "whatevervalue")
  {
     /// Your re-bind code goes here
   }
  }
This will re-bind your combobox if the selected index has "insert" or what ever value you have for that item.

Cheers
This
0
 

Author Comment

by:md0333
ID: 34893828
I know I can do it in codebehind... I was hoping there was a way to do it without that.

right now I have the combobox
<telerik:RadComboBox ID="cboLenders" runat="server"
                Width="203px"
                AutoPostBack="True"
                DataSourceID="sqlLenders2"
                DataTextField="BankName"
                DataValueField="BankID" />
            <asp:SqlDataSource ID="sqlLenders2" runat="server"
                ConnectionString="<%$ ConnectionStrings:FT_Data %>"
                SelectCommand="SELECT * FROM [Bank] WHERE ([DealerID] = @DealerID) ORDER BY [BankName]">
                <SelectParameters>
                    <asp:SessionParameter Name="DealerID" SessionField="DealerID"/>
                </SelectParameters>
            </asp:SqlDataSource>

and I have a formview
<asp:FormView runat="server" ID="frmLenders"
    DataKeyNames="BankID"
    OnModeChanged="onModeChanging"
    DataSourceID="sqlLenders">
    <EditItemTemplate>
           controls...
    </EditItemTemplate>
    <ItemTemplate>
        controls...
    </ItemTemplate>
    <InsertItemTemplate>
        controls....  when Item inserted I want to refresh the sqlLenders2 datasource if possible
    </InsertItemTemplate>
</asp:FormView>

<asp:SqlDataSource ID="sqlLenders"..... />


The formview loads because of the autopostback=True in the combobox... is there a similar control in the formview to reload the combobox? If not, I will just do it in codebehind. Fairly new to ASP and trying to learn... if there is a way to do this then I won't waste my time with codebehind.
0
 
LVL 10

Accepted Solution

by:
himanshut earned 500 total points
ID: 34893914
See when ever there would be a postback, it would be triggering your Page_Init() and Page_load() in code behind where you need to get your query to re-execute based on the conditional selects you make.

in your aspx page it loads for first time due to the embedded query/datasource you have. But to refresh, you need to pass on the event to Server side i.e. you need to make it work using code behind.

I hope it makes a lil sense :)

Cheers!
0
 

Author Comment

by:md0333
ID: 34893956
Makes perfect sense... just being fairly new to ASP I just wanted to make sure I wasn't missing something.

Thank you.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now