Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

Posted

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!

Posted

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;

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...