How to set compositekey manually

5 replies. Last post: April 12, 2010 12:35 AM by Andi Santoso
Tags :
  • (None)
  • New Discussion
  • New Question
  • New Product Feedback
Dennis CheeMember

Hi There,

Is there anyway to set composite key to RootTable DataKeyField programatically?

I've tried to mark the property as primarykey.

e.g.

object

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;
        }
    }
}

dataobject

    [DataObject]
    public class GenericObjectFactory<T> where T : class, IEntity
    {
        public GenericObjectFactory()
        {
        }

        [DataObjectMethodAttribute(DataObjectMethodType.Select, true)]
        public IList<Person> Select(int startRowIndex, int maximumRows, string sortExpression)
        {
            IList<Person> list = new List<Person>();
            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;
        }
    }

WebGrid DataSourceId

<ISWebGrid:WebGrid ID="EntityWebGrid" runat="server" DataSourceID="EntityWebGridObjectDataSource">
<ISWebGrid:WebGrid ID="EntityWebGrid" runat="server" DataSourceID="EntityWebGridObjectDataSource" OnPrepareDataBinding="EntityWebGrid_PrepareDataBinding"></ISWebGrid:WebGrid>  
<rbs:GenericObjectDataSource ID="EntityWebGridObjectDataSource" runat="server"></rbs:GenericObjectDataSource>
</ISWebGrid:WebGrid> <rbs:GenericObjectDataSource ID="EntityWebGridObjectDataSource" runat="server"></rbs:GenericObjectDataSource>

And call WebGrid.RetrieveStructure() within OnPrepareDatabinding event.

I've tried above but still get DataKeyField as null.

 

Any idea ?

 

All times are GMT -5. The time now is 1:09 AM.
Previous Next