M
Marc
I am studying ASP.NET I am trying to use this example
http://msdn.microsoft.com/en-us/library/system.web.ui.idatasource.aspx
but for practice I want to extend it so it handles deletes.
I have this
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
CsvDataSource cds = null;
protected void Page_Load(object sender, EventArgs e)
{
if (cds == null)
{
cds = new CsvDataSource();
}
cds.FileName = "~/App_Data/CSVTextFile.csv";
cds.IncludesColumnNames = true;
GridView1.AutoGenerateDeleteButton = true;
// GridView1.RowDeleting += new
GridViewDeleteEventHandler(gv_RowDeleting);
GridView1.DataSource = cds;
GridView1.DataBind();
}
void gv_RowDeleting(Object sender, GridViewDeleteEventArgs e)
{
ClientScript.RegisterStartupScript(GetType(), "MyAlert2",
"alert('Deleting');", true);
}
}
And I have changed this in the CSVDataSource Example
public override bool CanDelete
{
get
{
return true; //changed this
}
}
And have to do some stuff here that I know
protected override int ExecuteDelete(IDictionary keys, IDictionary values)
{
throw new NotSupportedException();
}
But the Execute Delete is not called. What more do I have to do to get the
GridView know that the CsvDataSource handles deletes? I am not getting this
exception:
NotSupportedException: Specified method is not supported.]
System.Web.UI.DataSourceView.ExecuteDelete(IDictionary keys, IDictionary
oldValues) +28
System.Web.UI.DataSourceView.Delete(IDictionary keys, IDictionary
oldValues, DataSourceViewOperationCallback callback) +75
System.Web.UI.WebControls.GridView.HandleDelete(GridViewRow row, Int32
rowIndex) +927
But this exception:
System.Web.UI.WebControls.GridView.OnRowDeleting(GridViewDeleteEventArgs e)
+325
System.Web.UI.WebControls.GridView.HandleDelete(GridViewRow row, Int32
rowIndex) +732
MarcWentink
http://msdn.microsoft.com/en-us/library/system.web.ui.idatasource.aspx
but for practice I want to extend it so it handles deletes.
I have this
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
CsvDataSource cds = null;
protected void Page_Load(object sender, EventArgs e)
{
if (cds == null)
{
cds = new CsvDataSource();
}
cds.FileName = "~/App_Data/CSVTextFile.csv";
cds.IncludesColumnNames = true;
GridView1.AutoGenerateDeleteButton = true;
// GridView1.RowDeleting += new
GridViewDeleteEventHandler(gv_RowDeleting);
GridView1.DataSource = cds;
GridView1.DataBind();
}
void gv_RowDeleting(Object sender, GridViewDeleteEventArgs e)
{
ClientScript.RegisterStartupScript(GetType(), "MyAlert2",
"alert('Deleting');", true);
}
}
And I have changed this in the CSVDataSource Example
public override bool CanDelete
{
get
{
return true; //changed this
}
}
And have to do some stuff here that I know
protected override int ExecuteDelete(IDictionary keys, IDictionary values)
{
throw new NotSupportedException();
}
But the Execute Delete is not called. What more do I have to do to get the
GridView know that the CsvDataSource handles deletes? I am not getting this
exception:
NotSupportedException: Specified method is not supported.]
System.Web.UI.DataSourceView.ExecuteDelete(IDictionary keys, IDictionary
oldValues) +28
System.Web.UI.DataSourceView.Delete(IDictionary keys, IDictionary
oldValues, DataSourceViewOperationCallback callback) +75
System.Web.UI.WebControls.GridView.HandleDelete(GridViewRow row, Int32
rowIndex) +927
But this exception:
System.Web.UI.WebControls.GridView.OnRowDeleting(GridViewDeleteEventArgs e)
+325
System.Web.UI.WebControls.GridView.HandleDelete(GridViewRow row, Int32
rowIndex) +732
MarcWentink