My Profile

Thursday, February 10, 2011

ASP.Net Folders - 2


Let’s understand the concept Data Binding with an example.

Example: In this example we’ll see about APP_Code, Data Binding and System.Collections.

Before going into the example let’s know about one important collection which is now going to use in this example i.e., “ArrayList”.

ArrayList: It is one class in System.Collections namespace which is used to store elements of different types.

Now we’ll do the example step wise…

Step 1: In “Solution Explorer” right click on our Project and select “Add Asp.Net Folder ” à App_Code.

Step 2: Right click on App_Code and select “Add New Item” à select “Class” à name it as “utility”.
          Result: “utility.cs” will be added to our project under App_Code folder.

Step 3: In this class write a method GetCountries() that returns ArrayList as follows:
          using System.Collections;
          public class Utility
          {
                   public static ArrayList GetCountries()
                   {
                             ArrayList obj = new ArrayList();
                             obj.Add(“United States”);
                             obj.Add(“India”);
                             obj.Add(“Australia”);
                             obj.Add(“United Kingdom”);
                             return obj;
                   }
          }

Step 4: Create a Web Form with LinkButton saying “Display Contries” and also create some List Cotrols to present data from data object.
          In LinkButton write code to get countries from Utility class and map it to List Controls. Mapping is done with a property “Data Source” and to present data, a method called “DataBind()”.

è Design the form as follows:



Note: I displayed the control names in the picture itself with paint not using Visual Studio :p lolz.

Coding:
Under LinkButton Click Event:
BulletedList1.DataSource = Utility.GetCountries();
BulletedList1.DataBind();

CheckBoxList1.DataSource = Utility.GetCountries();
CheckBoxList1.DataBind();

DropDownList1.DataSource = Utility.GetCountries();
DropDownList1.DataBind();

RadioButtonList1.DataSource = Utility.GetCountries();
RadioButtonList1.DataBind();

ListBox1.DataSource = Utility.GetCountries();
ListBox1.DataBind();

Output you‘ll gets as follows:


Ok... Friends... I Hope you understood how we provide data to the list controls using data binding concept.
Try yourself with the example I’m giving you

“Take a Link button or any PostBack” control and a two List Controls one for contries and another for states. Get the countries into the countries list control as we did above and when ever user select one of the countries the states List box should show all the corresponding states to that country. Try yourself this example in Data binding method not in normal method”

**If u want the solution for this Contact me ….


---------------------------------------------------------- 
** If you like this post please like our page in 
facebook " Dot Net Support" .

2 comments:

yeah thanQ...and there is a lot content wid me on microsoft technologiesss....present im lil busy wid my schedule...i ll keep updating my blog after sm days....keep chekng my blog



If you are stuck with your online management assignment then in this case you can opt for our Management

Assignment help
. we provide the best assignment assignment help online .
We also provide Leadership%20Assignment%20Help. for students across the globe.
for more information contact us +16692714848

Post a Comment

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites More