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

How to get column text and column unique name based on the column index given (On both client-side and server-side)?

8 Answers 846 Views
Grid
This is a migrated thread and some comments may be shown as answers.
LamKhoa
Top achievements
Rank 1
LamKhoa asked on 18 Oct 2011, 04:07 PM
If I know the column index, how do I get its header text and its unique name?
Please provide me the sample code to do that on both client-side (Javascript) and server-side (C# or VB).

Thanks

Lamk.

8 Answers, 1 is accepted

Sort by
0
Elliott
Top achievements
Rank 2
answered on 18 Oct 2011, 04:47 PM
you didn't say at what point or on what event you need this information
to get the unique name, the MasterTableView Columns collection, which is indexed, can give you the UniqueName on the server
- you'll need to know (or figure out) what kind of Column it is (GridBoundColumn, etc)
there is a get_columns() function for the MasterTableView object on the client which may get you what you want
as for the Text, once you have the UniqueName you can drill down into the Controls in the TableCell
0
LamKhoa
Top achievements
Rank 1
answered on 19 Oct 2011, 12:56 AM
Would you please give me an example?

Thanks

John
0
Elliott
Top achievements
Rank 2
answered on 19 Oct 2011, 02:26 PM
Dim aCol as GridBoundColumn=(GridBountColumn)RadGrid1.MasterTableView.Columns(2)
Dim strUnq = aCol.UniqueName
0
LamKhoa
Top achievements
Rank 1
answered on 19 Oct 2011, 02:42 PM
Thanks.
Would you please also give me the sample code for client-side as well?

Thanks

Lamk.
0
Accepted
Elliott
Top achievements
Rank 2
answered on 19 Oct 2011, 02:51 PM
var grid = sender;
var MasterTable = grid.get_masterTableView();       
var id = MasterTable.get_columns()[0].get_uniqueName();
not sure what event sender is coming from - but there are other ways to get the grid as an object
0
LamKhoa
Top achievements
Rank 1
answered on 19 Oct 2011, 03:37 PM
Thanks,

It works great.

Lamk
0
Chris
Top achievements
Rank 1
answered on 05 Dec 2011, 10:04 PM
Is it possible to change this so that it's not locked to column 0, but instead the column that was clicked?

I figured it out:  I can use the index to get the column name and pass it back to the server instead of the column index.

<script type="text/javascript">
       function rowClick(sender, args) {
           var grid = sender;
           var MasterTable = grid.get_masterTableView();
           var cellindex = args.get_domEvent().target.cellIndex
           var id = MasterTable.get_columns()[cellindex].get_uniqueName();
           sender.get_masterTableView().fireCommand("CellClick", id + "|" + args.get_domEvent().target.innerHTML);
       }
    </script>
0
Elliott
Top achievements
Rank 2
answered on 07 Dec 2011, 03:50 PM
"If I know the column index"
substitute the column index instead of 0
Tags
Grid
Asked by
LamKhoa
Top achievements
Rank 1
Answers by
Elliott
Top achievements
Rank 2
LamKhoa
Top achievements
Rank 1
Chris
Top achievements
Rank 1
Share this question
or