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

Format a HttpWebResponse

1 Answer 45 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Casper
Top achievements
Rank 1
Casper asked on 10 Oct 2012, 01:48 PM
I have a RadGrid with some columns inside of it. The data that is bound is to a custom class that has a HttpWebResponse property to it.

I want this property to be formatted in a specific way where I can use both the StatusCode and StatusDescription.

I am able to use one by setting "DataField" to "Response.StatusCode", but how do I format it for my liking's?

Here is the GridBoundColumn i'm using:
<telerik:GridBoundColumn DataField="Response.StatusCode" />

And here is what im aiming for (Pseudo code):
<telerik:GridBoundColumn DataField="Response" Format="{0}.StatusDescription ({0}.StatusCode}
/>

Where the output would for example be:
Page Not Found (404)

1 Answer, 1 is accepted

Sort by
0
Tsvetina
Telerik team
answered on 15 Oct 2012, 10:20 AM
Hi Casper,

You should better do the formatting in ItemDataBound event. There, you can access the cell text and modify it based on values from the DataItem, e.g.:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
        TableCell cell = (e.Item as GridDataItem)["Response"];
        MyCustomClass dataItem = e.Item as MyCustomClass;
        cell.Text = dataItem.StatusDescription + "(" + dataItem.StatusCode + ")";
    }
}


All the best,
Tsvetina
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Casper
Top achievements
Rank 1
Answers by
Tsvetina
Telerik team
Share this question
or