Solved

Need to reload a combobox after an insert of a formview

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

Independent Software Vendors: 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

Suggested Solutions

Title # Comments Views Activity
how to make search between pages 17 60
.NET Redemption/Outlook Examples 3 35
Select coumns form Data table? 3 27
Updating Printer Details in VB.Net 16 43
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.…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

710 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