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

Filtering on label text in GridTemplateColumn

5 Answers 193 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Scott Smith
Top achievements
Rank 1
Scott Smith asked on 22 May 2012, 06:18 PM
Is it possible to setup a filter to look at the text of a label inside a GridTemplateColumn? I'm building a column and the data is compiled into a comma delimited string, set to a label. 

<telerik:GridTemplateColumn HeaderText="Properties" AllowFiltering="true"   >
    <ItemTemplate>
        <asp:label ID="lblProperties" runat="server" />
    </ItemTemplate>
</telerik:GridTemplateColumn>

lblProperties.Text is set on the ItemDataBound event. I'd like to be able to filter on lblProperties.Text but can't figure out how to do it properly. Any help would be much appreciated. 

Also, is it possible to set the filter of column X to look at the contents of hidden column Y in the grid?

5 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 23 May 2012, 05:46 AM
Hi Scott Smith,

I am not sure about your requirement, If you want the Template column filtering please specify the DataField in the TemplateColumn which should be same for the Label as well. Take a look into the this help documentation.

Thanks,
Shinu.
0
Scott Smith
Top achievements
Rank 1
answered on 23 May 2012, 03:42 PM
Well, there's no one DataField name I can set because the label text is set with a string that is built on the ItemDataBound event, not a value directly from the DataSource. Here is the code that builds the string that appears in my GridTemplateColumn:

Dim properties As String = String.Join(", ", userProperties.Select(Function(id) id.Name).ToArray())
Dim lblProperties As Label = CType(e.Item.FindControl("lblProperties"), Label)
lblProperties.Text = properties

Then I would like the filter to use the text from the label as the DataField to filter on.
0
Scott Smith
Top achievements
Rank 1
answered on 23 May 2012, 06:54 PM
All I need to be able to do is build a string on the ItemDataBound, set that string to the text of the item in column "Properties", and then filter it. If anyone has ideas on how to implement that, I'd love to hear them. This is driving me nuts and I feel like I'm missing something pretty basic.
0
Ricardo Pinto
Top achievements
Rank 1
answered on 14 Oct 2012, 03:57 PM
Hi Scott!

Did you ever solve that problem?

I have the same scenario... several GridTemplateColumn with label built in code behind, that shows additional data.
But filtering doesn't work as there is no datafield that can be set...

Thanks!
Regards,

Ricardo.
0
Radoslav
Telerik team
answered on 18 Oct 2012, 07:11 AM
Hi Ricardo,

Unfortunately the RadGrid does not support the desired functionality. The filtering woks only over the data source to which the RadGrid is bound. So to achieve the desired functionality I suggest you to add additional field into the gird data source which contain the joined string. For example you could add an additional column into the database table to which the RadGrid is bound and create a Trigger which populates this additional column. So when new record is inserted into the database, the trigger could populate this additional column with concatenated strings from the other columns. Please give it try and let me know if it helps you.

Regards,
Radoslav
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
Scott Smith
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Scott Smith
Top achievements
Rank 1
Ricardo Pinto
Top achievements
Rank 1
Radoslav
Telerik team
Share this question
or