Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# GridView中的文件上载控件_C#_Asp.net - Fatal编程技术网

C# GridView中的文件上载控件

C# GridView中的文件上载控件,c#,asp.net,C#,Asp.net,我在GridViewControl中有两个用于上载文件的文件上载控件,我在gridview中有一个用于上载文件的按钮,我使用它的RowCommandEvent来上载文件。如何在RowCommandEvent中获取fileupload控件的值? 这是我的网格视图 <asp:GridView ID="DgFiles" runat="server" AutoGenerateColumns="false" OnRowCommand="DgFiles_RowCommand">

我在GridViewControl中有两个用于上载文件的文件上载控件,我在gridview中有一个用于上载文件的按钮,我使用它的RowCommandEvent来上载文件。如何在RowCommandEvent中获取fileupload控件的值? 这是我的网格视图

   <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>
我必须以类似GridView的结构显示记录,其中包含文件上载控件,如果有其他方法,请建议。

首先,
您必须添加一个命令名为upload的命令列
第二
必须使用父属性在行内找到控件

FileUpload fl1 = (FileUpload)e.Row[rowindex].Cells<cellindex>.FindControl("File1")
FileUpload fl2 = (FileUpload)e.Row[rowindex].Cells<cellindex>.FindControl("File2")
FileUpload fl1=(FileUpload)e.Row[rowindex].Cells.FindControl(“File1”)
FileUpload fl2=(FileUpload)e.Row[rowindex].Cells.FindControl(“File2”)

现在您可以使用
fl1
fl2
作为文件控件

我看到了这个,这个控件有一个上传控件,我对每一行都有单独的控件
FileUpload fl1 = (FileUpload)e.Row[rowindex].Cells<cellindex>.FindControl("File1")
FileUpload fl2 = (FileUpload)e.Row[rowindex].Cells<cellindex>.FindControl("File2")