|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
datagrid update/cancel command not workingI created a page with datagrid where i can edit, update, cancel the data. but rather strangely the update and cancel commands are not working. Only Edit button works. Did any one face the same problem before. Neither dgMasterData_CancelCommand() nor dgMasterData_UpdateCommand() is getting the control. I debugged and found that when I click update command the control goes to dgMasterData_EditCommand(), Also e.commandName has value "Edit" instead of "Update". (I already tried the ultimate solutions: Closing VS.Net and reloading the project,deleting the event handlers, and readding etc) ;) any pointers? I have a decent amount of time trying to figure out what was happening. but no luck.. > I created a page with datagrid where i can edit, update, cancel the Are you setting the EditItemIndex back to -1 on 'Cancel' et al?> data. but rather strangely the update and cancel commands are not > working. Only Edit button works. And are the commands and methods properly wired? -- Happy Hacking, Gaurav Vaish | http://www.mastergaurav.com http://www.edujinionline.com http://articles.edujinionline.com/webservices ------------------- I set up my screens like this:
<asp:TemplateColumn> <ItemStyle Wrap="false"></ItemStyle> <ItemTemplate> <asp:imagebutton runat="server" CommandName="Edit" BorderWidth="0" ImageURL="../images/edit.gif" alt="Edit"/> <asp:imagebutton runat="server" CommandName="Delete" id="btnDelete" BorderWidth="0" ImageURL="../images/delete.gif" alt="Delete" /> </ItemTemplate> <EditItemTemplate> <asp:imagebutton runat="server" CommandName="Update" BorderWidth="0" ImageURL="../images/update.gif" alt="Save"/> <asp:imagebutton runat="server" CommandName="Cancel" BorderWidth="0" ImageURL="../images/cancel.gif" alt="Cancel"/> </EditItemTemplate> <FooterTemplate> <asp:imagebutton runat="server" CommandName="Insert" BorderWidth="0" ImageURL="../images/add.gif" alt="Add"/> </FooterTemplate> </asp:TemplateColumn> And this is the codebehind: public void DataGrid_ItemCommand (Object sender, DataGridCommandEventArgs e) { if (((ImageButton)e.CommandSource).CommandName == "Insert") {DataGrid_Insert(sender, e);} if (((ImageButton)e.CommandSource).CommandName == "Delete") {DataGrid_Delete(sender, e);} } public void DataGrid_Edit (Object sender, DataGridCommandEventArgs e) { DataGrid.EditItemIndex = e.Item.ItemIndex; DataGrid.ShowFooter = false; } public void DataGrid_Cancel (Object sender, DataGridCommandEventArgs e) { DataGrid.EditItemIndex = -1; DataGrid.ShowFooter = true; } public void DataGrid_Update (Object sender, DataGridCommandEventArgs e) { DataGrid.EditItemIndex = -1; DataGrid.ShowFooter = true; } public void DataGrid_Insert (Object sender, DataGridCommandEventArgs e) { DataGrid.EditItemIndex = -1; } public void DataGrid_Delete (Object sender, DataGridCommandEventArgs e) { DataGrid.EditItemIndex = -1; } //Add a "confirm" to the Delete button public void DataGrid_ItemCreated(Object sender, DataGridItemEventArgs e) { ListItemType itemType = e.Item.ItemType; if (itemType == ListItemType.Item || itemType == ListItemType.AlternatingItem) { ImageButton ib = (ImageButton) e.Item.FindControl("btnDelete"); if (ib != null) { ib.Attributes.Add("onclick", "return confirm('Delete this record?');"); } } } If you're running VB, be sure you haven't lost the "handles" clauses on your events. I hate it when that happens!! HTH Dan Thanks Dan and Gaurav,
events are properly wired and here is the code : let me know if you find something wrong here.. <ASP:DATAGRID ID="dgMasterData" RUNAT="server" SHOWFOOTER="True" AUTOGENERATECOLUMNS="False" ONUPDATECOMMAND="dgMasterData_UpdateCommand" ONCANCELCOMMAND="dgMasterData_CancelCommand"> <EDITITEMSTYLE CSSCLASS="dgEditItem"></EDITITEMSTYLE> <ALTERNATINGITEMSTYLE CSSCLASS="dgAlternateItem"></ALTERNATINGITEMSTYLE> <ITEMSTYLE CSSCLASS="dgItemStyle"></ITEMSTYLE> <HEADERSTYLE CSSCLASS="dgHeader"></HEADERSTYLE> <COLUMNS> <ASP:TEMPLATECOLUMN VISIBLE="False"> <ITEMTEMPLATE> <ASP:LABEL ID="lblMstrDataID" RUNAT="server" TEXT='<%# DataBinder.Eval(Container.DataItem,"mstrDataID")%>'> </ASP:LABEL> </ITEMTEMPLATE> </ASP:TEMPLATECOLUMN> <ASP:TEMPLATECOLUMN HEADERTEXT="Description"> <ITEMTEMPLATE> <%# DataBinder.Eval(Container.DataItem,"mstrDataValue")%> </ITEMTEMPLATE> <FOOTERTEMPLATE> <ASP:TEXTBOX ID="tbNewMasterDataValue" RUNAT="server" CSSCLASS="tboxClass"></ASP:TEXTBOX> </FOOTERTEMPLATE> <EDITITEMTEMPLATE> <ASP:TEXTBOX ID="tbMasterDataValue" RUNAT="server" CSSCLASS="tboxClass" TEXT='<%# DataBinder.Eval(Container.DataItem,"mstrDataValue")%>'> </ASP:TEXTBOX> </EDITITEMTEMPLATE> </ASP:TEMPLATECOLUMN> <ASP:EDITCOMMANDCOLUMN BUTTONTYPE="PushButton" UPDATETEXT="Update" CANCELTEXT="Cancel" EDITTEXT="Edit"></ASP:EDITCOMMANDCOLUMN> <ASP:TEMPLATECOLUMN> <FOOTERTEMPLATE> <ASP:BUTTON ID="btnSaveNewMstrData" RUNAT="server" TEXT="Add New" ONMOUSEOVER="btn_FocusOn(this)" ONMOUSEOUT="btn_FocusOff(this)" CSSCLASS="mfbuttonCellText" COMMANDNAME="Add New"></ASP:BUTTON> </FOOTERTEMPLATE> </ASP:TEMPLATECOLUMN> </COLUMNS> </ASP:DATAGRID> private void InitializeComponent() { this.ddMasterData.SelectedIndexChanged += new System.EventHandler(this.ddMasterData_SelectedIndexChanged); this.dgMasterData.CancelCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.dgMasterData_CancelCommand); this.dgMasterData.EditCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.dgMasterData_EditCommand); this.dgMasterData.UpdateCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.dgMasterData_UpdateCommand); this.dgMasterData.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.dgMasterData_ItemDataBound); this.Load += new System.EventHandler(this.Page_Load); } private void dgMasterData_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) { try { dgMasterData.EditItemIndex = e.Item.ItemIndex; } catch(Exception ex) { Response.Write(ex.Message.ToString()); } } public void dgMasterData_CancelCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) { dgMasterData.SelectedIndex = -1; } public void dgMasterData_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) { ......... } DanG wrote: Show quoteHide quote > I set up my screens like this: > > <asp:TemplateColumn> > <ItemStyle Wrap="false"></ItemStyle> > <ItemTemplate> > <asp:imagebutton runat="server" CommandName="Edit" > BorderWidth="0" ImageURL="../images/edit.gif" alt="Edit"/> > <asp:imagebutton runat="server" CommandName="Delete" > id="btnDelete" BorderWidth="0" ImageURL="../images/delete.gif" > alt="Delete" /> > </ItemTemplate> > > <EditItemTemplate> > <asp:imagebutton runat="server" CommandName="Update" > BorderWidth="0" ImageURL="../images/update.gif" alt="Save"/> > <asp:imagebutton runat="server" CommandName="Cancel" > BorderWidth="0" ImageURL="../images/cancel.gif" alt="Cancel"/> > </EditItemTemplate> > > <FooterTemplate> > <asp:imagebutton runat="server" CommandName="Insert" > BorderWidth="0" ImageURL="../images/add.gif" alt="Add"/> > </FooterTemplate> > </asp:TemplateColumn> > > And this is the codebehind: > > public void DataGrid_ItemCommand (Object sender, > DataGridCommandEventArgs e) { > if (((ImageButton)e.CommandSource).CommandName == "Insert") > {DataGrid_Insert(sender, e);} > if (((ImageButton)e.CommandSource).CommandName == "Delete") > {DataGrid_Delete(sender, e);} > } > > public void DataGrid_Edit (Object sender, DataGridCommandEventArgs e) { > DataGrid.EditItemIndex = e.Item.ItemIndex; > DataGrid.ShowFooter = false; > } > > public void DataGrid_Cancel (Object sender, DataGridCommandEventArgs e) > { > DataGrid.EditItemIndex = -1; > DataGrid.ShowFooter = true; > } > > > public void DataGrid_Update (Object sender, DataGridCommandEventArgs e) > { > DataGrid.EditItemIndex = -1; > DataGrid.ShowFooter = true; > } > > public void DataGrid_Insert (Object sender, DataGridCommandEventArgs e) > { > DataGrid.EditItemIndex = -1; > } > > public void DataGrid_Delete (Object sender, DataGridCommandEventArgs e) > { > DataGrid.EditItemIndex = -1; > } > > //Add a "confirm" to the Delete button > public void DataGrid_ItemCreated(Object sender, DataGridItemEventArgs > e) { > ListItemType itemType = e.Item.ItemType; > if (itemType == ListItemType.Item || itemType == > ListItemType.AlternatingItem) { > ImageButton ib = (ImageButton) e.Item.FindControl("btnDelete"); > if (ib != null) { > ib.Attributes.Add("onclick", "return confirm('Delete this > record?');"); > } > } > } > > If you're running VB, be sure you haven't lost the "handles" clauses on > your events. I hate it when that happens!! > > HTH > Dan May be you can send the code as attachment (the aspx/.cs files)
It's kinda unreadable here :-) -- Show quoteHide quoteHappy Hacking, Gaurav Vaish | http://www.mastergaurav.com http://www.edujinionline.com http://articles.edujinionline.com/webservices ------------------- <madhu.da***@gmail.com> wrote in message news:1158292277.909693.173180@i42g2000cwa.googlegroups.com... > Thanks Dan and Gaurav, > > events are properly wired and here is the code : let me know if you > find something wrong here.. >
How do I return the name (ID) of a user control?
Detailsview - how to reference a field in Java/VB Script How do I stop this javascript from being emitted? ASP.net 2.0 DropdownList bound to SQLDataSource and setting SelectedIndex Smart Navigation asp.net 2.0 menu client script error Calendar control calendar control - weekends word wrap in ultrawebtree word wrap in ultrawebtree word wrap in ultrawebtree |
|||||||||||||||||||||||