Reputation: 2192
I have two file upload controls inside GridViewControl for uploading files, I have a button for uploading files inside gridview, I am using its RowCommandEvent for uploading files. How can I get values of fileupload controls in RowCommandEvent? This is my 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>
and my RowCommandEvent
protected void DgFiles_RowCommand(Object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "upload")
{
}
}
I have to display records in GridView like structure, with file upload control inside it, If there is alternate way I can do it, kindly suggest.
Upvotes: 0
Views: 5464
Reputation: 26
First,
You have to add a command column with command name upload
second,
You have to find the control inside the row by using parent property.
FileUpload fl1 = (FileUpload)e.Row[rowindex].Cells<cellindex>.FindControl("File1")
FileUpload fl2 = (FileUpload)e.Row[rowindex].Cells<cellindex>.FindControl("File2")
Now You can use fl1
and fl2
as your filecontrols.
Upvotes: 1