Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
210
Show and Hide Columns in webdatagrid
posted

Hi i am new to webdatagrid. I am binding the webdatagrid with the dataset containing the fields of a table. I want to hide some columns of that table in the webdatagrid.

How it is possible?

And how can i change the header text of the columns?

Thanks

Akhtar Abbas

Parents
No Data
Reply
  • 8421
    Suggested Answer
    posted

    Hello Akhtar,

    Are you using AutoGenerateColumns set to a value of true? If so, please note that the Columns collection off of the WebDataGrid only contains those columns which you have manually added to the grid through either the markup or code. If you allow the grid to automatically generate those columns then the collection will always be empty. If you want to manipulate columns on the server the recommended approach is that you add the columns to the grid manually based off of the requirements for your data.

    That said, if for some reason you cannot take this approach you can still make changes through the use of the server side InitializeRow event. The InitializeRow accepts event arguments of type RowEventArgs, which exposes a property called Row which is the row that is being initialized. In the event what you do is first check to see if the row's Index is 0 as you really only need to do column manipulation on the first row to have it apply to all rows in the grid. Then, you can access the row's Items and make any changes you need to make:

    if (e.Row.Index == 0) {

        e.Row.Items.FindItemByKey("ID").Column.Hidden = true;

        e.Row.Items.FindItemByKey("BirthDate").Column.Header.Text = "Birth Date";

    }

Children
No Data