PDA

View Full Version : درخواست کمک : در مورد حذف فایل ها از درون گرید ویو



ya30ien2
سه شنبه 02 آبان 1391, 18:57 عصر
سلام
من برای حذف فایل از کد زیر استفاده میکنم

string name = "key-icon.png";
string path = "~/UploadFile/";
string FileToDelete;
FileToDelete = Server.MapPath(path + name);
File.Delete(FileToDelete);

مشکلی هم نداره برای فراخوانی نام فایل ها هم از روش زیر استفاده میکنم


var files = Directory.GetFiles(Server.MapPath("~/UploadFile"));

gvFiles.DataSource = from f in files
select new
{

FileName = Path.GetFileName(f),
Size = Path.Combine(f),
Type = Path.GetExtension(f),
};
gvFiles.DataBind();




<asp:GridView ID="gvFiles" runat="server" AutoGenerateColumns="false"

onselectedindexchanged="gvFiles_SelectedIndexChanged">
<Columns>
<asp:TemplateField HeaderText="Delete">
<ItemTemplate>
<asp:Button ID="Delete" CommandName="Delete" text='<%# Eval("FileName") %>' runat="server" ></asp:Button>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="File Name">
<ItemTemplate>
<asp:Label ID="lblFileName" runat="server" Text='<%# Eval("FileName") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Size">
<ItemTemplate>
<asp:Label ID="lblSize" runat="server" Text='<%# Eval("Size") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Type">
<ItemTemplate>
<asp:Label ID="lblType" runat="server" Text='<%# Eval("Type") %>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>


وقتی از خصلت CommandArgument برای گرفتن نام فایل استفاده میکنم
دیگه صفحه باز نمیشه
لطفا بگید مشکل از کجاست
وقتی هم که هیچ عملی برای button تعریف نمیکنم در صورت کلیک روش با ارور زیر مواجه میشم


Server Error in '/upload' Application.

Invalid postback or callback argument. Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: Invalid postback or callback argument. Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.

Source Error:

hamed_hossani
سه شنبه 02 آبان 1391, 22:36 عصر
gridview Delete confirm box in codebehind using ASP.NET (http://www.dotnetspark.com/kb/348-gridview-delete-confirm-box-codebehind-using.aspx)
SELECT, UPDATE, INSERT, DELETE directly from a GridView control (http://www.dotnetspark.com/kb/2809-select-update-insert-delete-directly-from.aspx)