How to call a method in DataFormatString of a gridboundcolumn?

5 posts, 0 answers
  1. Deepak Vasudevan
    Deepak Vasudevan avatar
    82 posts
    Member since:
    May 2010

    Posted 17 Nov 2011 Link to this post

    I am creating a dynamic gridboundcolumn and need something like this

     grdColumn.DataFormatString = InitCaps("{0}")

    However this is not passing the real data to my method but just passes {0} itself. Can some one point where I am going wrong and what is that I am messing around?
  2. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 18 Nov 2011 Link to this post

    Hello,

    void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridDataItem)
            {
                GridDataItem item = e.Item as GridDataItem;
               item["YourColumnUniqueName"].Text  = initCaps(item["YourColumnUniqueName"].Text);
           }
    }


    Thanks,
    Jayesh Goyani
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Deepak Vasudevan
    Deepak Vasudevan avatar
    82 posts
    Member since:
    May 2010

    Posted 18 Nov 2011 Link to this post

    Dear Jayesh,

    Thanks for the snippet. Actually I got a compiler error with your statement If (e.Item Is GridDataItem) Then

    error BC30108: 'GridDataItem' is a type and cannot be used as an expression. The workaround I made to work was:

    If (e.Item.ItemType = GridItemType.Item Or _
                e.Item.ItemType = GridItemType.AlternatingItem) Then
           
    And then I checked the DataRowView using DirectCast

    Dim objDataRowView As DataRowView = DirectCast(objDataItem.DataItem, DataRowView)
  5. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 18 Nov 2011 Link to this post

    Hello Deepak,

    Are you able to resolved your issue ?

    Thanks,
    Jayesh Goyani
  6. Deepak Vasudevan
    Deepak Vasudevan avatar
    82 posts
    Member since:
    May 2010

    Posted 21 Nov 2011 Link to this post

    Dear Jayesh,

    Yes. Your guidance along with my little proposed workaround did get the objective and the mission accomplished. :)
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017