This is a migrated thread and some comments may be shown as answers.

cancel button working by clicking two times when i am useing e.cancel true in grid_UpdateCommand

0 Answers 33 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Manish
Top achievements
Rank 2
Manish asked on 28 Dec 2012, 06:08 AM
Hi,
I am inserting data in grid but i want to keep grid in edit mode if validation false. For that i am using e.canceled=true in else part.
But after that cancel is not working in one time i have to click it two times. Please help
 
 protected void rgBankAccount_UpdateCommand(object source, GridCommandEventArgs e)
        {
            if (ViewState["CommandName"] != null)
                strCommandName = ViewState["CommandName"].ToString();
            if (e.Item.OwnerTableView.Name == "Master")
            {
                UserControl ParentUserControl = (UserControl)e.Item.FindControl(GridEditFormItem.EditFormUserControlID);
                TextBox txtAccount = ParentUserControl.FindControl("txtAccount") as TextBox;
               //Label lblError = ParentUserControl.FindControl("lblError") as Label;
                RadDatePicker rdpAsof = ParentUserControl.FindControl("rdpAsof") as RadDatePicker;
                RadNumericTextBox RNTXTAccountNumber = ParentUserControl.FindControl("RNTXTAccountNumber") as RadNumericTextBox;
                RadNumericTextBox RNTXTBeginningBalance = ParentUserControl.FindControl("RNTXTBeginningBalance") as RadNumericTextBox;
                if (strCommandName == "Update")
                {
                    int AccountID = 0;
                    if (ViewState["AccountID"] != null)
                        AccountID = Convert.ToInt32(ViewState["AccountID"].ToString());
                    int AccountCount = objGetData.GetAccountExist(txtAccount.Text, AccountID, GroupID);
                    if (AccountCount == 0)
                    {
                        objUpdateData.UpdateBankAccount(AccountID, rdpAsof.SelectedDate.ToString(), txtAccount.Text,                        RNTXTAccountNumber.Text, Convert.ToDouble(RNTXTBeginningBalance.Text));
                        ViewState["AccountID"] = null;
                        lblError.Visible = false;
                     
                    }
                    else
                    {
                        lblError.Visible = true;
                        lblError.Text = "Please select another name";
                                             e.Canceled = true; *********************************** //// I have used it here
                    }
                }
                else
                {
                    int AccountCount = objGetData.GetAccountExist(txtAccount.Text, 0, GroupID);
                    if (AccountCount == 0)
                    {
                    objAddData.AddBankAccount(rdpAsof.SelectedDate.ToString(), txtAccount.Text, RNTXTAccountNumber.Text, Convert.ToDouble(RNTXTBeginningBalance.Text), GroupID);
                    lblError.Visible = false;
                    }
                    else
                    {
                        lblError.Visible = true;
                        lblError.Text = "Please select another name";
                       e.Canceled = true; *********************************** //// I have used it here
                    }
                }
            }
        }

Thanks
Manish

No answers yet. Maybe you can help?

Tags
Grid
Asked by
Manish
Top achievements
Rank 2
Share this question
or