开发者

Setting a ComboBox value using callback

开发者 https://www.devze.com 2023-04-08 09:30 出处:网络
I have an Asp.net page with 3 combobox and 1 button. The first combobox selection will affect the other 2 combobox datasource. I\'m setting the datasource for the other combobox using a callback funct

I have an Asp.net page with 3 combobox and 1 button. The first combobox selection will affect the other 2 combobox datasource. I'm setting the datasource for the other combobox using a callback function. After the user choose from all the combobox, the user click the button and a postback is generate. My Problem is that the server side code, is not aware of the selections made in the page, if i try to get the value from the combobox I get null allways. looking for a solution.

Thank you.

Code

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


Check whether or not the ASPxComboBox.ValueType property is specified correctly according to the “Data Type Mappings (ADO.NET)” table.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号