Irwsoft Web Control

Populate Data

Populate data is something that developer do to retrieve data from posted back. This thing can be hard working if you have many fields with many controls. Handle data type from these controls and persist them to object requires data type coverting or boxing/un-boxing from one type to another type, these are time consuming and hard to do. With IWC all those things is handled internally and what you need is just an object and a DataPopulate method to retrieve all data that specified in DataPropertyNames property of all DataControl object.

There are two ways how this thing will work :

  1. You can set an object where you will persist the data to DataObject or PageDataPropertyName property, then call DataPopulate method.
  2. Or you can retrieve these values from Values property directly by specifiying a data-property-name, after calling DataPopulate method.

Example : Input Gender data of Person table with DropDownList


C# code for Person table

// 1) Sample code for Person table
public class Person
{
     // 2) The columns of Person table.
     public int ID { get; set;}
     public string FirstName { get; set;}
     public string LastName { get; set;}
     public GenderType Gender { get; set;}  // 3) Input Gender property of Person.
     public DateTime DateOfBirth { get; set;}
     public int Age { get; set;}
     public string Address { get; set;}
     public string City { get; set;}
     public string Country { get; set;}
     public string IdentityCardNo { get; set;}
     public string BioData { get; set;}
     public string PictureUrl { get; set;}
}

// 4) GenderType enum values
public enum GenderType
{
     Male, Female
}

ASPX code for DropDownList

// 1) Defines the DropDownList control in DataPerson.aspx page
<irw:DropDownList ID="DDL1" runat="server" SkinStyle="SimpleGrey">
     <DataPropertyNames>  // 2) Defines a propertyto bind inside DataPropertyNames tag with DataType is List and Type is SamplesNET2.Data.GenderType.
          <irw:DataPropertyName Name="Gender" DataType="List" Type="SamplesNET2.Data.GenderType" />
     </DataPropertyNames>
     <Items>  // 3) Defines the values of SamplesNET2.Data.GenderType
          <irw:ListItem Text="Male" Value="Male" />
          <irw:ListItem Text="Female" Value="Female" />
     </Items>
</irw:DropDownList>

C# code for DataPopulate with DataObject

// 1) Defines codes to retrieve data in DataPerson.aspx.cs
protected void Submit_Click(object sender, EventArgs e)
{
     Person p = new Person();
     this.DDL1.DataObject = p;
     this.DDL1.DataPopulate();

     // 2) Let's display the data in a Label (LB1) control.
     this.LB1.Text = "Gender : " + p.Gender.ToString();
}

C# code for DataPopulate and retrieve from Values

// 1) Defines codes to retrieve data in DataPerson.aspx.cs
protected void Submit_Click(object sender, EventArgs e)
{
     Person p = new Person();
     // 2) Populate the data using DataPopulate method, then retrieve from Values.
     this.DDL1.DataPopulate();

     // 3) Let's display the data in a Label (LB1) control.
     this.LB1.Text = "Gender : " + this.DDL1.Values["Gender"];
}

Related Topics :

Irwsoft Data Ultimate Edition 4.0 supports data-schema extension (entity framework, linq to sql, simple class, and etc).