This example uses a DataList which contains LinkButton controls, which allows a user to navigate through a list of data. The example uses various DataList events to dynamically create the data from each row in the DataList and responds to user interaction within the control.
About Source Code
Create a new ASP.NET project using VS.NET, then drag a DataList control on the web form. Rest of the code is simple. Just follow the source for which events you need to implement.
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
using System.Xml.Xsl;
namespace WebBrowse
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
//this is the DataList Item on the WebForm
protected System.Web.UI.WebControls.DataList WebDataList;
private void Page_Load(object sender, System.EventArgs e)
{
//initialize GUI settings
if (!this.IsPostBack)
{
DMSDataList.DataSource = BuildDataTable(SomeXMLNode);
DMSDataList.DataBind();
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.DMSDataList.ItemCreated += new System.Web.UI.WebControls.DataListItemEventHandler
(this.DMSDataList_ItemCreated);
this.DMSDataList.ItemCommand += new System.Web.UI.WebControls.DataListCommandEventHandler
(this.DMSDataList_ItemCommand);
this.DMSDataList.ItemDataBound += new System.Web.UI.WebControls.DataListItemEventHandler
(this.DMSDataList_ItemDataBound);
this.DMSDataList.SelectedIndexChanged += new System.EventHandler
(this.DMSDataList_SelectedIndexChanged);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private ICollection BuildDataTable(string xmlElement)
{
DataTable dt = new DataTable();
Join the conversation! Your thoughts help the community grow.