[英]File Upload control inside GridView
我在GridViewControl內部有兩個用於上傳文件的文件上傳控件,我在gridview內部具有一個用於上傳文件的按鈕,我正在使用其RowCommandEvent來上傳文件。 如何在RowCommandEvent中獲取fileupload控件的值? 這是我的GridView
<asp:GridView ID="DgFiles" runat="server" AutoGenerateColumns="false" OnRowCommand="DgFiles_RowCommand">
<Columns>
<asp:TemplateField HeaderText="Crime" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Label ID="category" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "Category") %>' ></asp:Label><br/>
<asp:FileUpload ID="file1" runat="server" /><br />
<asp:FileUpload ID="file2" runat="server" />
<asp:Button ID="btnupload" runat="server" CommandName="upload" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Date" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Label ID="lbldate" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "Date") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="City" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Label ID="lblcity" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "City") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
和我的RowCommandEvent
protected void DgFiles_RowCommand(Object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "upload")
{
}
}
我必須在GridView之類的結構中顯示記錄,並在其中包含文件上載控件,如果還有其他方法可以做到,請提出建議。
第一,
您必須添加帶有命令名稱上載的命令列
第二,
您必須使用父屬性在行內找到控件。
FileUpload fl1 = (FileUpload)e.Row[rowindex].Cells<cellindex>.FindControl("File1")
FileUpload fl2 = (FileUpload)e.Row[rowindex].Cells<cellindex>.FindControl("File2")
現在,您可以將fl1
和fl2
用作文件控件。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.