Trying to set DataKeyNames for the C1GridView in code behind

Originally Posted 16 August 2013, 1:19 pm EST

  • Originally Posted 16 August 2013, 1:19 pm EST

    I'm setting the DataKey names programmatically in my code behind file. This works fine with the standard ASP.NET gridview control. However, when I use the following code with the C1GridView, I have a problem.
    private void BindData<T>(IEnumerable<T> list, string[] dataKeyNames)
    {
    gvLookup.DataKeyNames = dataKeyNames;
    gvLookup.DataSource = list;
    gvLookup.DataBind();
    }


    The problem is that upon selecting a row using the autogenerated select button, the DataKeyNames collection is empty in both the OnSelectedIndexChanging and OnSelectedIndexChanged events. If I define the DataKeyNames directly in my markup, it works fine.
    <wijmo:C1GridView ID="gvLookup" AutoGenerateSelectButton="True" OnRowCreated="gvLookup_OnRowCreated" runat="server" OnSelectedIndexChanging="gvLookup_OnSelectedIndexChanging" 
    DataKeyNames="Id" OnPageIndexChanging="gvLookup_PageIndexChanging" ScrollMode="Vertical" AllowPaging="True" OnSelectedIndexChanged="gvLookup_SelectedIndexChanged">
    </wijmo:C1GridView>


    Am I missing something?
  • Reply

    Hi Svilotti,

    I'm sorry I couldn't reproduce the issue you've mentioned, at my end. I set the DataKeyNames property in Page_Load and was able to get the DataKeyNames collection in the OnSelectedIndexChanging and OnSelectedIndexChanged events of C1GridView. I've attached a sample application for your reference. Please take a look and let me know if you're able to reproduce the issue with my sample as well.
    Also, please check the build that you're using. If it's not the latest one, please download it from http://prerelease.componentone.com and give it a try.

    Regards
    Abdias
    2013/08/C1GridView_Wijmo_DataKeyNames.zip
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels