Gridview Edit State

Feb 19 2013 8:10 AM
When using gridview I have a textbox that returns results and loads the grid.

When I want to edit the row I have a different method that has the ID of the row being edited and it complains about ViewState.

I have tried disabling viewstate and making it inherit but then it wont do theupdate as it cant remeber the viewstate.

When view state is disabled.  On the LoadGridEdit() I have to press edit twice and then it will make the labels/textboxs editable. but wont update.

this is my method for LoadGrid():
        private void LoadGrid()
        {
            try
            {
                using (dbDataContext _db = new dbDataContext())
                {
                    var loadGrid = _db.tbl_Users.Where(u => u.Deleted == false)
                        .Select(u => new
                                    {
                                        u.UserId,
                                        u.UserName,
                                        u.Email,
                                        u.IsAdmin,
                                        u.ServiceAreaId,
                                        u.tbl_ServiceArea.ServiceArea
                                        });

                    grd_User.DataSource = loadGrid;
                    grd_User.DataBind();
                }
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
            }
        }


and this is the method for LoadGridEdit()

        private void LoadGridEdit(int i_ID)
        {
            using (dbDataContext _db = new dbDataContext())
            {
                var result = _db.tbl_Users.Where(u => u.UserId == i_ID)
                    .Select(u => new
                                    {
                                        u.UserId,
                                        u.UserName,
                                        u.Email,
                                        u.IsAdmin,
                                        u.ServiceAreaId,
                                        u.tbl_ServiceArea.ServiceArea,
                                    });

                //if (IsAdmin)
                //{
                //    var chkBox = (CheckBox) grd_User.Rows[count].FindControl("chk_Val_Admin");
                //    if (chkBox != null)
                //    {
                //        chkBox.Checked = true;
                //    }
                //}

                grd_User.DataSource = result;
                grd_User.DataBind();
            }
        }

because what I want to achieve is to load the grid again when I press edit and if the are admin from the DB then the Checkbox iin EditMode sound be checked.
Because when the grid is in edit mode there is a checkbox to see if you want to change this to admin, and if you dont check it you are no longer admin.
which is not good as you have to be admin to get to this part of the site.