CodeVerge.Net Beta


   Item Entry   Register  Login  
Microsoft News
Asp.Net Forums
IBM Software
Borland Forums
Adobe Forums
Novell Forums




Can Reply:  No Members Can Edit: No Online: Yes
Zone: > Asp.Net Forum > general_asp.net.web_parts_and_personalization Tags:
Item Type: Date Entered: 12/6/2005 8:54:29 AM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
NR
XPoints: N/A Replies: 2 Views: 160 Favorited: 0 Favorite
3 Items, 1 Pages 1 |< << Go >> >|
"haridasi" <>
NewsGroup User
GridView.RowDeleted event not firing in a webpart12/6/2005 8:54:29 AM

0

I have a webpart where a gridview is defined programmatically. Editing etc. works, but when I try to delete a row in the gridview, the row is never deleted. It enters the RowDeleting event, but not the RowDeleted event.

I need some help here, and hope some of you guys can give me a helping hand. :-)

Code:

public class DocumentReport : WebPart
{
GridView gvDocuments;
SqlDataSource gvDataSource;
string _guid;

public DocumentReport()
{
gvDataSource = new SqlDataSource();
gvDataSource.ConnectionString = ConfigurationManager.ConnectionStrings["DBServer"].ConnectionString;
gvDataSource.ProviderName = ConfigurationManager.ConnectionStrings["DBServer"].ProviderName;
gvDataSource.SelectCommand = DatabaseQueries.DocumentReports_Select;
gvDataSource.DeleteCommand = DatabaseQueries.DocumentReports_Delete;

this.AllowClose = false;
this.AllowEdit = false;
this.AllowHide = false;
this.AllowMinimize = false;
this.Title = Resources.AirOnline.DocumentReport_Title;
}

protected override void CreateChildControls()
{
gvDocuments = new GridView();
gvDocuments.DataKeyNames = new string[] { "AODR_GUID" };
gvDocuments.AutoGenerateColumns = false;
gvDocuments.AutoGenerateSelectButton = false;
gvDocuments.AutoGenerateDeleteButton = true;
gvDocuments.AutoGenerateEditButton = false;
gvDocuments.RowCommand += new GridViewCommandEventHandler(gvDocuments_RowCommand);
gvDocuments.RowDeleting += new GridViewDeleteEventHandler(gvDocuments_RowDeleting);
gvDocuments.RowDeleted += new GridViewDeletedEventHandler(gvDocuments_RowDeleted);

BoundField bfTitle = new BoundField();
bfTitle.DataField = "AODR_Title";

ButtonField btnEdit = new ButtonField();
btnEdit.Text = "Edit";
btnEdit.CommandName = "EditRow";

gvDocuments.Columns.Add(bfTitle);
gvDocuments.Columns.Add(btnEdit);

this.Controls.Add(gvDocuments);
gvDocuments.DataSource = gvDataSource;
gvDocuments.DataBind();
}

void gvDocuments_RowDeleted(object sender, GridViewDeletedEventArgs e)
{
string sdf = "";
}

void gvDocuments_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
DBHandler dbManager = (DBHandler)this.Page.Application["DBManager"];
DataSet dsReport = null;
// Delete the file connected to the row being deleted
dsReport = dbManager.ExecuteDataSet(null, DatabaseQueries.DocumentReports_SelectChosenReport, new OracleParameter(":AODR_GUID", gvDocuments.DataKeys[e.RowIndex]["AODR_GUID"].ToString()));

try
{
if (dsReport != null)
{
string filepath = @Page.Server.MapPath("~") + ConfigurationManager.AppSettings["fileUploadReports"] + dsReport.Tables[0].Rows[0]["AODR_FILENAME"].ToString();
File.Delete(filepath);
}
}
catch (Exception ex)
{ }
}

void gvDocuments_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "EditRow")
{
gvDocuments.SelectedIndex = Convert.ToInt32(e.CommandArgument);
this.WebPartManager.DisplayMode = WebPartManager.EditDisplayMode;
this.WebPartManager.BeginWebPartEditing(this);
}
}

