This is a migrated thread and some comments may be shown as answers.

How to call a method in DataFormatString of a gridboundcolumn?

4 Answers 54 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Deepak Vasudevan
Top achievements
Rank 2
Deepak Vasudevan asked on 17 Nov 2011, 11:10 PM
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?

4 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 18 Nov 2011, 06:32 AM
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
0
Deepak Vasudevan
Top achievements
Rank 2
answered on 18 Nov 2011, 05:36 PM
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)
0
Jayesh Goyani
Top achievements
Rank 2
answered on 19 Nov 2011, 05:35 AM
Hello Deepak,

Are you able to resolved your issue ?

Thanks,
Jayesh Goyani
0
Deepak Vasudevan
Top achievements
Rank 2
answered on 21 Nov 2011, 08:44 PM
Dear Jayesh,

Yes. Your guidance along with my little proposed workaround did get the objective and the mission accomplished. :)
Tags
Grid
Asked by
Deepak Vasudevan
Top achievements
Rank 2
Answers by
Jayesh Goyani
Top achievements
Rank 2
Deepak Vasudevan
Top achievements
Rank 2
Share this question
or