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

DataKeyValues

1 Answer 57 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Christian
Top achievements
Rank 1
Christian asked on 04 Jul 2012, 02:51 PM
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

1 Answer, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 04 Jul 2012, 03:58 PM
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
Tags
Grid
Asked by
Christian
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Share this question
or