It is possible to attach those in the CreateChildControls but it will have the same result, thats why I have chosen to place it in the BindData(). With every postback those eventhandlers have to be reattached.
Further, there is no cycle or an endless loop. After reattaching the eventhandlers it will not execute the eventhandlers again. This have something to do with the page lifecycle, it will execute the events just once. Ive looked on internet but there is almost no results on google where the update button executes the rowediting event instead of the rowupdating event. For more info, there is an demo on http://test.cezus.nl click in the demo on edit and then on update and you see there is no change in the page because it executes the rowupdating event again. On 4 mei, 12:45, Cerebrus <[email protected]> wrote: > I don't get it at all... Why would you attach your eventhandlers in > the BindData() method when you call this method from the Eventhandlers > themselves ? > > Don't you see a cycle here ? > > On May 4, 2:21 pm, Cezus <[email protected]> wrote: > > > Hello, > > > I have a problem in my composite control. In this composite control I > > create a GridView in one of the TableCells of a Table control. This > > GridView has multiple events on it, such as rowediting event, > > rowupdating event, rowcancelingedit event. > > > image:http://www.cezus.nl/GridView.JPG > > > [code] > > private void BindData() > > { > > _gvCategories = (GridView)this.FindControl > > ("gvCategories"); > > _dtCategories = (DataTable)HttpContext.Current.Session > > ["dtCategories"]; > > > _gvCategories.DataSource = _dtCategories; > > _gvCategories.AutoGenerateDeleteButton = true; > > _gvCategories.AutoGenerateEditButton = true; > > _gvCategories.RowEditing += new GridViewEditEventHandler > > (_gvCategories_RowEditing); > > _gvCategories.RowUpdating += new GridViewUpdateEventHandler > > (_gvCategories_RowUpdating); > > _gvCategories.RowDeleting += new GridViewDeleteEventHandler > > (_gvCategories_RowDeleting); > > _gvCategories.RowCreated += new GridViewRowEventHandler > > (_gvCategories_RowCreated); > > _gvCategories.RowCancelingEdit += new > > GridViewCancelEditEventHandler(_gvCategories_RowCancelingEdit); > > > _gvCategories.DataBind(); > > } > > > void _gvCategories_RowEditing(object sender, > > GridViewEditEventArgs e) > > { > > _gvCategories = (GridView)sender; > > _gvCategories.EditIndex = e.NewEditIndex; > > BindData(); > > } > > > void _gvCategories_RowUpdating(object sender, > > GridViewUpdateEventArgs e) > > { > > _gvCategories = (GridView)sender; > > _dtCategories = (DataTable)HttpContext.Current.Session > > ["dtCategories"]; > > GridViewRow row = _gvCategories.Rows[e.RowIndex]; > > > foreach (DataRow dr in _dtCategories.Rows) > > { > > if (dr.RowState != DataRowState.Deleted) > > { > > if (Convert.ToInt32(dr["drID"]) == Convert.ToInt32 > > (((TextBox)(row.Cells[3].Controls[0])).Text)) > > { > > dr["ID"] = ((TextBox)(row.Cells[1].Controls > > [0])).Text; > > dr["Categorie"] = ((TextBox)(row.Cells > > [2].Controls[0])).Text; > > } > > } > > } > > _gvCategories.EditIndex = -1; > > HttpContext.Current.Session["dtCategories"] = > > _dtCategories; > > > BindData(); > > > Button _btnNieuw = (Button)this.FindControl("btnNieuw"); > > _btnNieuw.Enabled = true; > > > } > > [/code] > > > If I press on the 'edit' button in the GridView it goes to the > > rowediting event. If I press after that on the 'update' button it goes > > again through the rowediting event instead of going through the > > rowupdating event. > > > I am struggling for 2 days with this, I hope somebody knows a > > solution. > > > With Kind Regards, > > > Cees van Altena
