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

Selective labeling in Grid

5 Answers 52 Views
Grid
This is a migrated thread and some comments may be shown as answers.
earl
Top achievements
Rank 1
earl asked on 02 Dec 2008, 11:45 PM
Hi, I am upgrading an old ASP application to use the Grid control. The old ASP implementation reads in single character status codes from the database and outputs user friend text labels which sometimes include data from other tables into an HTML page. For example, the database might contain status codes 'P' and 'S' which would correspond to 'Pending' and 'Shipping from [location]' on screen. How can I accomplish something similar in RadGrid while preserving filtering and sorting functionality?

5 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 03 Dec 2008, 10:05 AM
Hello,

You can use GridTemplateColumn to achieve this. Here is example:
...
<ItemTemplate>
    <%# GetMyText(Eval("Country").ToString())%>
</ItemTemplate>
...
    protected string GetMyText(string text)
    {
        return text[0].ToString();
    }
...

Other possible approach is to modify desired cell Text in ItemDataBound event for desired grid column:

if(e.Item is GridDataItem)
{
    TableCell cell = ((GridDataItem)e.Item)["YourColumnUniqueName"];
    cell.Text = GetMyText(DataBinder.Eval(e.Item.DataItem, "YourFieldName").ToString());
}

All the best,
Vlad
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
earl
Top achievements
Rank 1
answered on 12 Dec 2008, 09:33 PM
Hi, I have implemented a template column which displays the status labels correctly, but it does not filter on the displayed value and instead filters on the underlying data. Here is my column and the VB function:

              <telerik:GridTemplateColumn DataField="orderstat" UniqueName="OrderStatusLabel" HeaderText="Ord Stat">
                  <ItemTemplate>
                      <%#GetStatusLabel(Eval("orderstat")).ToString()%>
                  </ItemTemplate>
                  <HeaderStyle Width="30px" />
              </telerik:GridTemplateColumn>

    Protected Function getStatusLabel(ByVal sCode As Object)
        Select Case sCode
            Case "R"
                getStatusLabel = "Pending"
            Case "H"
                getStatusLabel = "Signed out"
            Case Else
                getStatusLabel = "Unknown"
        End Select
    End Function

The problem is that if the user types "Pending" or "Signed out" in the filter box then nothing is returned. How can I make it so the template column can be filtered on the displayed values? Thank you.



0
Vlad
Telerik team
answered on 15 Dec 2008, 07:14 AM
Hello earl,

The grid filtering can work only with fields/values from the grid data source.

Regards,
Vlad
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
earl
Top achievements
Rank 1
answered on 18 Dec 2008, 11:21 PM
Vlad,

It looks like this example might be something like what i want:
http://www.telerik.com/help/aspnet-ajax/grdimplementingfilteringfortemplatecolumns.html

What exactly does the code in the lower portion do?

I would imagine this is a common thing to do. There is absolutely no workaround to filter template columns based on the displayed value and not the underlying data?

Thanks,
Earl
0
Nikolay Rusev
Telerik team
answered on 22 Dec 2008, 10:26 AM
Hi earl,

The example which you are pointing demonstrates how you can create custom filtering  if you extend GridColumn.

You can find more examples on the links below:
Filtering with MS DropDownList instead of textbox - this example give you the steps to implement custom filtering in GridBoundColumn.
Google-like Filtering

I hope this helps.

Greetings,
Nikolay
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
earl
Top achievements
Rank 1
Answers by
Vlad
Telerik team
earl
Top achievements
Rank 1
Nikolay Rusev
Telerik team
Share this question
or