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

DataKeyValues always null

1 Answer 71 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Simon
Top achievements
Rank 1
Simon asked on 18 Sep 2014, 05:09 PM
Dear All Telerik Gurus.  I have about 2 years experience of using the radgrid control usually without too much problem.  Everytime I click a button to update the row the DataKeyValue is always null.  I have either gone mad or I am making a school boy error here.  Please see my font end code and serverside code.  Any help would be appreciated.

<telerik:RadGrid ID="radIssues" runat="server" AllowFilteringByColumn="false" AllowSorting="True" nItemCommand="radIssues_ItemCommand" CellSpacing="0" CssClass="grid-float" DataSourceID="ldsIssueLog" ShowStatusBar="True" Skin="Sitefinity" Width="70%">
<MasterTableView AutoGenerateColumns="false" DataSourceID="ldsIssueLog" GroupLoadMode="Client" DataKeyNames="issueID" ClientDataKeyNames="issueID">
 <Columns>
    <telerik:GridBoundColumn DataField="issueID" HeaderText="" UniqueName="issueID" Visible="true">                            </telerik:GridBoundColumn>
                                                                
<telerik:GridBoundColumn DataField="issueTitle" HeaderText="Title" ReadOnly="True" SortExpression="issueTitle" UniqueName="issueTitle"></telerik:GridBoundColumn>
 
<telerik:GridBoundColumn DataField="issueText" HeaderText="Issue" ReadOnly="True" SortExpression="issueText" UniqueName="issueText"></telerik:GridBoundColumn>
 
<telerik:GridBoundColumn DataField="issueDateCreated" HeaderText="Created Date" ReadOnly="True" SortExpression="issueText" UniqueName="issueDateCreated"></telerik:GridBoundColumn>
 
<telerik:GridBoundColumn DataField="createdBy" HeaderText="Created By" ReadOnly="True" SortExpression="issueText" UniqueName="createdBy"></telerik:GridBoundColumn>
 
<telerik:GridBoundColumn DataField="issueDateAmended" HeaderText="Amended Date" ReadOnly="True" SortExpression="issueText" UniqueName="issueDateAmended"></telerik:GridBoundColumn>
                                                                
 <telerik:GridBoundColumn DataField="amendedBy" HeaderText="Amended By" ReadOnly="True" SortExpression="issueText" UniqueName="amendedBy"></telerik:GridBoundColumn>
 
<telerik:GridTemplateColumn AllowFiltering="false" HeaderText="Comment" UniqueName="issueComment">
                                                                    <ItemTemplate>
                                                                        <telerik:RadTextBox ID="txtNote" runat="server" InputType="Text" Rows="2" Text='<%# Eval("issueComment")%>' TextMode="MultiLine">
                                                                        </telerik:RadTextBox>
                                                                    </ItemTemplate>
                                                                </telerik:GridTemplateColumn>
                                                                <telerik:GridTemplateColumn HeaderText="Complete" ItemStyle-Width="100px" UniqueName="chkComplete">
                                                                    <ItemTemplate>
                                                                        <input type="checkbox" id="chkComplete" onclick="checkChangedEvent();" runat="server"
                                                                            checked='<%# Eval("completed")%>' />
                                                                    </ItemTemplate>
                                                                </telerik:GridTemplateColumn>
                                                                <telerik:GridTemplateColumn>
                                                                    <ItemTemplate>
                                                                        <a class="popup-link" href='dlgAddNewIssue.aspx?issueID=<%# Eval("issueID")%>&instructionID=<%=Int32.Parse(Request.QueryString["instructionID"])%>&panelID=<%= Request.QueryString["panelID"]%>&sale=<%= Request.QueryString["sale"]%>' title="Edit Issue">[Edit] </a>
                                                                    </ItemTemplate>
                                                                </telerik:GridTemplateColumn>
                                                                <telerik:GridTemplateColumn>
                                                                    <ItemTemplate>
                                                                        <a class="popup-link" href='dlgRemoveIssue.aspx?issueID=<%# Eval("issueID")%>&instructionID=<%=Int32.Parse(Request.QueryString["instructionID"])%>&panelID=<%= Request.QueryString["panelID"]%>&sale=<%= Request.QueryString["sale"]%>' title="Remove Issue">[Remove] </a>
                                                                    </ItemTemplate>
                                                                </telerik:GridTemplateColumn>
                                                                <telerik:GridButtonColumn ButtonType="PushButton" Text="Completion Note" CommandName="transfer">
                                                                </telerik:GridButtonColumn>
                                                            </Columns>
                                                        </MasterTableView>
                                                    </telerik:RadGrid>
This is the grid above
01.if (e.Item.ItemType == GridItemType.AlternatingItem || e.Item.ItemType == GridItemType.Item)
02.               {
03.                   GridDataItem item = e.Item as GridDataItem;
04.                   // using DataKey
05.                   string id = item.GetDataKeyValue("IssueID").ToString();
06.                    
07.                   //int issueID;
08. 
09.                   //var issuesIdCheck = item.GetDataKeyValue("issueID").ToString();
10. 
11.                   //if (int.TryParse(item["IssueID"].Text, out issueID))
12.                   //if (int.TryParse(id, out issueID))
13.                   //{
14.                       using (var db = new dataDataContext())
15.                       {
16.                           issue objIssue = db.issues.FirstOrDefault(f => f.issueID == int.Parse(id));
17.                           if (objIssue != null)
18.                           {
19.                               PostCompletionIssue objCompletionNote = new PostCompletionIssue()
20.                               {
21.                                   FK_InstructionID = int.Parse(Request.QueryString["instructionID"]),
22.                                   postCompletionIssueCreatedDate = DateTime.Now,
23.                                   postCompletionText = objIssue.issueText,
24.                                   postCompletionTitle = objIssue.issueTitle
25.                               };
26. 
27.                               db.PostCompletionIssues.InsertOnSubmit(objCompletionNote);
28.                               db.SubmitChanges();
29. 
30.                               RadAjaxPanel5.ResponseScripts.Add(String.Format("$find('{0}').ajaxRequest();",
31.                                   RadAjaxPanel7.ClientID));
32.                               RadAjaxPanel5.Alert("Added to completion notes.");
33. 
34.                           }
35.                       }
36.                   }
This is how I am referencing the datakeyvalue but keeps returning null.
Many thanks

Simon

1 Answer, 1 is accepted

Sort by
0
Radoslav
Telerik team
answered on 22 Sep 2014, 12:50 PM
Hi Simon,

From the posted code snippet I saw that the first letter from the DataKyeNames is with lower case - "issueID", however when you try getting the value by using GetDataKeyValue you use “IssueID” with first capital letter. Could you please try getting the value by using GetDataKeyValue function with the key  “issueID” (first letter in lower case) and let me know if the issue still exists.
string id = item.GetDataKeyValue("issueID").ToString();

I hope this helps.

Regards,
Radoslav
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
Simon
Top achievements
Rank 1
Answers by
Radoslav
Telerik team
Share this question
or