*i work on northwind database .*In my AspxGridview i want to show comboBox.I fill grid on back end C#.i also want my combo will fill back end.
<dxwgv:ASPxGridView ID="ASPxGridView1" runat="server"
AutoGenerateColumns="False" KeyFieldName="CategoryID"
oncelleditorinitialize="ASPxGridView1_CellEditorInitialize">
<Columns>
<dxwgv:GridViewCommandColumn VisibleIndex="0" Width="80px">
<EditButton Visible="True">
</EditButton>
<NewButton Visible="True">
</NewButton>
<DeleteButton Visible="True">
</DeleteButton>
</dxwgv:GridViewCommandColumn>
<dxwgv:GridViewDataTextColumn Caption="CategoryID" FieldName="CategoryID"
VisibleIndex="1">
</dxwgv:GridViewDataTextColumn>
<dxwgv:GridViewDataComboBoxColumn Caption="CategoryName"
FieldName="CategoryName" VisibleIndex="2">
<PropertiesComboBox TextField="Value" ValueField="key" ValueType="System.Int32">
<ClientSideEvents SelectedIndexChanged="function(s, e) { OnBankChanged(s); }" />
</PropertiesComboBox>
</dxwgv:GridViewDataComboBoxColumn>
<dxwgv:GridViewDataTextColumn Caption="Description" FieldName="Description"
VisibleIndex="3">
</dxwgv:GridViewDataTextColumn>
</Columns>
</dxwgv:ASPxGridView>
To fill grid i use the bellow C# syntax.
DataClasses1DataContext db = new DataClasses1DataContext();
var r = from p in db.Categories
select p;
ASPxGridView1.DataSource = r;
ASPxGridView1.DataBind();
To fill gridview cell of combo i use Bellow C# syntax
protected void ASPxGridView1_CellEditorInitialize(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewEditorEventArgs e)
{
if (!ASPxGridView1.IsEditing || e.Column.FieldName != "CategoryID") return;
ASPxComboBox combo = e.Editor as ASPxComboBox;
if (!(e.KeyValue == DBNull.Value || e.KeyValue == null)) //return;
{
object val = ASPxGridView1.GetRowValuesByKeyValue(e.KeyValue, "CategoryID");
if (val == DBNull.Value) return;
Int32 CategoryID = (Int32)val;
FillCityCombo(combo, CategoryID);
}
combo.Callback += new CallbackEventHandlerBase(cmbBranch_OnCallback);
}
private void cmbBranch_OnCallback(object source, CallbackEventArgsBase e)
{
FillCityCombo(source as ASPxComboBox, Convert.ToInt16(e.Parameter));
}
protected void FillCityCombo(ASPxComboBox cmb, Int32 CategoryID)
{
//cmb.Items.Clear();
//cmb.DataSourceID = "";
DataClasses1DataContext db = new DataClasses1DataContext();
var r = from p in db.Categories
select new { p.CategoryID,p.CategoryName};
cmb.DataSource = r;
cmb.DataBind();
}
When i run the code AspxGridview fill well but when i click on Edit or New Command on left side of my grid show me bellow error message ;
**Object reference not set to an instance of an object.**
What's the problem is?How to solve this problem.How to bind cell combo on aspx gridview