public override EditorPartCollection CreateEditorParts()
{
DocumentReportEditorPart edit = new DocumentReportEditorPart();
edit.ID = "DocumentEditor";

DocumentTypeEditorPart doctype = new DocumentTypeEditorPart();
doctype.ID = "DocumentTypeEditor";

DocumentStatusEditorPart docStatus = new DocumentStatusEditorPart();
docStatus.ID = "DocumentStatusEditor";

ArrayList editorArray = new ArrayList();
editorArray.Add(edit);
editorArray.Add(doctype);
editorArray.Add(docStatus);
EditorPartCollection editorParts = new EditorPartCollection(editorArray);
return editorParts;
}

public override WebPartVerbCollection Verbs
{
get
{
WebPartVerb NewVerb = new WebPartVerb("New", new WebPartEventHandler( this.AddNewDocument));
NewVerb.Text = Resources.AirOnline.DocumentReport_MenuAddNew;
NewVerb.Description = Resources.AirOnline.DocumentReport_MenuAddNew;

WebPartVerb[] verbs = new WebPartVerb[] { NewVerb };
return new WebPartVerbCollection(verbs);
}
}

public void AddNewDocument(object sender, WebPartEventArgs e)
{
gvDocuments.SelectedIndex = -1;
this.WebPartManager.DisplayMode = WebPartManager.EditDisplayMode;
this.WebPartManager.BeginWebPartEditing(this);
}

public GridView DataContainer
{
get { return gvDocuments; }
}

[Personalizable()]
public string guid
{
get { return _guid; }
set { _guid = value; }
}
}

Girl Power ! ;-P
"phuff" <>
NewsGroup User
Re: GridView.RowDeleted event not firing in a webpart12/7/2005 10:19:27 PM

0

Hi again Haridasi-

The reason your GridView never gets to the RowDeleted event is because you are binding the SqlDataSource control to the GridView via the GridView's DataSource property instead of its DataSourceID property.  Even though the SqlDataSource is a data source control, when you bind it to the GridView via the DataSource property, the GridView can't take advantage of automatic data updates, deletes, inserts, or sorting.

To take advantage of the SqlDataSource's capabilities and have the GridView automatically update, delete, sort, etc., you need to add the SqlDataSource to the page and use the GridView's DataSourceID property to bind to it. 

If you prefer to bind through the DataSource property, you will have to call Delete on the SqlDataSource or its view directly in your handler for RowDeleting.


Polita Paulus


This posting is provided "AS IS" with no warranties, and confers no rights.
"haridasi" <>
NewsGroup User
Re: GridView.RowDeleted event not firing in a webpart12/12/2005 10:29:09 AM

0

Hey phuff,

It's so great there's a female .net expert on the team :-)

Thanks for the tip, I was hoping I could get away with not doing it "manually", but a girl's gotta do what a girl's gotta do. :-)
Girl Power ! ;-P
3 Items, 1 Pages 1 |< << Go >> >|


Free Download:













error: object reference not set to an instance of an object.

configuration error in visual studio.net

newbie question - post issue tracker install issue

portal security in new aspx pages

i need an alert/warning/confrim box

please help - unable to set breakpoint in desktopdefault page

timetracker for rainbow portal

configuration error

porting ibuyspy to delphi 8

bug when setting up new user with admins priveledges

stored procedure

looking for guestbook module

change namespace aspnet.starterkit.portal

need a litle help

portal authentication

space in c#

unable to spawn acrobat reader when streaming application/pdf mime type.

user control within ibuyspy - system.invalidcastexception: specified cast is not valid.??

portal site map..

please help me i will be crayz

how can i make a copy of my portal?

question about personal portal settings

install error- database connection failure

sql server 7

employee detail option

decision time

mk.bat error

trusted-connection

printing contents of a module without printing the whole page.

managing db's: dev, integration, prod environment

oracle 9i ddl for ibuyspy.

sign-in module is not displayed on portal home page

object reference not set to an instance of an object

xml vs sql?

ibuyspy workshop

stupid newbie question

enternal announcements

how to start

admin tab

datagrid(w/paging) - after edit how to go back to correct page?help!

checkbox validation, raise error immediately?

portal starter kit

wrox content management error

about the aspnet account

probs installing at webserver

system.invalidcastexception:invalidcast,what is the matter?

problems installing the portal

multiple applications within the same portal. urgent !!!

portal configuration (iis)

authentication problems

   
  Privacy | Contact Us
All Times Are GMT