DataKeyValues

2 posts, 0 answers
  1. Christian Pardun
    Christian Pardun avatar
    112 posts
    Member since:
    May 2010

    Posted 04 Jul 2012 Link to this post

    Dear Support,

    can you explain me, why the DataKeyValues property at the MasterTableView / OwnerTableView is a GridDataKeyArray and not a Dictonary<string, object>? Because if I deserialize the KeyValues property from GridDataItem it's only a Dictonary<string, object>.

    So the GridDataKeyArray could have more than one DataKeyValues.Pair. Under which cases I got more than one DataKeyValues.Pair?

    Thanks alot.

    Kind regards,
    Christian
  2. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 04 Jul 2012 Link to this post

    Hello,

    protected void dgPassanger_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
            {
                
                Dictionary<string, int> dct = new Dictionary<string, int>();
                dct.Add("1", 10);
                dct.Add("2", 20);
                dgPassanger.DataSource = dct;
            }
     
     
    protected void dgPassanger_ItemDataBound(object sender, GridItemEventArgs e)
            {
                
                if (e.Item is GridDataItem)
                {
                    GridDataItem item = e.Item as GridDataItem;
                    // By using Key
                    string strKey =  item.GetDataKeyValue("Key").ToString();
                    int strValue =Convert.ToInt32(item.GetDataKeyValue("Value").ToString());
                     
                    // By Using DataItem
                    string strKey1 = ((System.Collections.Generic.KeyValuePair<string, int>)(item.DataItem)).Key;
                    int strValue1 = ((System.Collections.Generic.KeyValuePair<string, int>)(item.DataItem)).Value;
                }
            }
    <MasterTableView  DataKeyNames="Key,Value">


    Thanks,
    Jayesh Goyani
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top