الاثنين، 15 يونيو 2015

Update Cell Element in RadGridView


it's better to create a class for all user msgs .. 



private void grvDepartment_CellValidating(object sender, CellValidatingEventArgs e)
        {
            var column = e.Column as GridViewDataColumn;
            if (e.Row is GridViewDataRowInfo && column != null && column.Name == "DepartmentName")
            {
                if (string.IsNullOrEmpty((string) e.Value) || ((string) e.Value).Trim() == string.Empty)
                {
                    e.Cancel = true;
                    //e.Row.ErrorText = "Validation error!";
                    RadMessageBox.Show("Please write Department name");
                }
                else
                {
                    int departmentId = Convert.ToInt32(grvDepartment.Rows[e.RowIndex].Cells["DepartmentId"].Value);
                    Department user =
                        (from u in _outEntities.Department
                            where u.DepartmentName == (string) e.Value && u.DepartmentId != departmentId
                            select u)
                            .FirstOrDefault();
                    if (user != null)
                    {
                        e.Cancel = true;
                        //e.Row.ErrorText = "Validation error!";
                        RadMessageBox.Show("Department name already exits");
                    }
                }
            }
            else if (e.Row is GridViewDataRowInfo && column != null && column.Name == "DepartmentAcronum")
            {
                if (string.IsNullOrEmpty((string)e.Value) || ((string)e.Value).Trim() == string.Empty)
                {
                    e.Cancel = true;
                    //e.Row.ErrorText = "Validation error!";
                    RadMessageBox.Show("Please write Department acronum");
                }
                else
                {
                    int departmentId = Convert.ToInt32(grvDepartment.Rows[e.RowIndex].Cells["DepartmentAcronum"].Value);
                    Department user =
                        (from u in _outEntities.Department
                         where u.DepartmentAcronum == (string)e.Value && u.DepartmentId != departmentId
                         select u)
                            .FirstOrDefault();
                    if (user != null)
                    {
                        e.Cancel = true;
                        //e.Row.ErrorText = "Validation error!";
                        RadMessageBox.Show("Department acronum already exits");
                    }
                }
            }
        }

ليست هناك تعليقات:

إرسال تعليق