Retrieving DataKeyNames (Name itself) and Value of Edited Row .. in Server PageLoad POstback

2 posts, 0 answers
  1. Neal
    Neal avatar
    114 posts
    Member since:
    Apr 2008

    Posted 07 Aug 2008 Link to this post


    We need to retriev the DataKeyNames (Name itself) i.e the DataItem(Dsources Col Name, ..and  the Value of it  as/per Edited Row .. in Server Code,...but
     at the PageLoad event (IspOstback = true) as opposed to in the Event Handlers provided for  Insert Delete Edit Update,..
    Reason being, we override the Page Load ,  referencing our   Userlog  obj in it, so all pages inheriting from the overridden Page Load, have it by default, 

    1)  We now want to trap the Row Id (stored in DataKeyNames ), but since not all grids in the system use a std named "Id" as the DataKeyName,   ..!!
    2) retrieve the value of the datakeyname of the "edited/deleted" row,..also in the Page load

    Is this possible ? and if so how.

  2. John
    John avatar
    416 posts
    Member since:
    Oct 2006

    Posted 12 Aug 2008 Link to this post

    hi Neal :)

    When the DataKeyNames property is set, the RadGrid control automatically populates its DataKeys collection with the values from the specified field or fields, which provides a convenient way to access the primary keys of each item.

    The following code example demonstrates how to achieve your goal:

                            <telerik:GridBoundColumn UniqueName="CompanyName" HeaderText="CompanyName" DataField="CompanyName"

    using System; 
    using System.Data; 
    using System.Configuration; 
    using System.Web; 
    using System.Web.Security; 
    using System.Web.UI; 
    using System.Web.UI.WebControls; 
    using System.Web.UI.WebControls.WebParts; 
    using System.Web.UI.HtmlControls; 
    public partial class _Default : System.Web.UI.Page  
        protected void Page_Load(object sender, EventArgs e) 
            if (IsPostBack) 
                foreach (Telerik.Web.UI.DataKey dataKey in RadGrid1.MasterTableView.DataKeyValues) 
                    foreach (String str in RadGrid1.MasterTableView.DataKeyNames) 
                        Response.Write(dataKey[str].ToString() + "</br>");    

    <John:Peel />
  3. DevCraft R3 2016 release webinar banner
Back to Top