Disable Dropdown list in GridView(Edit Mode)

H

Houston Lucifer

Hi all, i have three column in GridView which in the edit mode are dropdown
lists. Based on the role, when the user clicks on the 'Edit' Button i need to
disable any two of those columns. How can i do this. Can i generate the 'Edit
Item Template' at runtime? Is there any easy way?

Thanks for the help.
 
P

Phillip Williams

Hi Houston,

You can use the RowCreated event like this:

protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowState == DataControlRowState.Edit)
{
DropDownList ddl1 = (DropDownList)e.Row.FindControl("dropdownlist1");
//use the reference to the dropdownlist to enable or disable it
based on the roles
if (Context.User.IsInRole ("Manager") )
{
ddl1.Enabled = false;
}
}
}
 
H

Houston Lucifer

Thanks i will try this.

Phillip Williams said:
Hi Houston,

You can use the RowCreated event like this:

protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowState == DataControlRowState.Edit)
{
DropDownList ddl1 = (DropDownList)e.Row.FindControl("dropdownlist1");
//use the reference to the dropdownlist to enable or disable it
based on the roles
if (Context.User.IsInRole ("Manager") )
{
ddl1.Enabled = false;
}
}
}
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
 
H

Houston Lucifer

Thanks. This did it. I appreciate it.

Phillip Williams said:
Hi Houston,

You can use the RowCreated event like this:

protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowState == DataControlRowState.Edit)
{
DropDownList ddl1 = (DropDownList)e.Row.FindControl("dropdownlist1");
//use the reference to the dropdownlist to enable or disable it
based on the roles
if (Context.User.IsInRole ("Manager") )
{
ddl1.Enabled = false;
}
}
}
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top