Constants, Code Blocks, and Grid Configuration

2 posts, 0 answers
  1. Shane Milton
    Shane Milton avatar
    219 posts
    Member since:
    Dec 2003

    Posted 29 Jan 2010 Link to this post


    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!!
  2. Iana Tsolova
    Iana Tsolova avatar
    3388 posts

    Posted 04 Feb 2010 Link to this post

    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,
    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.
Back to Top