Cezus, You're most welcome and it's been my pleasure to assist. I'm glad it now "walks like the sun" ! :-)
Happy coding! On May 7, 2:12 pm, Cezus <[email protected]> wrote: > Thank you for your help in this thread, it cost me some days to think > about but I know now what you mean with the cycle. > > I removed the databinding from the CreateChildControls and it is only > called at the end of the requirering events. The attaching of the > events will now be performed in the OnInit. As we say normally in > dutch: It now walks like a sun! ( It works smoothly as it should be! ) > > Thank you! > > I even get some more information for composite controls from your > links! > > On 4 mei, 21:46, Cerebrus <[email protected]> wrote: > > > > > What I am trying to imply is that attaching eventhandlers in the > > DataBind() method is not the correct way to do it. (and nor is doing > > it in CreateChildControls()). > > > I would probably try attaching the eventhandlers in the OnInit > > override. If that doesn't work, I would expose the GridView's events > > as top level events of the Composite control using the Event bubbling > > method. For more information, refer to Dino Esposito's article here: > > <http://msdn.microsoft.com/en-us/library/aa479016.aspx> > > > and MSDN: <http://msdn.microsoft.com/en-us/library/aa719734(VS. > > 71).aspx> > > > Event bubbling sample: <http://msdn.microsoft.com/en-us/library/ > > aa720044(VS.71).aspx> > > > On May 4, 6:50 pm, Cezus <[email protected]> wrote: > > > > 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- Hide quoted text - > > > > - Show quoted text -- Hide quoted text - > > - Show quoted text -
