[英]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.