Control—webcontrol—BaseDataBoundControl>-DataBoundControlàListControl
All listcontrols(DrowDownList,RadioButtionList,BulletedList..ect) are derived from ListControl class.
So ListControl is base/abstract class for all Listcontrols.ListControl provides base funcationality to derived classes.
So every Listcontrol get the common funcationalities
Like:
DataTextField,DataValueField,items…derived from Listcontrol class.
We can bind data to these listcontrols in 2 ways
1. Items collection
2. DataBinding
1. ListControls Items Collection:
Ex :
RadioButtionList1.items.Add(“abcd”)
Or
ListItem li=new Listem();
li.Text=”abcd”;
2 ListControls DataBinding:
RadioButtonList,CheckBoxList,ListBox,DropDownList,ButtedList all have DataSource and DataBind method so we can easily bind data to these controls
So these are also called databinding controls.
Ex:Binding data to ListControls
RadioButtonList1.DataSource=GetCourses()
RadioButtonList1.DataBind();
public ArrayList GetCourses()
{
ArrayList courses = new ArrayList();
courses.Add("csharp");
courses.Add("visualbasic");
courses.Add("asp.net");
courses.Add("sharepoint");
return courses;
}
ListControl has a collection is called items.items return type is ListItemCollection.
Note : ListItemCollection :IList(count property)
public void Add(ListItem item);
public void Add(string item);
Using items Collection propertie we can get all the information of that control infromation like count.
EX:
int i = RadioButtonList1.Items.Count; //ListItemCollection
Response.Write(i.ToString());
ListItemCollection licol = new ListItemCollection();
ListItem li1 = new ListItem();
li1.Text = "proper";
ListItem li2 = new ListItem();
li2.Text = "code";
licol.Add(li1);
licol.Add(li2);
IEnumerator ier = licol.GetEnumerator();
while (ier.MoveNext())
{
ListItem li =(ListItem)ier.Current;
RadioButtonList1.Items.Add(li);
}
int j = RadioButtonList1.Items.Count;
Response.Write(j.ToString());
ListItemCollection
public void Add(ListItem item);
public void Add(string item);
public void AddRange(ListItem[] items);
public int Count { get; }
public void Clear();
public bool Contains(ListItem item);
public void Insert(int index, ListItem item);
public void Insert(int index, string item);
--------ect
ListItemCollection
public void Add(ListItem item);
public void Add(string item);
public void AddRange(ListItem[] items);
public int Count { get; }
public void Clear();
public bool Contains(ListItem item);
public void Insert(int index, ListItem item);
public void Insert(int index, string item);
--------ect
No comments:
Post a Comment