Solved

Need to reload a combobox after an insert of a formview

Posted on 2011-02-14
4
1,501 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

630 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