PrivateSub Page_Load(sender AsObject, e As System.EventArgs)
’ Put user code to initialize the page here’ Create and populate a multi-dimensional arrayDim MyArray(4) AsInteger()
Dim i AsIntegerFor i = 0To3
MyArray(i) = NewInteger(5) {}
Dim x AsIntegerFor x = 0To4
MyArray(i)(x) = x + 5 * i
NextNext
DataList1.DataSource = MyArray
DataList1.DataBind()
EndSub’Page_Load
C#
privatevoidPage_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here// Create and populate a multi-dimensional arrayint [][] MyArray = newint[4][];
for (int i=0; i<4; i++)
{
MyArray[i] = newint[5];
for (int x=0; x<5; x++)
{
MyArray[i][x] = x+(5*i);
}
}
DataList1.DataSource = MyArray;
DataList1.DataBind();
}
PrivateSub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Load
’Put user code to initialize the page hereIf Request('txtPath') <> '' ThenDim strDir AsString = Request('txtPath')
lblHeader.Text = 'File Listing for ' & strDir & ''Dim dirInfo AsNew DirectoryInfo(strDir)
’ Get the files for the directory strDirDim fInfos As FileInfo() = dirInfo.GetFiles('*.*')
DataList1.DataSource = fInfos
DataList1.DataBind()
EndIfEndSubProtectedSub SelectedIndexChanged(ByVal sender AsObject, ByVal e As System.EventArgs) Handles DataList1.SelectedIndexChanged
Dim strFilePath AsString = DataList1.DataKeys(DataList1.SelectedItem.ItemIndex).ToString()
Dim fInfo As FileInfo = New FileInfo(strFilePath)
Dim objStream As StreamReader = fInfo.OpenText()
Dim strContents AsString = objStream.ReadToEnd()
objStream.Close()
lblFileContents.Text = 'Contents of ' & fInfo.Name & ':' & _'<xmp>' & vbCrLf & strContents & vbCrLf & '</xmp>'EndSub
C#
privatevoidPage_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page hereif (Request['txtPath']!= null)
{
string strDir = Request['txtPath'];
lblHeader.Text = 'File Listing for ' + strDir + '';
DirectoryInfo dirInfo =new DirectoryInfo(strDir);
// Get the files for the directory strDir
FileInfo[] fInfos = dirInfo.GetFiles('*.*');
DataList1.DataSource = fInfos;
DataList1.DataBind();
}
}
protectedvoidSelectedIndexChanged(Object sender , System.EventArgs e )
{
string strFilePath = DataList1.DataKeys[(int)DataList1.SelectedItem.ItemIndex].ToString();
FileInfo fInfo = new FileInfo(strFilePath);
StreamReader objStream = fInfo.OpenText();
string strContents = objStream.ReadToEnd();
objStream.Close();
lblFileContents.Text = 'Contents of ' + fInfo.Name + ':' + '<xmp>' + '
' + strContents + '
' + '</xmp>';
}
PrivateSub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Load
’Put user code to initialize the page here
DataList1.DataSource = System.Environment.GetEnvironmentVariables()
DataList1.DataBind()
EndSub
privatevoidPage_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
DataList1.DataSource = System.Environment.GetEnvironmentVariables();
DataList1.DataBind();
}
Sub Page_Load(ByVal sender AsObject, ByVal e As EventArgs) HandlesMyBase.Load
IfNot Page.IsPostBack Then
BindTitle()
EndIfEndSub’Bind Data to DataList Populating the DatasetSub BindTitle()
Dim ds AsNew DataSet
Dim sqlStmt AsString = 'SELECT * FROM Employees order by title'Dim conString AsString = 'server=localhost;database=Northwind;uid=sa;pwd=;'Dim myda As SqlDataAdapter = New SqlDataAdapter(sqlStmt, conString)
myda.Fill(ds, 'Table')
DataList1.DataSource = ds
DataList1.DataBind()
EndSub’The ItemDataBound EventProtectedSub ItemDB(ByVal sender AsObject, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs)
If e.Item.ItemType = ListItemType.AlternatingItem Or e.Item.ItemType = ListItemType.Item ThenDim strval AsString = CType(e.Item.FindControl('lblTitle'), Label).TextDim title AsString = ViewState('title')If title = strval Then
CType(e.Item.FindControl('lblTitle'), Label).Text = ''
e.Item.Visible = FalseElse
title = strval
ViewState('title') = title
CType(e.Item.FindControl('lblTitle'), Label).Text = title
e.Item.Visible = TrueEndIfEndIfEndSub
C#
voidPage_Load(object sender, EventArgs e)
{
if (!(Page.IsPostBack))
{
BindTitle();
}
}
voidBindTitle()
{
DataSet ds = new DataSet();
string sqlStmt = 'SELECT * FROM Employees order by title';
string conString = 'server=localhost;database=Northwind;uid=sa;pwd=;';
SqlDataAdapter myda = new SqlDataAdapter(sqlStmt, conString);
myda.Fill(ds, 'Table');
DataList1.DataSource = ds;
DataList1.DataBind();
}
protectedvoidItemDB(object sender, System.Web.UI.WebControls.DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.AlternatingItem | e.Item.ItemType == ListItemType.Item)
{
string strval = ((Label)(e.Item.FindControl('lblTitle'))).Text;
string title = ViewState('title');
if (title == strval)
{
((Label)(e.Item.FindControl('lblTitle'))).Text = '';
e.Item.Visible = false;
}
else
{
title = strval;
ViewState('title') = title;
((Label)(e.Item.FindControl('lblTitle'))).Text = title;
e.Item.Visible = true;
}
}
}
Dim intStart AsIntegerDim intpageSize AsIntegerDim cn As SqlConnection
Dim da As SqlDataAdapter
Dim ds As DataSet
PrivateSub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Load
’Put user code to initialize the page here IfNot Page.IsPostBack Then
ViewState('Start') = 0
bindList()
EndIfEndSubSub bindList()
cn = New SqlConnection('server=localhost;uid=sa;pwd=;database=northwind')
da = New SqlDataAdapter('Select * from Products ', cn)
ds = New DataSet
intStart = ViewState('Start')
ViewState('pageSize') = 14
da.Fill(ds, intStart, ViewState('pageSize'), 'Table')
DataList1.DataSource = ds
DataList1.DataBind()
EndSubPrivateSub lnkPrevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lnkPrevious.Click
intStart = ViewState('Start')- ViewState('pageSize')
ViewState('Start') = intStartIf intStart <= 0Then
ViewState('Start') = 0EndIf
bindList()
EndSubPrivateSub lnkNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lnkNext.Click
Dim dlistcount AsInteger = DataList1.Items.Count
intStart = ViewState('Start') + ViewState('pageSize')
ViewState('Start') = intStartIf dlistcount < ViewState('pageSize') Then
ViewState('Start') = ViewState('Start') - ViewState('pageSize')EndIf
bindList()
EndSubPrivateSub lnkFirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
If intStart <= 0Then
ViewState('Start') = 0EndIf
bindList()
EndSub
C#
int intStart ;
SqlConnection cn ;
SqlDataAdapter da ;
DataSet ds ;
privatevoidPage_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page hereif(!Page.IsPostBack )
{
ViewState['Start'] = 0;
bindList();
}
}
voidbindList()
{
cn = new SqlConnection('server=localhost;uid=sa;pwd=;database=northwind');
da = new SqlDataAdapter('Select * from Products ', cn);
ds = new DataSet();
intStart = (int)ViewState['Start'];
ViewState['pageSize'] = 14;
da.Fill(ds, intStart,(int) ViewState['pageSize'], 'Table');
DataList1.DataSource = ds;
DataList1.DataBind();
}
privatevoidlnkPrevious_Click(object sender, System.EventArgs e)
{
intStart = (int) ViewState['Start'] -(int) ViewState['pageSize'];
ViewState['Start'] = intStart;
if (intStart <= 0 )
{
ViewState['Start'] = 0;
}
bindList();
}
privatevoidlnkNext_Click(object sender, System.EventArgs e)
{
int dlistcount = DataList1.Items.Count;
intStart = (int) ViewState['Start']+(int) ViewState['pageSize'];
ViewState['Start'] = intStart;
if ( dlistcount < (int)ViewState['pageSize'] )
{
ViewState['Start'] = (int)ViewState['Start'] - (int)ViewState['pageSize'];
}
bindList();
}
’Populate the DataList in the Page_Load EventProtectedSub ItemDB(ByVal sender AsObject, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs)
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem ThenIf CType(e.Item.FindControl('chkDiscontinued'), CheckBox).Checked Then
e.Item.BackColor = Color.CadetBlue
EndIfEndIfEndSub
C#
//Bind the DataList in the Page_Load EventprotectedvoidItemDB(object sender , System.Web.UI.WebControls.DataListItemEventArgs e )
{
if(( e.Item.ItemType == ListItemType.Item)||( e.Item.ItemType == ListItemType.AlternatingItem) )
{
if( ((CheckBox)(e.Item.FindControl('chkDiscontinued'))).Checked )
{
e.Item.BackColor = Color.CadetBlue;
}
}
}
PrivateSub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Load
’Put user code to initialize the page here’Populate the DataList with DataSetEndSubProtectedSub ItemDB(ByVal sender AsObject, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles DataList1.ItemDataBound
Dim drv As DataRowView = CType(e.Item.DataItem, DataRowView)
Dim BDate As DateTime
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then’To check if the BirthDate has null valuesIfNot drv.Row('BirthDate').ToString = DBNull.Value.ToString Then’Assign the BirthDate to variable BDate
BDate = DateTime.Parse(drv.Row('BirthDate').ToString)EndIf’If the Employee BirthDay is Today ’Change the row Text Color to blueIf BDate.ToString('dd/MM') = DateTime.Now.ToString('dd/MM') Then
e.Item.ForeColor = Color.Blue
e.Item.Font.Bold = TrueEndIfEndIfEndSub
C#
privatevoidPage_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
DataList1.DataSource =BindDataClass.BindData ();
DataList1.DataBind ();
}
protectedvoidItemDB(Object sender , System.Web.UI.WebControls.DataListItemEventArgs e )
{
DataRowView drv = (DataRowView)e.Item.DataItem;
DateTime BDate=Convert.ToDateTime (null) ;
if ((e.Item.ItemType == ListItemType.Item )||( e.Item.ItemType == ListItemType.AlternatingItem))
{ //To check if the BirthDate has null valuesif( drv.Row['BirthDate'].ToString() != DBNull.Value.ToString())
{
//Assign the BirthDate to variable BDate
BDate = DateTime.Parse(drv.Row['BirthDate'].ToString());
}
//If the Employee BirthDay is Today //Change the row Text Color to blueif (BDate.ToString('dd/MM') == DateTime.Now.ToString('dd/MM'))
{
e.Item.ForeColor = Color.Blue;
e.Item.Font.Bold = true;
}
}
}
Dim arrlist AsNew ArrayList
Dim enumColor AsNew KnownColor
Dim Colors As Array = [Enum].GetValues(enumColor.GetType())
Dim clr AsObjectForEach clr In Colors
IfNot Color.FromKnownColor(CType(clr, KnownColor)).IsSystemColor Then
arrlist.Add(clr.ToString())
EndIfNext
DataList1.DataSource = arrlist
DataList1.DataBind()
C#
ArrayList arrlist = new ArrayList ();
KnownColor enumColor = new KnownColor();
Array Colors = Enum.GetValues(enumColor.GetType());
foreach(object clr in Colors)
{
if (!Color.FromKnownColor((KnownColor)clr).IsSystemColor)
arrlist.Add ( clr.ToString());
}
DataList1.DataSource = arrlist;
DataList1.DataBind();
Share with