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

Datakeyvalue in ListView

4 Answers 110 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ingo Oltmann
Top achievements
Rank 1
Ingo Oltmann asked on 17 Mar 2009, 09:10 PM
Hi,

I am using the Datagrid as Listview as in this example:
http://demos.telerik.com/aspnet-ajax/grid/examples/programming/listview/defaultcs.aspx
I added a DataKeyField and created an ItemCommand eventhandler which fires fine using EnablePostbackOnRowClick. The problem is that I get the same DataKeyValue codebehind for each source record I click on. Can you show me a way out of this problem?

Regards,
Ingo

4 Answers, 1 is accepted

Sort by
0
Accepted
Tsvetoslav
Telerik team
answered on 20 Mar 2009, 03:10 PM
Hi Ingo Oltmann,

Please, refer to my reply in the support ticket you opened on the same topic.

Best regards,
Tsvetoslav
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0
Ingo Oltmann
Top achievements
Rank 1
answered on 20 Mar 2009, 03:38 PM
Hi Tsvetoslav,

thank you for your help. Your solution works perfectly.

Regards,
Ingo
0
Adam
Top achievements
Rank 2
answered on 15 Apr 2009, 11:34 AM
Can you post the solution to this on the forum for everyone else?  I'm interested in a workaround for this too.
0
Tsvetoslav
Telerik team
answered on 16 Apr 2009, 06:00 AM
Hi Adam,

Please, find below the post from the support thread:

-----------------------------------------------------TICKET 198314-------------------------------------------------------------------

The behavior you are observing is expected, since when using ItemTemplate only one dataitem is rendered on the client. Still there is a way to get the data key value for the item clicked. Here are the steps for this:

1. Attach a client event handler to the asp:Panel control for the ItemTemplate of the grid and pass to it the current item's index:

                    <asp:Panel ID="ItemContainer" ... onclick='<%#"sendID(" +((GridDataItem)Container).ItemIndex + ")" %>'>  
                    ...  
                    </asp:Panel> 

2. Add an AjaxManager control to your page and attach an event handler to its AjaxRequest server event.

3. Go back to your aspx and add the client event handler for the panel click:

    <telerik:RadCodeBlock ID="Codeblock" runat="server">  
    <script type="text/javascript">  
      
 
          
        function sendID(index)  
        {  
         
           var manager = $find('<%=RadAjaxManager1.ClientID %>');  
             
           manager.ajaxRequest(index);  
        }  
      
      
    </script>  
    </telerik:RadCodeBlock> 

4. Add the following code to the server-side event handler for the AjaxRequest event of the RadAjaxManager control:

        protected void RadAjaxManager1_AjaxRequest(object sender, Telerik.Web.UI.AjaxRequestEventArgs e)  
        {  
            string Id = RadGrid1.MasterTableView.DataKeyValues[4]["MediaID"].ToString();  
        } 

--------------------------------------------------END OF POST------------------------------------------------------------------------

All the best,
Tsvetoslav
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
Ingo Oltmann
Top achievements
Rank 1
Answers by
Tsvetoslav
Telerik team
Ingo Oltmann
Top achievements
Rank 1
Adam
Top achievements
Rank 2
Share this question
or