views:

542

answers:

3

*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

A: 

Bind in the OnRowDataBound event (or AspxGridview equivalent)

TheGeekYouNeed
will you plz send some syntax how to Bound data on AspxGridView for cell combo
shamim
A: 

Hi

This is the cause of this issue. You are checking for the "CategoryID" field name. But the ComboBox column is created for the "CategoryName" field:

if (!ASPxGridView1.IsEditing || e.Column.FieldName != "CategoryID") return;
ASPxComboBox combo = e.Editor as ASPxComboBox;
DevExpress Team
thanks it's really a big mistake.thaks.This problem is solve but when i click on New command link of AspxGridview my combo is not load .will you please tell me the reason?Thanks again
shamim
click on new command why this method is not active private void cmbBranch_OnCallback(object source, CallbackEventArgsBase e) { FillCityCombo(source as ASPxComboBox, Convert.ToInt16(e.Parameter)); }
shamim
Why my OnCallback event is not active.How to active on this event.plz see my above syntax.
shamim
A: 

Hi,

We've posted a sample project showing how to implement dependent combos in insert mode at:

http://www.devexpress.com/Support/Center/ViewIssue.aspx?issueid=Q102130

I hope, this project will be helpful to you.

DevExpress Team