Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
930
Column containing name and (hidden) ID
posted

 I have a webgrid where I would like to add a column where each cell contains a name and an ID, with the name displayed in the cell. I can do this by creating my own class as below, and make each cell element an instance of this class:

private class NameAndID
        {
            private string name;
            private int ID;
            public NameAndID(string name, int ID)
            {
                this.name = name;
                this.ID = ID;
            }
            public override string ToString()
            {
                return this.name;
            }

            public int getID()
            {
                return this.ID;
            }
        }

 This works server-side because I can use the getID method to retrieve the ID of an element, but how do I get the ID at client-side with javascript? The cell.getValue() javascript method only returns the name! And is this the way to go or can I create a custom column that contains a name and an ID in some other way?

 EDIT: I have tried making a hidden column that contains the ID but this doesn't work, because a hidden column is not sorted when the grid is sorted, and therefore the proper IDs are not linked to the proper names after a sort, so I would like to avoid hidden columns!

Parents Reply Children
No Data