This is a migrated thread and some comments may be shown as answers.

When to Bind?

1 Answer 70 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Tony Casey
Top achievements
Rank 1
Tony Casey asked on 02 Apr 2010, 11:20 AM
I have a problem I have spent days on, its a simple thing so it frustrates me on the amount of time taken.

I havea  FormView within an Ajax panel, default mode is View, so when I click the Edit button, I want the form to show my current record so I can change it.

All works fine except, I have a LoadonDemand RadCombo box that is databound in the code behind.

I have two functions, BindCompany( In32 ) and BindCompany( string ), the string version is for ItemsRequested event of the combo and the int version is for when the page loads.

My problem is when do I bind to the combo with the int32, Page_Load , Combo_Load, FormView_ModeChanged, FormView_Load ?

None of these do it for the following reasons...

Page_Load, happens once & the combo doesnt exist because we are in EditMode
Combo_Load, this happens every time the ItemRequested fires so my current companyid might not be in the recordset return
FormView_ModeChanged, I cannot bind at that point because this fires before the control is rendered
FormView_Load, only happens once when the page is rendered & not when I click the edit button.

So, is there something simple I am missing, I really hope so because I am loosing my marbles.

1 Answer, 1 is accepted

Sort by
0
Tony Casey
Top achievements
Rank 1
answered on 02 Apr 2010, 11:56 AM
Ive got it,

Set a variable at the top when the FormView loads that holds the currentCompanyId...

In the ComboBox Load set...

 protected void RadComboBoxCompany_Load(object sender, EventArgs e)  
        {  
            RadComboBox companyCombo = (RadComboBox)sender;  
            if (companyCombo.Text == null || companyCombo.Text == "")  
            {  
                BindCompanies(currentCompanyId);  
            }  
 
        } 

In this, I check to see firstly that this is not an ItemRequest, if so, then bind the companies by using the current company id.
Tags
ComboBox
Asked by
Tony Casey
Top achievements
Rank 1
Answers by
Tony Casey
Top achievements
Rank 1
Share this question
or