ASPxGridView中的DropDownLists - 显示消息不支持指定的方法

时间:2010-07-31 14:56:02

标签: linq asp.net-3.5 devexpress

<div>

    <dx:ASPxGridView ID="ASPxGridView1" runat="server" AutoGenerateColumns="False" 
        ClientInstanceName="ASPxGridView1" DataSourceID="LinqServerModeDataSource1" 
        KeyFieldName="ProductID" 
        oncelleditorinitialize="ASPxGridView1_CellEditorInitialize" 
        onrowdeleting="ASPxGridView1_RowDeleting" 
        onrowinserting="ASPxGridView1_RowInserting" 
        onrowupdating="ASPxGridView1_RowUpdating">
        <Columns>
            <dx:GridViewCommandColumn VisibleIndex="0">
                <EditButton Visible="True">
                </EditButton>
                <NewButton Visible="True">
                </NewButton>
                <DeleteButton Visible="True">
                </DeleteButton>
            </dx:GridViewCommandColumn>
            <dx:GridViewDataTextColumn Caption="ProductID" FieldName="ProductID" 
                VisibleIndex="1">
            </dx:GridViewDataTextColumn>
            <dx:GridViewDataTextColumn Caption="ProductName" FieldName="ProductName" 
                VisibleIndex="2">
            </dx:GridViewDataTextColumn>
            <dx:GridViewDataComboBoxColumn Caption="CategoryID" FieldName="CategoryID" 
                VisibleIndex="3">
                <PropertiesComboBox DataSourceID="LinqServerModeDataSource2" 
                    TextField="CategoryName" ValueField="CategoryID" ValueType="System.Int32">
                </PropertiesComboBox>
            </dx:GridViewDataComboBoxColumn>
        </Columns>
    </dx:ASPxGridView>

</div>
<dx:LinqServerModeDataSource ID="LinqServerModeDataSource1" runat="server" 
    onselecting="LinqServerModeDataSource1_Selecting" />
<dx:LinqServerModeDataSource ID="LinqServerModeDataSource2" runat="server" 
    onselecting="LinqServerModeDataSource2_Selecting" />

C#语法:

  protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void LinqServerModeDataSource1_Selecting(object sender, DevExpress.Data.Linq.LinqServerModeDataSourceSelectEventArgs e)
        {
            NorthWindDataContext db = new NorthWindDataContext();
            var r = from p in db.Products
                    select p;
            e.QueryableSource = r;
        }

        protected void ASPxGridView1_RowInserting(object sender, DevExpress.Web.Data.ASPxDataInsertingEventArgs e)
        {

        }

        protected void ASPxGridView1_RowUpdating(object sender, DevExpress.Web.Data.ASPxDataUpdatingEventArgs e)
        {

        }

        protected void ASPxGridView1_RowDeleting(object sender, DevExpress.Web.Data.ASPxDataDeletingEventArgs e)
        {

        }

        //protected void ASPxGridView1_CellEditorInitialize(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewEditorEventArgs e)
        //{

        //}

        protected void ASPxGridView1_CellEditorInitialize(object sender, 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;
                Int16 BrokerId = (Int16)val;
                FillCityCombo(combo, BrokerId);
            }

            combo.Callback += new CallbackEventHandlerBase(cmbBranch_OnCallback);
        }

        protected void FillCityCombo(ASPxComboBox cmb, Int16 BrokerId)
        {
            NorthWindDataContext db = new NorthWindDataContext();
            var r = from p in db.Categories
                    where (p.CategoryID == BrokerId)
                    select p;

            cmb.Items.Clear();
            cmb.DataSourceID = "";
            cmb.DataSource = r;
            cmb.DataBind();
        }


        private void cmbBranch_OnCallback(object source, CallbackEventArgsBase e)
        {
            FillCityCombo(source as ASPxComboBox, Convert.ToInt16(e.Parameter));
        }


        protected void LinqServerModeDataSource2_Selecting(object sender, DevExpress.Data.Linq.LinqServerModeDataSourceSelectEventArgs e)
        {
            NorthWindDataContext db = new NorthWindDataContext();
            var r = from p in db.Categories
                    select p;
            e.QueryableSource = r;
        }

运行代码显示错误消息不支持指定方法。

我使用NorthWind数据库。我想在AspxGridview中显示产品表信息.CategoryID是Product table的列之一。我想在该列上显示 Categories 表格,我想要从类别表中显示 CategoryName 如何?

为什么要显示错误。如何解决此问题。 点击gridview的命令字段我想根据CategoryName获取CategoryID。

1 个答案:

答案 0 :(得分:1)

不支持Show message指定方法如果将LinqServerModeDataSource.EnableUpdate属性设置为true,则可以解决错误。此外,您可以在以下位置阅读有关此错误的信息:

http://search.devexpress.com/?q=Specified+method+is+not+supported.&p=T4|P5|0&d=447

  

&GT;   我使用NorthWind数据库。我想在AspxGridview中显示产品表信息.CategoryID是Product table的列之一。我想在该列上显示Categories表格,我想从类别表中显示CategoryName。如何?   &LT;&LT;   创建GridViewDataComboBox列以显示此类数据。此列属性允许您在两个字段之间设置链接:

http://documentation.devexpress.com/#AspNet/clsDevExpressWebASPxGridViewGridViewDataComboBoxColumntopic