CsvDataSource : how to extend the example so it calls handle delete?

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,817
Latest member
AdalbertoT

Latest Threads

Top