Is there a way to know column index of GridDataItem in GridItemDataBound Event?

3 posts, 0 answers
  1. Robin
    Robin avatar
    41 posts
    Member since:
    Sep 2012

    Posted 10 Apr 2014 Link to this post

    Hello, 

    I would like to access grid column header from grid item databound event. Purpose is to validate data and display error message together with column header text. Please see following sample code. Is there a way to know column header or column index from GridDataItem?

     protected void gridSample_ItemDataBound(object sender, GridItemEventArgs e)
            {
                if (e.Item is GridDataItem)
                {
                    GridDataItem _item = e.Item as GridDataItem;
                    if (_item["unique_name"].Text == "something") //condition
                    {
                        string l_columnHeader = gridSample.Columns[_item - column - index].HeaderText; //<-- Required column header text

                        DisplayErrorMsg("Error at column:" + l_columnHeader);
                    }
                }
            }


    Thanks in advanced,
    Robin




  2. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 14 Apr 2014 Link to this post

    Hello Robin,

    I think that the Accessing Cells Using Column Unique Name section in the following article will help you achieve your goal:
    http://www.telerik.com/help/aspnet-ajax/grid-accessing-cells-and-rows.html

    Regards,
    Pavlina
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 14 Apr 2014 Link to this post

    Hi Robin,

    I think that the Accessing Cells Using Column Unique Name section in the following article will help you achieve your goal:
    http://www.telerik.com/help/aspnet-ajax/grid-accessing-cells-and-rows.html

    Regards,
    Pavlina
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top