本文介绍了在asp.net gridview的每一行中上传文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要从datagrid的每一行中的磁盘中选择文件.我正在按以下方式使用FileUpload,但无法访问
Hi,
I need to select file from disk in each row of datagrid. I am using FileUpload as following but its not accessable
fu = (FileUpload)row.FindControl("fu_doc");
在服务器端.
on server side.
<asp:TemplateField HeaderText="Select file">
<itemtemplate>
<asp:FileUpload ID="fu_doc"; runat="server">
</itemtemplate>
有任何建议吗?
Any suggestion?
推荐答案
<asp:TemplateField HeaderText="Logo Upload">
<ItemTemplate>
<asp:FileUpload ID="FileUpload4" runat="server" /><asp:Button ID="bt_upload" runat="server" EnableViewState="False" Text="Upload" CommandName="Upload" />
</ItemTemplate>
</asp:TemplateField>
并在服务器端:
and in the serverside:
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
Button bts = e.CommandSource as Button;
Response.Write(bts.Parent.Parent.GetType().ToString());
if (e.CommandName.ToLower() != "upload")
{
return;
}
FileUpload fu = bts.FindControl("FileUpload4") as FileUpload;//here
if (fu.HasFile)
{
bool upload = true;
string fleUpload = Path.GetExtension(fu.FileName.ToString());
if (fleUpload.Trim().ToLower() == ".xls" | fleUpload.Trim().ToLower() == ".xlsx")
{
fu.SaveAs(Server.MapPath("~/UpLoadPath/" + fu.FileName.ToString()));
string uploadedFile = (Server.MapPath("~/UpLoadPath/" + fu.FileName.ToString()));
//Someting to do?...
}
else
{
upload = false;
// Something to do?...
}
if (upload)
{
// somthing to do?...
}
}
else
{
//Something to do?...
}
}
根据您的要求进行修改
modify according to your requirement
这篇关于在asp.net gridview的每一行中上传文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!