Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
215
WebCombo FindByText
posted

I have a webcombo on my Asp.net page which is bound to a data table.

 this.WebCombo1.DataSource = DataSet1.tblBankAccounts;this.WebCombo1.DataMember = "tblBankAccounts";this.WebCombo1.DataTextField = "AccountNumber";this.WebCombo1.DataValueField = "pk_BankAccount";this.WebCombo1.DataBind();  

Then when I try to set the selected index of the webcombo I get an “Object reference not set to an instance of an object.” error.

  this.WebCombo1.SelectedIndex = this.WebCombo1.FindByText("1235684").Row.Index; 

I double checked that the value is present in the data table.

 

The thing is that it does not throw the error when the AutoGenerateColumns attribute is set to true. As soon as the AutoGenerateColumns is set to false I receive this error.

 

Thanks

Parents
  • 50
    Offline posted

    make sure you set the seletedindex in the webcombo's databound event not in the page load.
    you have to wait for data to be present in the combo before you can search and set the index.

Reply Children
No Data