lorena Posted July 17, 2006 Posted July 17, 2006 I have a datagrid that allows editing. If a certain group of users accesses the page, however, I would like the page set up to only edit one field and not all of the edit fields? The admin user would have the ability to edit all fields in the grid. Can this be done through ItemDataBound? If so, does anyone have an example of how to do it? Hope this makes sense. Quote
APaule Posted July 18, 2006 Posted July 18, 2006 Int32 myEditIndex = -1; protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e) { myEditIndex = e.NewEditIndex; } protected void GridView1_PreRender(object sender, EventArgs e) { if (myEditIndex > -1) { GridView1.Rows[myEditIndex].Cells[1].Enabled = false; } } What you want to do, has to be done in the PreRender event of the grid. I did'nt find a way to affect the ReadOnly property directly, but this one works. And don't forget to reset the the var myEditIndex to -1 in RowEditCanceling and RowUpdating! Quote
lorena Posted July 18, 2006 Author Posted July 18, 2006 Thanks so much. I will give that a shot! Quote
APaule Posted July 18, 2006 Posted July 18, 2006 Welcome, but I fear you won't be so happy with my solution, because I just realized that you were looking for the datagrid. And this sounds much like asp.net 1.1 and I gave you a solution for the gridview of version 2.0. In version 1.1 you can try something that raises a conversionexception in 2.0 during compiletime (strange but true). So here you should be able to change the ReadOnly property directly: BoundColumn col = (BoundColumn)DataGrid1.Column(1); col.ReadOnly = false; Quote
lorena Posted July 18, 2006 Author Posted July 18, 2006 Yes, I am still chugging along with VS2003. The BoundColumn code - is that still in the PreRender event? Quote
APaule Posted July 19, 2006 Posted July 19, 2006 Yes lorena, this is still the place where it has to be done. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.