Disable Dropdown list in GridView(Edit Mode)

Discussion in 'ASP .Net Web Controls' started by Houston Lucifer, Dec 13, 2005.

  1. 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.
    Houston Lucifer, Dec 13, 2005
    #1
    1. Advertising

  2. 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


    "Houston Lucifer" wrote:

    > 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.
    Phillip Williams, Dec 13, 2005
    #2
    1. Advertising

  3. Thanks i will try this.

    "Phillip Williams" wrote:

    > 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
    >
    >
    > "Houston Lucifer" wrote:
    >
    > > 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.
    Houston Lucifer, Dec 13, 2005
    #3
  4. Thanks. This did it. I appreciate it.

    "Phillip Williams" wrote:

    > 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
    >
    >
    > "Houston Lucifer" wrote:
    >
    > > 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.
    Houston Lucifer, Dec 13, 2005
    #4
  5. You are welcome.
    --
    HTH,
    Phillip Williams
    http://www.societopia.net
    http://www.webswapp.com


    "Houston Lucifer" wrote:

    > Thanks. This did it. I appreciate it.
    >
    > "Phillip Williams" wrote:
    >
    > > 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
    > >
    > >
    > > "Houston Lucifer" wrote:
    > >
    > > > 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.
    Phillip Williams, Dec 14, 2005
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alex
    Replies:
    0
    Views:
    399
  2. =?Utf-8?B?a2Vu?=
    Replies:
    1
    Views:
    10,315
    Wiktor Zychla [C# MVP]
    Jan 23, 2006
  3. GridView Newbie

    Disable GridView Controls in Edit Mode

    GridView Newbie, Sep 8, 2008, in forum: ASP .Net
    Replies:
    0
    Views:
    412
    GridView Newbie
    Sep 8, 2008
  4. Steve Myers
    Replies:
    2
    Views:
    266
    Steve Myers
    Nov 20, 2003
  5. Jaime Stuardo

    GridView control enters edit mode when I click Edit link twice

    Jaime Stuardo, Apr 7, 2006, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    383
    Jaime Stuardo
    Apr 7, 2006
Loading...

Share This Page