Solved

Need to reload a combobox after an insert of a formview

Posted on 2011-02-14
4
1,491 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…

914 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

14 Experts available now in Live!

Get 1:1 Help Now