0

When i set value ASPXCombobox. Coming null ref Exception;

<td>
                                            <dxe:ASPxComboBox ID="cmb" runat="server" AutoPostBack="True" ClientInstanceName="cmb"
                                                EnableCallbackMode="True" EnableSynchronization="False" CallbackPageSize="20" Width="300px"
                                                IncrementalFilteringMode="Contains"
                                                LoadingPanelText="Yükleniyor&hellip;" Theme="Aqua">
                                            </dxe:ASPxComboBox>
                                        </td>
  Test tt = new Test();
    DataTable dt = paf.GetAllItem();
    cmb.ValueField = "ID";
    cmb.TextField = "NAME";
    cmb.DataSource = dt;
    cmb.DataBind();
    cmbMahPafta.SelectedIndex = -1;

After i am using that code and coming error.

 cmbMahPafta.SelectedItem.Value=user.ID;//Null reference Exception.

How can I fix this issue ?

  • @Steve that question diffrent Question. – Muratcan Oguzhan Oct 14 '16 at 08:24
  • No it is always the same. You use a variable thinking that has a value instead it is null because you don't check. In your case SelectedItem or user could be null. And the answer is always the same. Check with a debugger what is null and think about it. – Steve Oct 14 '16 at 08:38
  • But combobox datasource not null, i fill combobox data, why prevent set selecteditem ?@Steve – Muratcan Oguzhan Oct 14 '16 at 08:44
  • _SelectedItem_ means the Item selected in the combo. Do you have any item selected? I gues no because you set SelectedIndex = -1. What if you set the SelectedIndex to 0? – Steve Oct 14 '16 at 08:46
  • How can i select any item on Combobox ? I am doing that asp:DropDownList just cmb.SelectedValue=user.ID; but ASPXComboBox doesnt have SelectedValue property. @Steve – Muratcan Oguzhan Oct 14 '16 at 08:56

0 Answers0