使用回调设置ComboBox值

时间:2011-09-23 07:41:15

标签: asp.net callback devexpress

我有一个带有3个组合框和1个按钮的Asp.net页面。第一个组合框选择将影响另外2个组合框数据源。我正在使用回调函数为其他组合框设置数据源。 在用户从所有组合框中选择之后,用户单击该按钮并生成回发。 我的问题是服务器端代码,不知道页面中的选择, 如果我试图从组合框中获取值,我总是得到null。 寻找解决方案。

谢谢。

代码

Code of aspx
<script type="text/javascript">
    // <![CDATA[
        function OnProductChange(cb_Products) {
            cb_Packing.PerformCallback(cb_Products.GetValue().toString());
            cb_ProductionSite.PerformCallback(cb_Products.GetValue().toString());
        }
        function OnPackChange(cb_Products) {
            ASPxComboBox1.PerformCallback(cb_Packing.GetValue().toString());
        }`enter code here`
        function OnFactoryChange(cb_Products) {
            cb_ProductionSite.PerformCallback();
        }
    // ]]> 
    </script>

<PanelCollection>
            <dx:PanelContent runat="server" SupportsDisabledAttribute="True">
                <dx:ASPxLabel ID="ASPxLabel1" runat="server" Font-Bold="True" Font-Names="Snap ITC"
                    Font-Size="Medium" Font-Underline="True" ForeColor="#333333" Text="Production Form (DEMO)">
                </dx:ASPxLabel>
                <br />
                <br />
                <dx:ASPxLabel ID="ASPxLabel2" runat="server" Font-Names="Berlin Sans FB Demi" Font-Size="Medium"
                    Text="Select Product" ForeColor="#FF3300">
                </dx:ASPxLabel>
                <dx:ASPxComboBox ID="cb_Products" runat="server" ValueType="System.String" Font-Names="Berlin Sans FB Demi"
                    DataSourceID="EntityDataSource1" Spacing="3" TextField="PC_Name" EnableSynchronization="False"
                    ValueField="PCID" ClientIDMode="Static" DropDownStyle="DropDownList">
                    <Columns>
                        <dx:ListBoxColumn Caption="Product's name" FieldName="PCID" Visible="false" />
                        <dx:ListBoxColumn Caption="Product's name" FieldName="PC_Name" />
                    </Columns>
                    <ClientSideEvents SelectedIndexChanged=" function(s,e) { OnProductChange(s); }" />
                </dx:ASPxComboBox>
                <asp:EntityDataSource ID="EntityDataSource1" runat="server" ConnectionString="name=TrackQREntities"
                    DefaultContainerName="TrackQREntities" EnableFlattening="False" EntitySetName="TrackQR_ProductsCatalog"
                    Select="it.[PC_Name], it.[PCID]" Where="it.[ClientID] == 11">
                </asp:EntityDataSource>
                <br />
                <br />
                <dx:ASPxLabel ID="ASPxLabel3" runat="server" Font-Names="Berlin Sans FB Demi" Font-Size="Medium"
                    Text="Packing Options" ForeColor="#FF3300">
                </dx:ASPxLabel>
                <dx:ASPxComboBox ID="cb_Packing" runat="server" Font-Names="Berlin Sans FB Demi"
                    ValueType="System.String" ClientIDMode="Static" DropDownStyle="DropDown" EnableSynchronization="False"
                    OnCallback="Packing_Callback" TextField="PackQuantity"
                    ValueField="PackID" ClientInstanceName="cb_Packing" 
                    EnableCallbackMode="True">
                    <Columns>
                        <dx:ListBoxColumn FieldName="PackID" Visible="False" />
                        <dx:ListBoxColumn Caption="Pack Quantity" FieldName="PackQuantity" />
                    </Columns>
                    <ClientSideEvents SelectedIndexChanged=" function(s,e) { OnPackChange(s); }" />
                </dx:ASPxComboBox>
                <br />
                <br />
                <dx:ASPxLabel ID="ASPxLabel4" runat="server" Font-Names="Berlin Sans FB Demi" Font-Size="Medium"
                    Text="Production Site" ForeColor="#FF3300">
                </dx:ASPxLabel>
                <dx:ASPxComboBox ID="cb_ProductionSite" runat="server" Font-Names="Berlin Sans FB Demi"
                    ValueType="System.String" ClientIDMode="Static" DropDownStyle="DropDown" EnableSynchronization="False"
                    TextField="LLName" ValueField="LLID" 
                    ClientInstanceName="cb_ProductionSite" EnableCallbackMode="True" 
                    OnCallback="cb_ProductionSite_Callback" 
                     >
                    <Columns>
                        <dx:ListBoxColumn FieldName="LLID" Visible="False" />
                        <dx:ListBoxColumn Caption="Factory Name" FieldName="LLName" />
                    </Columns>
                    <ClientSideEvents SelectedIndexChanged=" function(s,e) { OnFactoryChange(s); }" />
                </dx:ASPxComboBox>
                <br />
                <br />
                <dx:ASPxLabel ID="ASPxLabel5" runat="server" Font-Names="Berlin Sans FB Demi" Font-Size="Medium"
                    Text="Number of Products" ForeColor="#FF3300">
                </dx:ASPxLabel>
                <dx:ASPxTextBox ID="atb_Quantity" runat="server" Width="170px">
                </dx:ASPxTextBox>
                <br />
                <dx:ASPxButton ID="ab_Produce" runat="server" Text="Produce" 
                    Font-Names="Arial Black" Font-Size="Medium" OnClick="ab_Produce_Click" 
                    CssFilePath="~/App_Themes/SoftOrange/{0}/styles.css" CssPostfix="SoftOrange" 
                    SpriteCssFilePath="~/App_Themes/SoftOrange/{0}/sprite.css">
                </dx:ASPxButton>
                <dx:ASPxComboBox ID="ASPxComboBox1" runat="server" Font-Names="Berlin Sans FB Demi"
                    ValueType="System.String" ClientIDMode="Static" DropDownStyle="DropDown" EnableSynchronization="False"
                    TextField="LLName" ValueField="LLID" 
                    ClientInstanceName="cb_ProductionSite" EnableCallbackMode="True" 
                    OnCallback="cb_ProductionSite_Callback" 
                     >
                    <Columns>
                        <dx:ListBoxColumn FieldName="LLID" Visible="False" />
                        <dx:ListBoxColumn Caption="Factory Name" FieldName="LLName" />
                    </Columns>
                    <ClientSideEvents SelectedIndexChanged=" function(s,e) { OnFactoryChange(s); }" />
                </dx:ASPxComboBox>
                <br />
                <br />
            </dx:PanelContent>

