Solved

Need to reload a combobox after an insert of a formview

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

828 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