DevExpress的使用(二) ASPxGridView

本文详细介绍了如何使用ASPxDropDownEdit组件来实现产品二级类别的选择功能,包括前端界面配置、后台代码逻辑及JavaScript交互。通过具体实例展示了如何通过组件选择多个类别并获取其OID和名称。

  <tr>
                                <td>
                                    Second Product Category:
                                </td>
                                <td colspan="2">
                                    <dx:ASPxDropDownEdit ID="ASPxDropDownEdit4" AllowUserInput="False" ClientInstanceName="txtSecondCateName"
                                        runat="server" CssFilePath="~/App_Themes/DevEx/{0}/styles.css" CssPostfix="DevEx"
                                        Spacing="0" SpriteCssFilePath="~/App_Themes/DevEx/{0}/sprite.css" Width="100%">
                                        <DropDownWindowTemplate>
                                            <dx:ASPxGridView ID="ASPxGridView2" KeyFieldName="Oid" ClientInstanceName="grid2"
                                                DataSourceID="XpoDataSource5" runat="server" CssFilePath="~/App_Themes/DevEx/{0}/styles.css"
                                                CssPostfix="DevEx" OnCustomDataCallback="ASPxGridView2_CustomDataCallback" Width="100%">
                                                <Columns>
                                                    <dx:GridViewCommandColumn ShowInCustomizationForm="True" ShowSelectCheckbox="True"
                                                        VisibleIndex="0">
                                                        <ClearFilterButton Visible="True">
                                                        </ClearFilterButton>
                                                    </dx:GridViewCommandColumn>
                                                    <dx:GridViewDataColumn FieldName="Name" Caption="Name" VisibleIndex="1">
                                                    </dx:GridViewDataColumn>
                                                    <dx:GridViewDataColumn FieldName="Oid" Caption="Oid" Visible="false"></dx:GridViewDataColumn>
                                                </Columns>
                                                <ClientSideEvents SelectionChanged="function(s,e){GetID2(s,e);}" />
                                                <Settings ShowFilterRow="True" ShowGroupPanel="True" />
                                                <Images SpriteCssFilePath="~/App_Themes/DevEx/{0}/sprite.css">
                                                    <LoadingPanelOnStatusBar Url="~/App_Themes/DevEx/GridView/StatusBarLoading.gif">
                                                    </LoadingPanelOnStatusBar>
                                                    <LoadingPanel Url="~/App_Themes/DevEx/GridView/Loading.gif">
                                                    </LoadingPanel>
                                                </Images>
                                                <ImagesFilterControl>
                                                    <LoadingPanel Url="~/App_Themes/DevEx/GridView/Loading.gif">
                                                    </LoadingPanel>
                                                </ImagesFilterControl>
                                                <Styles CssFilePath="~/App_Themes/DevEx/{0}/styles.css" CssPostfix="DevEx">
                                                    <Header ImageSpacing="5px" SortingImageSpacing="5px">
                                                    </Header>
                                                    <LoadingPanel ImageSpacing="5px">
                                                    </LoadingPanel>
                                                </Styles>
                                                <StylesEditors ButtonEditCellSpacing="0">
                                                    <ProgressBar Height="21px">
                                                    </ProgressBar>
                                                </StylesEditors>
                                            </dx:ASPxGridView>
                                        </DropDownWindowTemplate>
                                        <ButtonStyle Width="13px">
                                        </ButtonStyle>
                                    </dx:ASPxDropDownEdit>
                                </td>
                            </tr>

 

 

脚本

 

        function GetID2(s, e) {
            grid2.GetSelectedFieldValues("Oid", function (value) {
                txtSecondCateName.SetKeyValue(value);
            });
            grid2.GetSelectedFieldValues("Name", function (value) {
                txtSecondCateName.SetText(value);
            });
        }

 

后台代码

 

    protected void ASPxGridView2_CustomDataCallback(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewCustomDataCallbackEventArgs e)
    {

        if (e.Parameters != "")
        {
            string[] arr = e.Parameters.Split(',');
            string stroid = "";
            string strname = "";
            for (int i = 0; i < arr.Length; i++)
            {
                strname = strname + arr[i] + ',';
                //Terminology aw = s.FindObject<Terminology>(DevExpress.Data.Filtering.CriteriaOperator.Parse("Oid=?", oid));
                //stroid += "," + oid;
                //if (aw != null)
                //{
                //    strname += "," + aw.Name;
                //}
            }
            //if (stroid != "")
            //    stroid = stroid.Substring(1);
            //if (strname != "")
            //    strname = strname.Substring(1);
            //e.Result = stroid + "|" + strname;
            e.Result = strname;
        }
    }

 

     if (!string.IsNullOrEmpty(r.PSecondCategory))
                {
                    (ASPxNavBar1.Groups[0].FindControl("ASPxDropDownEdit4") as ASPxDropDownEdit).KeyValue = r.PSecondCategoryOid;
                    (ASPxNavBar1.Groups[0].FindControl("ASPxDropDownEdit4") as ASPxDropDownEdit).Value = r.PSecondCategory;
                    ASPxDropDownEdit edi = (this.ASPxNavBar1.Groups[0].FindControl("ASPxDropDownEdit4") as ASPxDropDownEdit);
                    ASPxGridView ag = edi.FindControl("ASPxGridView2") as ASPxGridView;

                    string str = r.PSecondCategoryOid;
                    string[] arr = str.Split(',');

                    for (int j = 0; j < ag.VisibleRowCount; j++)
                    {
                        for (int i = 0; i < arr.Length; i++)
                        {
                            if (ag.GetRowValues(j, "Oid") != null)
                                if (ag.GetRowValues(j, "Oid").ToString() == arr[i].ToString())
                                    ag.Selection.SelectRow(j);

                        }
                    }
                }
                else
                {
                    (ASPxNavBar1.Groups[0].FindControl("ASPxDropDownEdit4") as ASPxDropDownEdit).KeyValue = null;
                    (ASPxNavBar1.Groups[0].FindControl("ASPxDropDownEdit4") as ASPxDropDownEdit).Value = "";
                }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值