Professional Web Applications Themes

Enabling/Disabling a DataGrid ButtonColumn - ASP.NET Data Grid Control

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

  1. #1

    Default Enabling/Disabling a DataGrid ButtonColumn

    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 Guest

  2. #2

    Default Re: Enabling/Disabling a DataGrid ButtonColumn

    How about this?

    MyDatagrid.Columns[0].Visible = false;

    "CGuy" <cguycsharp.net> wrote in message
    news:OJRoZzAmDHA.2232TK2MSFTNGP09.phx.gbl...
    > 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 Guest

  3. #3

    Default Re: Enabling/Disabling a DataGrid ButtonColumn

    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" <Rajesh_vanchihotmail.com> wrote in message
    news:OHGgEUGmDHA.988TK2MSFTNGP10.phx.gbl...
    > How about this?
    >
    > MyDatagrid.Columns[0].Visible = false;
    >
    > "CGuy" <cguycsharp.net> wrote in message
    > news:OJRoZzAmDHA.2232TK2MSFTNGP09.phx.gbl...
    >
    > > 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 Guest

Similar Threads

  1. Disable ButtonColumn inside DataGrid through logic
    By sheidt in forum ASP.NET Data Grid Control
    Replies: 1
    Last Post: June 23rd, 06:02 PM
  2. Datagrid with ButtonColumn as Last Column
    By Bhaumik in forum ASP.NET Data Grid Control
    Replies: 1
    Last Post: June 14th, 08:47 PM
  3. Dynamic ButtonColumn in datagrid?
    By Richard in forum ASP.NET Data Grid Control
    Replies: 0
    Last Post: April 13th, 09:36 PM
  4. multiple buttonColumn in one datagrid
    By Alvin Bruney [MVP] in forum ASP.NET Data Grid Control
    Replies: 0
    Last Post: April 4th, 12:35 AM
  5. How to use ButtonColumn to select a Datagrid row?
    By Northern in forum ASP.NET General
    Replies: 0
    Last Post: July 22nd, 08:34 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139