繁体   English   中英

GridView中的文件上传控件

[英]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")

现在,您可以将fl1fl2用作文件控件。

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM