﻿<?xml version="1.0" encoding="utf-8"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:media="http://search.yahoo.com/mrss/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><title>Intersoft Community - WebGrid Enterprise - How to set compositekey manually</title><link>http://www.intersoftsolutions.com/Community/WebGrid/How-to-set-compositekey-manually/</link><description /><generator>http://www.intersoftsolutions.com</generator><language>en</language><copyright>Copyright 2002 - 2015 Intersoft Solutions Corp. All rights reserved.</copyright><ttl>60</ttl><item><title>How to set compositekey manually</title><link>http://www.intersoftsolutions.com/Community/WebGrid/How-to-set-compositekey-manually/</link><pubDate>Mon, 12 Apr 2010 00:35:07 GMT</pubDate><dc:creator>andi@intersoftpt.com</dc:creator><description>&lt;p&gt;&lt;span style="font-size: 9pt; "&gt;Hi Dennis,&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-size: 9pt; "&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;Yes, it will not be a problem. Attached is a running simple sample of getting composite keys. Please ensure to put the SimpleList.cs in your App_Code folder.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: 9pt; "&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; I hope it helps. Thank you and have a nice day.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: 9pt; "&gt;Best Regards,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: 9pt; "&gt;Andi Santoso&lt;/span&gt;&lt;/p&gt;</description></item><item><title>How to set compositekey manually</title><link>http://www.intersoftsolutions.com/Community/WebGrid/How-to-set-compositekey-manually/</link><pubDate>Sun, 11 Apr 2010 20:44:09 GMT</pubDate><dc:creator>d4dennis</dc:creator><description>&lt;p&gt;Hi Andi, &lt;/p&gt;
&lt;p&gt;I do exactly as you said, it still not working. Is it possible for you to supply a simple working sample?&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Dennis&lt;/p&gt;</description></item><item><title>How to set compositekey manually</title><link>http://www.intersoftsolutions.com/Community/WebGrid/How-to-set-compositekey-manually/</link><pubDate>Thu, 08 Apr 2010 22:50:58 GMT</pubDate><dc:creator>andi@intersoftpt.com</dc:creator><description>&lt;p&gt;&lt;span style="font-size: 9pt; "&gt;Hi Dennis Chee,&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-size: 9pt; "&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; If that is the scenario, please ensure that you do not declare the DataKeyField in your server side PrepareDataBinding event. Once you set two Primary Keys on your class, WebGrid will automatically set its composite key values. Those key values will be set as an array, here are the snippet to get those key&amp;nbsp;values:&lt;/span&gt;&lt;/p&gt;
&lt;p /&gt;&lt;pre&gt;&lt;span style="font-size: 9pt; "&gt;var grid = ISGetObject("WebGrid1");
var selectedObject = grid.GetSelectedObject();
   if (selectedObject != null) {
      var toRowObject = selectedObject.ToRowObject();
      alert("Key Values are " &amp;#43; toRowObject.KeyValues[0] &amp;#43; " and " &amp;#43; toRowObject.KeyValues[1]);
   }&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;&lt;span style="font-size: 9pt; "&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; I hope it helps. Thank you and have a nice day.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: 9pt; "&gt;Best Regards,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: 9pt; "&gt;Andi Santoso&lt;/span&gt;&lt;/p&gt;
&lt;p /&gt;</description></item><item><title>How to set compositekey manually</title><link>http://www.intersoftsolutions.com/Community/WebGrid/How-to-set-compositekey-manually/</link><pubDate>Thu, 08 Apr 2010 20:18:48 GMT</pubDate><dc:creator>d4dennis</dc:creator><description>&lt;p&gt;Hi Andi, &lt;/p&gt;
&lt;p&gt;I've tried to mark 2 PrimaryKeys on my class, when i tried to retrieve keyvalues on selectedrow via javascript, it still return null.&lt;/p&gt;&lt;pre&gt;                var webGrid = ISGetObject(controlId);
                var selectedObject = webGrid.GetSelectedObject();
                if (selectedObject != null) {
                    var selectedRow = selectedObject.ToRowObject();
                    alert(selectedRow.KeyValue);
                    alert(selectedRow.KeyValues);&lt;/pre&gt;
&lt;p&gt;any ideas ?&lt;/p&gt;</description></item><item><title>How to set compositekey manually</title><link>http://www.intersoftsolutions.com/Community/WebGrid/How-to-set-compositekey-manually/</link><pubDate>Thu, 08 Apr 2010 04:09:04 GMT</pubDate><dc:creator>andi@intersoftpt.com</dc:creator><description>&lt;p /&gt;&lt;p style="margin-top: 7.5pt; margin-right: 0in; margin-bottom: 7.5pt; margin-left: 0in; "&gt;&lt;span style="font-family: 'lucida sans unicode', sans-serif; color: black; font-size: 9pt; "&gt;&lt;span style="font-size: 9pt; "&gt;Hi Dennis,&lt;o:p /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 7.5pt; margin-right: 0in; margin-bottom: 7.5pt; margin-left: 0in; "&gt;&lt;span style="font-family: 'lucida sans unicode', sans-serif; color: black; font-size: 9pt; "&gt;&lt;span style="font-size: 9pt; "&gt;      Even though you set that particular column as
a [PrimaryKey()], you will need to make sure that on server side of
PrepareDataBinding, you have set the DataKeyField for the WebGrid.&lt;o:p /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p /&gt;
&lt;p /&gt;&lt;pre&gt;&lt;span style="font-size: 9pt; "&gt;protected void WebGrid1_PrepareDataBinding(object sender, ISNet.WebUI.WebGrid.DataSourceEventArgs e)
    {    
        if (!IsPostBack)
        {        
            WebGrid1.RetrieveStructure();
            
        }
        WebGrid1.RootTable.DataKeyField = "CustomerID";
    }&lt;/span&gt;&lt;/pre&gt;
&lt;p /&gt;
&lt;p /&gt;
&lt;p&gt;&lt;span style="font-size: 9pt; "&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'lucida sans unicode', sans-serif; font-size: 9pt; "&gt;&lt;span style="font-size: 9pt; "&gt;Then, if you try to debug it, you will see that the DataKeyField
is null. That is our default behavior. However, if you look deeper you will see
that each row already set its KeyValue.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 7.5pt; margin-right: 0in; margin-bottom: 7.5pt; margin-left: 0in; "&gt;&lt;span style="font-family: 'lucida sans unicode', sans-serif; color: black; font-size: 9pt; "&gt;&lt;span style="font-size: 9pt; "&gt;      Different case if you are trying to
create a composite key. You will need to set two Primary Keys in your class.
For this case, in PrepareDataBinding, you will not need to set any
DataKeyField. Just leave it blank and it will automatically set the composite
key. The composite key is returned as an array.&lt;o:p /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 7.5pt; margin-right: 0in; margin-bottom: 7.5pt; margin-left: 0in; "&gt;&lt;span style="font-family: 'lucida sans unicode', sans-serif; color: black; font-size: 9pt; "&gt;&lt;span style="font-size: 9pt; "&gt;      I hope it helps. Thank you and have a
nice day.&lt;o:p /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 7.5pt; margin-right: 0in; margin-bottom: 7.5pt; margin-left: 0in; "&gt;&lt;span style="font-family: 'lucida sans unicode', sans-serif; color: black; font-size: 9pt; "&gt;&lt;span style="font-size: 9pt; "&gt;Best Regards,&lt;o:p /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 7.5pt; margin-right: 0in; margin-bottom: 7.5pt; margin-left: 0in; "&gt;&lt;span style="font-family: 'lucida sans unicode', sans-serif; color: black; font-size: 9pt; "&gt;&lt;span style="font-size: 9pt; "&gt;Andi Santoso&lt;/span&gt;&lt;o:p /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p /&gt;</description></item><item><title>How to set compositekey manually</title><link>http://www.intersoftsolutions.com/Community/WebGrid/How-to-set-compositekey-manually/</link><pubDate>Wed, 07 Apr 2010 03:07:06 GMT</pubDate><dc:creator>d4dennis</dc:creator><description>&lt;p&gt;Hi There,&lt;/p&gt;
&lt;p&gt;Is there anyway to set composite key to RootTable DataKeyField programatically? &lt;/p&gt;
&lt;p&gt;I've tried to mark the property as primarykey. &lt;/p&gt;
&lt;p&gt;e.g.&lt;/p&gt;
&lt;p&gt;object&lt;/p&gt;&lt;pre&gt;public class Person
{
	public Person(string _Id, string _Name, string _Sex)
	{
        this._Id = _Id;
        this._Name = _Name;
        this._Sex = _Sex;
	}

    private string _Id = string.Empty;
    private string _Name = string.Empty;
    private string _Sex = string.Empty;

    [PrimaryKey()] 
    public string Id
    {
        set
        {
            this._Id = value;
        }
        get
        {
            return this._Id; 
        }
    }
    
    public string Name
    {
        set
        {
            this._Name = value;
        }
        get
        {
            return this._Name;
        }
    }
    
    public string Sex
    {
        set
        {
            this._Sex = value;
        }
        get
        {
            return this._Sex;
        }
    }
}
&lt;/pre&gt;
&lt;p&gt;dataobject&lt;/p&gt;&lt;pre&gt;    [DataObject]
    public class GenericObjectFactory&amp;lt;T&amp;gt; where T : class, IEntity
    {
        public GenericObjectFactory()
        {
        }

        [DataObjectMethodAttribute(DataObjectMethodType.Select, true)]
        public IList&amp;lt;Person&amp;gt; Select(int startRowIndex, int maximumRows, string sortExpression)
        {
            IList&amp;lt;Person&amp;gt; list = new List&amp;lt;Person&amp;gt;();
            list.Add(new Person("1", "Name 1", "Male 1"));
            list.Add(new Person("1", "Name 1", "Male 1"));
            list.Add(new Person("1", "Name 1", "Male 1"));
            return list;
        }
    }&lt;/pre&gt;
&lt;p&gt;WebGrid DataSourceId&lt;/p&gt;&lt;pre&gt;&amp;lt;ISWebGrid:WebGrid ID="EntityWebGrid" runat="server" DataSourceID="EntityWebGridObjectDataSource"&amp;gt;&lt;pre&gt;&amp;lt;ISWebGrid:WebGrid ID="EntityWebGrid" runat="server" DataSourceID="EntityWebGridObjectDataSource" OnPrepareDataBinding="EntityWebGrid_PrepareDataBinding"&amp;gt;&amp;lt;/ISWebGrid:WebGrid&amp;gt;  
&amp;lt;rbs:GenericObjectDataSource ID="EntityWebGridObjectDataSource" runat="server"&amp;gt;&amp;lt;/rbs:GenericObjectDataSource&amp;gt;&lt;/pre&gt;
&amp;lt;/ISWebGrid:WebGrid&amp;gt;  
&amp;lt;rbs:GenericObjectDataSource ID="EntityWebGridObjectDataSource" runat="server"&amp;gt;&amp;lt;/rbs:GenericObjectDataSource&amp;gt;&lt;/pre&gt;
&lt;p&gt;And call WebGrid.RetrieveStructure() within OnPrepareDatabinding event.&lt;/p&gt;
&lt;p&gt;I've tried above but still get DataKeyField as null.&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;Any idea ?&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;</description></item></channel></rss>