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

Constants, Code Blocks, and Grid Configuration

1 Answer 38 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Shane Milton
Top achievements
Rank 2
Shane Milton asked on 29 Jan 2010, 05:03 PM
Howdy,

Something that has bothered me for a long time about how I've worked with grids (Telerik and non-Telerik alike) is when I have to specify things like DataKeyNames. I HATE how I essentially have them specified, MULTIPLE TIMES (both in the aspx and in the .cs when accessing them), with a hand-typed string. Obviously in the code behind I can put this string into a constant and access it that way. A better idea would be to use that same constant in the aspx file as well. Unfortunately, I can't seem to get that to work.

My ideal implementation would be readonly static KeyValuePair<string, string> objects where the key is the UniqueName and the value is the DataField. However, the DataKeyNames property will not take these as best as I can tell. Also, once I get THAT working, I'd also want to use this same technique when configuring my columns. I'm trying it as such:

DataKeyNames='<%=GridColumnID.Key%>, <%=GridColumnQty.Key%>, <%=GridColumnMax.Key%>' 

What is a way for me to do this such that these "magic strings" are only defined once in my constants section rather than being copied/pasted multiple times?

Mucho thanks!!
-Shane

1 Answer, 1 is accepted

Sort by
0
Iana Tsolova
Telerik team
answered on 04 Feb 2010, 07:53 AM
Hi Shane,

Find attached a sample project illustrating how you can set the MasterTableView DataKeyNames using server-side properties.

Check it out and let me know if it helps.

Kind regards,
Iana
the Telerik team

Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
Tags
Grid
Asked by
Shane Milton
Top achievements
Rank 2
Answers by
Iana Tsolova
Telerik team
Share this question
or