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

[Solved] getDataKeyValue is returning null value

3 Answers 652 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Afzal Farooqui
Top achievements
Rank 1
Afzal Farooqui asked on 12 Oct 2009, 10:52 PM
I am getting a null value back when tried the following code:

                 <RadCodeBlock runat="server" ID="radCodeBlock">
       <script type="text/javascript">
                         function RadGridCommand(sender, args) {
  
               if (args.get_commandName() == "Update") {
  
                   alert(sender.get_masterTableView().get_dataItems()[0].getDataKeyValue("datamember"));
                  
               }
          }
                
                
                 </script>
                 </gsm:RadCodeBlock>
                
                 <gsm:RadGrid runat="server"
                        AutoGenerateColumns="false" ID="RadGrid1" 
                        AllowFilteringByColumn="false" AllowSorting="true"
                        AllowPaging="true"
                        AlternatingItemStyle-BackColor = "White"
                        PageSize="10"
                        ShowStatusBar="true"
                        CellPadding="0" CellSpacing="0" Visible="false">
                   <PagerStyle Mode="NextPrevAndNumeric"  />
                   <GroupingSettings CaseSensitive="false" />
                   <MasterTableView AutoGenerateColumns="false"
                                    AllowFilteringByColumn="false"
                                    EditMode="InPlace"
                                    TableLayout="Auto"
                                    DataKeyNames="ID" CommandItemDisplay="Top"  >
                        <Columns >
                            <gsm:GridBoundColumn   ItemStyle-HorizontalAlign="Center" FilterControlWidth="100%" DataField="datamember" HeaderText="datamember" SortExpression="MemberPair" UniqueName="datamember" AutoPostBackOnFilter="true" CurrentFilterFunction="Contains" ShowFilterIcon="false">
                                <ItemStyle Width="20%"   Font-Names="tahoma,helvetica" Font-Size="10px" HorizontalAlign="Justify"/>
                                <HeaderStyle Width="20%" Font-Names="tahoma,helvetica" Font-Size="10px" HorizontalAlign="Justify" />
                            </gsm:GridBoundColumn>
                        </Columns>
                   </MasterTableView>
                    <ClientSettings>
                        <Scrolling AllowScroll="true"  UseStaticHeaders="true"/>                       
                        <ClientEvents OnRowDblClick="RowDblClick" />  
                        <ClientEvents OnCommand="RadGridCommand" />                     
                    </ClientSettings>                                                         
                 </gsm:RadGrid>

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 13 Oct 2009, 04:05 AM
Hi Afzal,

Set the ClientDataKeyNames as datamember in order to retrieve the value.

-Shinu.
0
Afzal Farooqui
Top achievements
Rank 1
answered on 13 Oct 2009, 02:51 PM
Thanks Shinu, that worked!
One related issue is that this getDataKeyValue in OnCommand event gives me the old value of text box (in edit mode) not the one I just entered. Should I use some other event which gives me the new, just entered, value?
0
Princy
Top achievements
Rank 2
answered on 15 Oct 2009, 12:55 PM
Hello Afzal,

The DataKeyNames or ClientDataKeyNames are used to specify primarykey fields(uniquevalues) in the database, which needs to be retrieved during operations like update. So the datakeyvalues would retrieve only the old values and not the changed values. If you want to access the textbox editor values on the client while updating, you can refer to the following code library which demonstrtaes a similar scenario:
Retrieving grid editor value client side

Hope this helps..
Princy.
Tags
Grid
Asked by
Afzal Farooqui
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Afzal Farooqui
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or