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

[Solved] The DataKeys collection is empty. Please specify a data key.

2 Answers 232 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
neal
Top achievements
Rank 1
neal asked on 05 Apr 2012, 08:30 AM
Hi
I want to make a row selectable on a telerik grid but when i add the .Selectable() command I get the error in that is in the title

here is my code can anyone help please

    @(Html.Telerik().Grid(Model)
.Name("Firms")
        .Columns(columns =>
            {
                columns.Bound(c => c.logo).Visible(false);
                columns.Bound(c => c.address1).Visible(false);
                columns.Bound(c => c.address2).Visible(false);
                columns.Bound(c => c.address3).Visible(false);
                columns.Bound(c => c.address4).Visible(false);
                columns.Bound(c => c.postcode);
                columns.Bound(c => c.country);
                columns.Bound(c => c.telno);
                columns.Bound(c => c.faxno);
                columns.Bound(c => c.email);
                columns.Bound(c => c.websiteurl);
                columns.Bound(c => c.firmsize);
                columns.Bound(c => c.sector);
            })
.Pageable(paging =>
            paging.PageSize(20)
                  .Style(GridPagerStyles.NextPreviousAndNumeric)
                  .Position(GridPagerPosition.Bottom))
                  .Sortable()
                  .Filterable()
                  .Scrollable(c => c.Height("600px"))
                    .Selectable(p => p.Enabled(true))
                    
    .RowTemplate(@<text>
    <table>
        <tr>
            <td width="60px" class="gc4">
                <img src="../../Images/@item.logo" alt="" height="100px" width="60px"/>
            </td>
            <td class="gc1">
                <table>
                    <tr>
                        <td height="10px" style="font-weight: bold">
                            Address:
                        </td>
                        <td>@item.address1
                        </td>
                    </tr>
                    <tr>
                        <td height="10px" style="font-weight: bold">
                        </td>
                        <td>@item.address4
                        </td>
                    </tr>
                    <tr>
                        <td height="10px" style="font-weight: bold">
                            PostCode:
                        </td>
                        <td>@item.postcode
                        </td>
                    </tr>
                    <tr>
                        <td height="10px" style="font-weight: bold">
                            Country:
                        </td>
                        <td>@item.country
                        </td>
                    </tr>
                </table>
            </td>
            <td class="gc2">
                <table>
                    <tr>
                        <td height="10px" style="font-weight: bold">
                            Firm Size:
                        </td>
                        <td>@item.firmsize
                        </td>
                    </tr>
                    <tr>
                        <td height="10px" style="font-weight: bold">
                        </td>
                        <td>
                        </td>
                    </tr>
                    <tr>
                        <td height="10px" style="font-weight: bold">
                            Sector:
                        </td>
                        <td>@item.sector
                        </td>
                    </tr>
                    <tr>
                        <td height="10px" style="font-weight: bold">
                        </td>
                        <td>
                        </td>
                    </tr>
                </table>
            </td>
            <td class="gc3">
                <table>
                    <tr>
                        <td height="10px" style="font-weight: bold">
                            email:
                        </td>
                        <td>@item.email
                        </td>
                    </tr>
                    <tr>
                        <td height="10px" style="font-weight: bold">
                            Fax No:
                        </td>
                        <td>@item.faxno
                        </td>
                    </tr>
                    <tr>
                        <td height="10px" style="font-weight: bold">
                            Tel No:
                        </td>
                        <td>@item.telno
                        </td>
                    </tr>
                    <tr>
                        <td height="10px" style="font-weight: bold">
                            Website:
                        </td>
                        <td>
                            @item.websiteurl
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
    </text>)

thanks in advance

2 Answers, 1 is accepted

Sort by
0
Accepted
Dadv
Top achievements
Rank 1
answered on 05 Apr 2012, 02:03 PM
@(Html.Telerik().Grid(Model)
.Name("Firms") 
.DataKeys(d => { d.Add(a => a.YourPrimaryKeyId).RouteKey("YourPrimaryKeyId");  })

For selection, you need a "identity key" or something like that (guid, string ..) to define an unique value of the row that is select.
 in your sample you didn't seem to have any Identity key, but you need to tell telerik grid one (why not 'telno' ?)

                
0
neal
Top achievements
Rank 1
answered on 08 Apr 2012, 01:13 PM
perfect answer mate thanks
Tags
Grid
Asked by
neal
Top achievements
Rank 1
Answers by
Dadv
Top achievements
Rank 1
neal
Top achievements
Rank 1
Share this question
or