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

Concatenating 2 columns into one (radgrid)

2 Answers 358 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Greg
Top achievements
Rank 1
Greg asked on 06 Aug 2013, 08:04 PM
Hi there,

This is kind of hard to explain. I have 4 columns in a radgrid:

A | B | C | D

A user will use this grid to insert information for each of the four columns. When they click Add, the form inserts their inputted values into each of the four columns.

I need to be able to concatenate the A and B columns into one column. So for instance, the grid will now look like:

A | B | C | D
-------------
1 | 2 | 3 | 4
5 | 6 | 7 | 8
9 | A | B | C



I can hide Column A and column B and make column A-B read-only. The reason for this is when they click add, they will be inserting column A and B values separately...so column A and column B must exist but be hidden. So now there will now be 5 columns, Column A, B, C, D, and A-B.

The tricky part is that these columns have to be searchable... so for instance if these were fields in the columns:

A-B | C | D
-----------
1-2 | 3 | 4
5-6 | 7 | 8
9-A | B | C


If the user puts "1" in the search box for the A-B column, the number 1-2 will show up. If they put "6" in the search box, the number 5-6 will show up.

How on earth can I get this to work? I'm lost :confused: How do I tell the grid that I want to show and search a concatenated field? Is this even possible?

I have been looking into getters and setters but I don't know how they work. 

2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 1
answered on 07 Aug 2013, 09:43 AM
Hi Greg,

One way to do this will be by using GridCalculatedColumn,if both the column are of DataType of String.I was able to get it search using filter condition of Contains if that is the search that you are mentioning.Then to hide the columns you can set Display=false.Check the below code snippet.

ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" DataSourceID="SqlDataSource1"
    AllowPaging="true" AutoGenerateEditColumn="true" AllowFilteringByColumn="true">
    <GroupingSettings CaseSensitive="false" />
    <MasterTableView CommandItemDisplay="Top">
        <Columns>
            <telerik:GridBoundColumn UniqueName="OrderID" DataField="OrderID" HeaderText="OrderID" />
            <telerik:GridBoundColumn DataField="ShipCity" HeaderText="ShipCity" UniqueName="ShipCity" Display="false"  />       
            <telerik:GridBoundColumn DataField="CustomerID" HeaderText="CustomerID" UniqueName="CustomerID"  Display="false" />
            <telerik:GridCalculatedColumn HeaderText="Test" UniqueName="Test" DataFields="ShipCity, CustomerID"
                Expression='{0} + " - " + {1}'>
            </telerik:GridCalculatedColumn>
         </Columns>
    </MasterTableView>
</telerik:RadGrid>

Thanks,
Princy
0
Greg
Top achievements
Rank 1
answered on 07 Aug 2013, 02:41 PM
........ok, that worked.

I'm kind of mad that it worked, haha! This was literally the first thing I tried (I found it here: http://stackoverflow.com/questions/4016487/how-to-merge-columns-using-telerik-radgrid-control) and I could not for the life of me get it to work, something about grid bindings, but I think I just had my variables mistyped.....oh my.......


THANK YOU! It works well and looks great.
Tags
Grid
Asked by
Greg
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Greg
Top achievements
Rank 1
Share this question
or