Ok, have a look at my functions below, to do the Update/Edit/Cancel:
 
It might give you a hint on what you are missing, if you dont get to anything, then still let me know, i will try to look at it later for more depth...
 

private void dgAccessRights_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)

            {

                  // Select the current row for 'edit mode'

                  this.dgAccessRights.EditItemIndex = e.Item.ItemIndex;

 

                  // Refill DataSets with information

                  //FillDataSet(dset);

                 

                  // Rebind data

                  clsMDMS objMDMS = new clsMDMS();

                  //objMDMS.BindGrid(((DataSet)ViewState["SelectedUserAccess"]).Tables[0],"Access_Right_ID",this.dgAccessRights);

                  // Select default dropdown option, as earlier

                  DropDownList ddl = (DropDownList)e.Item.FindControl("cmb_Access_Right");

                  objMDMS.BindGrid(((DataSet)ViewState["SelectedUserAccess"]).Tables[0],"Rep_ID",this.dgAccessRights);

                  objMDMS.PopulateDropDown("wc_Access_Rights_List",ddl,"Please Select Access Right.");

           

                 

           

                  //ddl.SelectedIndex =ddl.Items.IndexOf( ddl.Items.FindByValue(e.Item.Cells[1].Text));

                  LinkButton lb = (LinkButton)e.Item.Cells[2].Controls[0];

                  string strForeignKey = lb.Text;

                  ddl.SelectedIndex =ddl.Items.IndexOf(ddl.Items.FindByValue(strForeignKey));

                 

            }

 

      private void dgAccessRights_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)

            {

                 

                  clsMDMS objMDMS = new clsMDMS();

                  try

                  {

                        // Step one: Put dropdown list value into foreign key field

                        //((TextBox)e.Item.Cells[2].Controls[0]).Text = ((DropDownList)e.Item.FindControl("cmb_Access_Right")).SelectedItem.Value;

                       

                        string strEditedValue = ((DropDownList)e.Item.FindControl("cmb_Access_Right")).SelectedItem.Value;

                 

                       

                        LinkButton lb = (LinkButton)e.Item.Cells[5].Controls[0];

                        string strPrimaryKey = lb.Text;

                        //string strPrimaryKey =((Label)e.Item.FindControl("lblRep_ID")).Text.ToString();

                        // Step two: Fill DataSet and identify row to edit

                        DataSet dsetAccessRights = (DataSet)ViewState["SelectedUserAccess"];

                 

                        UpdateRecord(strPrimaryKey,strEditedValue);

                        //DataRow objEditedRow = (dsetAccessRights).Tables[0].Rows.Find( ((TextBox)e.Item.Cells[1].Controls[0]).Text);

 

                        // Step three: Cycle through valid "data" cells and put

                        // information back in underlying DataSet

                        /*int intCount;

                              for(intCount=0;intCount<=e.Item.Cells.Count-1;intCount++)

                              {

                                    if( e.Item.Cells[intCount].Controls.Count > 0 )

                                    {

                                          if((e.Item.Cells[intCount].Controls[0]) is TextBox)

                                          {

                                                //This appears to be a TextBox-holding "data" cell

                                                string strValue = ((TextBox)(e.Item.Cells[intCount].Controls[0])).Text;

                                                // Put value (or null if empty) back into relevant DataSet field

                                                if (strValue == "")

                                                {

                                                      objEditedRow[dgAccessRights.Columns[intCount].SortExpression] = System.DBNull.Value;

                                                }

                                                else

                                                {

                                                      objEditedRow[dgAccessRights.Columns[intCount].SortExpression]  = strValue;

                                                }

                                          }

                                    }

                              }

                              */

                        // Update backend data

                       

                        //ParentNewsArticleDataAdapter.Update(MyDataSet)

                        //UpdateRecords(dsetAccessRights);

                        this.dgAccessRights.SelectedIndex = -1;

                        this.dgAccessRights.EditItemIndex = -1;

                        LoadRecords();

                       

                        myObj.BindGrid(((DataSet)ViewState["SelectedUserAccess"]).Tables[0],"Rep_ID",this.dgAccessRights); 

                        // Deselect DataGrid items and rebind

            }

                  catch (Exception ex1)

                  {

                       

                        myObj.DisplayWebPageErrMessage(ex1.Message);

 

                  }

                 

                 

 

 

            }

 

            private void dgAccessRights_CancelCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)

            {

                  this.dgAccessRights.EditItemIndex = -1;

                  myObj.BindGrid(((DataSet)ViewState["SelectedUserAccess"]).Tables[0],"Rep_ID",this.dgAccessRights); 

            }

           

 

      }

      private void dgAccessRights_CancelCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)

            {

                  this.dgAccessRights.EditItemIndex = -1;

                  myObj.BindGrid(((DataSet)ViewState["SelectedUserAccess"]).Tables[0],"Rep_ID",this.dgAccessRights); 

}


Yahoo! Groups Sponsor
ADVERTISEMENT
click here


Yahoo! Groups Links

Reply via email to