Code of aspx.cs

protected void Packing_Callback(object sender, DevExpress.Web.ASPxClasses.CallbackEventArgsBase e)
        {
            //if (e.Parameter != "")
            //{
                using (TrackQREntities te = new TrackQREntities())
                {
                    int id = int.Parse(e.Parameter);
                    var product = te.TrackQR_ProductsCatalog.Where(s => s.PCID == id).FirstOrDefault();
                    cb_Packing.DataSource = product.TrackQR_PacksType.ToList();
                    cb_Packing.DataBind();

                    cb_Products.SelectedIndex = id;
             //   }
            }

        }

        protected void cb_ProductionSite_Callback(object sender, DevExpress.Web.ASPxClasses.CallbackEventArgsBase e)
        {
            if (e.Parameter != "")
            {
                using (TrackQREntities te = new TrackQREntities())
                {
                    cb_ProductionSite.DataSource = te.TrackQR_LogisticLocations.Where(s => s.LLTypesID == 1).ToList();
                    cb_ProductionSite.DataBind();
                }
            }
        }

protected void ab_Produce_Click(object sender, EventArgs e)
        {

cb_ProductionSite.Value.ToString(); <--- Error Value is null

1 个答案:

答案 0 :(得分:0)

检查是否根据“Data Type Mappings (ADO.NET)”表正确指定了ASPxComboBox.ValueType属性。