我有一個fileupload
控制,我想要filename
在codebehind
。我正在使用editindex
事件,當我選擇文件並按editindex
按鈕時,我得到的null
的值爲fileupload
。 這裏是我aspx
代碼:FileUpload控件在代碼後面檢索空值?
<asp:GridView ID="comp_gr" runat="server" AutoGenerateColumns="false" OnRowEditing="comp_gr_RowEditing">
<Columns>
<asp:CommandField ShowEditButton="true" ButtonType="Button" EditText="Complete Task" ControlStyle-BorderColor="White" ControlStyle-BorderStyle="Double" ControlStyle-BackColor="#990000" />
</Columns
<Columns>
<asp:TemplateField HeaderText="Attach Document">
<ItemTemplate>
<asp:FileUpload ForeColor="Black" ID="FileUpload1" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
這裏是我的codebehind
protected void comp_gr_RowEditing(object sender, GridViewEditEventArgs e)
{
FileUpload file = (FileUpload)comp_gr.Rows[e.NewEditIndex].Cells[1].FindControl("FileUpload1");
string f = file.FileName.ToString();
}
但我在f
越來越總是null
值。
你是什麼意思?我看不懂 –
查看該鏈接 http://www.asp.net/web-forms/overview/data-access/custom-formatting/using-templatefields-in-the-the- gridview-control-cs –
如果我把這個'fileupload'控件放在''裏面,'gridview'顯示時'fileupload'控件會消失。當gridview處於視圖模式時,不會顯示'fileupload' –