简体   繁体   English

ASP.NET DevExpress-如何在另一个函数中获取ASPxComboBox的选定值

[英]ASP.NET DevExpress - How to get selected value of ASPxComboBox in another function

I have a ASPxUploadControl item (with an integrated Upload Button) and then a ASPxComboBox like this 我有一个ASPxUploadControl项(带有集成的上载按钮),然后有一个像这样的ASPxComboBox 在此处输入图片说明

In the first one I need to browse and select an item (picture), then I have to select an application in the second item and finally I need to upload it (click the button below). 在第一个项目中,我需要浏览并选择一个项目(图片),然后在第二个项目中选择一个应用程序,最后我需要上传它(单击下面的按钮)。 So I did this for the client side: 因此,我为客户端执行了此操作:

<dx:ASPxUploadControl ID="ASPxUploadControl_Browse" runat="server" ShowUploadButton="True" AddUploadButtonsHorizontalPosition="Left"
                UploadMode="Auto" OnFileUploadComplete="UploadControl_FileUploadComplete" AllowedFileExtensions=".jpg,.jpeg,.gif,.png" Width="280px">
                <BrowseButton Text="Sfoglia" />
                <UploadButton Text="Carica"/>
</dx:ASPxUploadControl>
<dxe:ASPxComboBox ID="ASPxComboBox_Select" runat="server" DataSourceID="SqlDataSourceApplications"
                TextField="name" ValueField="applicationid" OnSelectedIndexChanged="ApplicationList_SelectedIndexChanged" Height="25px">
</dxe:ASPxComboBox>

And then for the server side: 然后对于服务器端:

protected void ApplicationList_SelectedIndexChanged(object sender, EventArgs e)
{
    ASPxComboBox cb = (ASPxComboBox)sender;
    ASPxGridCustomers.FilterEnabled = true;
    ASPxGridCustomers.FilterExpression = "( applicationid = " + cb.SelectedItem.Value + ")";

    ASPxButtonAll.ClientEnabled = true;
}

protected void UploadControl_FileUploadComplete(object sender, DevExpress.Web.ASPxUploadControl.FileUploadCompleteEventArgs e)
{
    try
    {
        FileInfo fileinfo = new FileInfo(e.UploadedFile.FileName);
        string s = "";
        try
        {
            s = ASPxComboBox_Select.Value.ToString();
        }
        catch (Exception ex) 
        {
            throw new Exception(ex.Message);
        }
        byte[] attachmentfile = GetBytes(fileinfo.Name);
        putDocumentToDB(selectedApp, attachmentfile);
    }
    catch (Exception ex)
    {
        throw new Exception(ex.Message);
    }
}

Since I need to put the file (in byte) in a database I need to know the application that the user chose. 由于我需要将文件(以字节为单位)放入数据库中,因此我需要知道用户选择的应用程序。 The problem is that I can't understand how to call it from inside the function UploadControl_FileUploadComplete. 问题是我不明白如何从函数UploadControl_FileUploadComplete内部调用它。 For now the string is completely empty.. 目前,该字符串完全为空。

Thanks! 谢谢!

it's because UploadControl_FileUploadComplete is a callback event handler, not a postback one. 这是因为UploadControl_FileUploadComplete是回调事件处理程序,而不是回发事件处理程序。

as a work-around, try saving combobox selection in a session variable, like this: 解决方法是,尝试将组合框选择保存在会话变量中,如下所示:

protected void ApplicationList_SelectedIndexChanged(object sender, EventArgs e)
{
    ASPxComboBox cb = (ASPxComboBox)sender;
    ASPxGridCustomers.FilterEnabled = true;
    ASPxGridCustomers.FilterExpression = "( applicationid = " + cb.SelectedItem.Value + ")";

    Session["cbSelectedValue"] = cb.SelectedItem.Value;

    ASPxButtonAll.ClientEnabled = true;
}

protected void UploadControl_FileUploadComplete(object sender, DevExpress.Web.ASPxUploadControl.FileUploadCompleteEventArgs e)
{
    try
    {
        FileInfo fileinfo = new FileInfo(e.UploadedFile.FileName);
        string s = "";
        try
        {
            s = Session["cbSelectedValue"].ToString();
        }
        catch (Exception ex) 
        {
            throw new Exception(ex.Message);
        }
        byte[] attachmentfile = GetBytes(fileinfo.Name);
        putDocumentToDB(selectedApp, attachmentfile);
    }
    catch (Exception ex)
    {
        throw new Exception(ex.Message);
    }
}

// in case your combobox has a selected value on page load
protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        Session["cbSelectedValue"] = cb.SelectedItem.Value;
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 通过jQuery获取DevExpress ASPxComboBox的价值 - Get value of DevExpress ASPxComboBox via jQuery 如何在asp.net core 2.2的下拉列表中获取选定的值? - How to get selected value in dropdown in asp.net core 2.2? 如何从DevExpress RepositoryItemLookUpEdit获取选定的值 - How to get Selected Value from DevExpress RepositoryItemLookUpEdit 如何在aspxgridview devexpress中获取所选行的值 - how to get value of selected row in aspxgridview devexpress asp.net button_click函数为devexpress ASPxHiddenField返回怪异的值 - asp.net button_click function returns weird value for devexpress ASPxHiddenField 如何从DevExpress LookupEdit中获取选定的值? - How to get selected value from DevExpress LookupEdit? 如何从一个数据源填充ASP.NET DropDownList并从另一个数据源设置所选值? - How to populate an ASP.NET DropDownList from one datasource and set the selected value from another? 如何获取转换后的布尔值以在asp.net gridview的可编辑下拉列表中显示为选定值? - How to get converted boolean value to show as selected value in the editable drop down list in asp.net gridview? 如何从CheckBoxList获取选定项并将其转移到另一页ASP.Net C# - How to get selected items from a CheckBoxList and transfer it to another page ASP.Net C# 从asp.net的下拉列表中获取选定的值 - Get selected value from dropdownlist in asp.net
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM