Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <asp:GridView ID="gvFiles" runat="server" AutoGenerateColumns="False"
- OnPageIndexChanging="gvFiles_PageIndexChanging"
- OnSelectedIndexChanged="renFile" OnRowCommand="gvFiles_RowCommand"
- OnRowDataBound="gvFiles_RowDataBound" OnRowDeleting="delFile">
- <AlternatingRowStyle />
- <Columns>
- <asp:TemplateField HeaderText="Name" SortExpression="Name">
- <ItemTemplate>
- <asp:LinkButton runat="server" ID="lbFolderItem" CommandName="OpenFolder" CommandArgument='<%# Eval("Name") %>'></asp:LinkButton>
- <asp:Literal runat="server" ID="ltlFileItem"></asp:Literal>
- </ItemTemplate>
- </asp:TemplateField>
- <asp:BoundField DataField="FileSystemType" HeaderText="Type" SortExpression="FileSystemType" />
- <asp:BoundField DataField="LastWriteTime" HeaderText="Last Modified" SortExpression="LastWriteTime" />
- <asp:TemplateField HeaderText="Size" SortExpression="Size" ItemStyle-HorizontalAlign="Right">
- <ItemTemplate>
- <%# DisplaySize((long?) Eval("Size")) %>
- </ItemTemplate>
- <ItemStyle HorizontalAlign="Right"></ItemStyle>
- </asp:TemplateField>
- <asp:CommandField HeaderText="Rename" SelectText="Rename"
- ShowSelectButton="True" ButtonType="Link"/>
- <asp:CommandField HeaderText="Delete" DeleteText="Delete"
- ShowDeleteButton="True" ButtonType="Link" />
- </Columns>
- </asp:GridView>
- public void delFile(object sender, GridViewDeleteEventArgs e)
- {
- //I have got error:
- //System.ArgumentOutOfRangeException:
- //Index was out of range.
- //Must be non-negative and less than the size of the collection.
- string filename = gvFiles.DataKeys[e.RowIndex].Values[0].ToString(); //on this line
- string path = Server.MapPath(ConfigurationManager.AppSettings["path"] + "/" + filename);
- //actually do not delete. Add a suffix in order not to list it to the user
- File.Move(filename, filename + "_del");
- PopulateGrid();
- }
- public void renFile(object sender, GridViewSelectEventArgs e)
- {
- //I have got error:
- //System.ArgumentOutOfRangeException:
- //Index was out of range.
- //Must be non-negative and less than the size of the collection.
- string filename = gvFiles.DataKeys[e.NewSelectedIndex].Values[0].ToString(); //on this line
- string path = Server.MapPath(ConfigurationManager.AppSettings["path"] + "/" + filename);
- //just for experiment
- File.Move(filename, filename + "_ren");
- PopulateGrid();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement