Enabling/Disabling a DataGrid ButtonColumn

Discussion in 'ASP .Net Datagrid Control' started by CGuy, Oct 21, 2003.

  1. CGuy

    CGuy Guest

    Hi,

    I have a datagrid that has one ButtonColumn which is bound to a database
    field.

    My requirement is that when the page containing the datagrid is loaded,
    I would like the ButtonColumn to be enabled/disabled based on the value of a
    boolean variable that is calculated at runtime - if the value if false, I
    don't want the ButtonColumn to display links for the displayed items.

    Please help me in doing this.

    CGuy
     
    CGuy, Oct 21, 2003
    #1
    1. Advertising

  2. CGuy

    Rajesh.V Guest

    How about this?

    MyDatagrid.Columns[0].Visible = false;

    "CGuy" <> wrote in message
    news:...

    > Hi,
    >
    > I have a datagrid that has one ButtonColumn which is bound to a

    database
    > field.
    >
    > My requirement is that when the page containing the datagrid is

    loaded,
    > I would like the ButtonColumn to be enabled/disabled based on the value of

    a
    > boolean variable that is calculated at runtime - if the value if false, I
    > don't want the ButtonColumn to display links for the displayed items.
    >
    > Please help me in doing this.
    >
    > CGuy
    >
    >
     
    Rajesh.V, Oct 22, 2003
    #2
    1. Advertising

  3. CGuy

    CGuy Guest

    Nope... that would make the whole column vanish!!!

    My requirement is that based on a variable's value, the column should behave
    like a ButtonColumn or a Bound Colummn.

    I was able to find a solution myself. This is how I'm doing it.

    private void DataGrid_ItemDataBound(object sender, DataGridItemEventArgs e)
    {
    if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
    ListItemType.AlternatingItem)
    {
    if(!ControlStatus)
    {
    //If ControlStatus is False, remove the LinkButton and Add a
    Label
    e.Item.Cells[1].Controls.RemoveAt(0);
    Label labelItem = new Label();
    labelItem.Text = "Text";
    e.Item.Cells[1].Controls.Add(labelItem);
    }
    }
    }


    "Rajesh.V" <> wrote in message
    news:...
    > How about this?
    >
    > MyDatagrid.Columns[0].Visible = false;
    >
    > "CGuy" <> wrote in message
    > news:...
    >
    > > Hi,
    > >
    > > I have a datagrid that has one ButtonColumn which is bound to a

    > database
    > > field.
    > >
    > > My requirement is that when the page containing the datagrid is

    > loaded,
    > > I would like the ButtonColumn to be enabled/disabled based on the value

    of
    > a
    > > boolean variable that is calculated at runtime - if the value if false,

    I
    > > don't want the ButtonColumn to display links for the displayed items.
    > >
    > > Please help me in doing this.
    > >
    > > CGuy
    > >
    > >

    >
    >
     
    CGuy, Oct 22, 2003
    #3
    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. CGuy
    Replies:
    2
    Views:
    2,038
  2. VSK
    Replies:
    0
    Views:
    362
  3. VSK
    Replies:
    3
    Views:
    485
    John Saunders
    Oct 23, 2003
  4. Jason Nadrowski
    Replies:
    0
    Views:
    392
    Jason Nadrowski
    Oct 23, 2003
  5. Assimalyst
    Replies:
    3
    Views:
    1,932
    Assimalyst
    Aug 9, 2005
Loading...

Share This Page