Showing posts with label DataTable. Show all posts
Showing posts with label DataTable. Show all posts

Monday, November 15, 2010

get items data at run time using the ItemDataBound, RowDataBound event

protected void Page_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable();
//For Fill Data in DataTable
dt = clsemp.GetData();
//For DataList
DataList1.DataSource = dt;
DataList1.DataBind();
//for GridView
GridView1.DataSource = dt;
GridView1.DataBind();
//for repeater
Repeater1.DataSource = dt;
Repeater1.DataBind();

}
protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
if (e.Item.DataItem != null)
{
int intEmployeeId = Convert.ToInt32(DataBinder.Eval(e.Item.DataItem, "EmployeeId"));
string strFName = Convert.ToString(DataBinder.Eval(e.Item.DataItem, "FirstName"));
string strLName = Convert.ToString(DataBinder.Eval(e.Item.DataItem, "LastName"));

//work do as per require
}
}
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.DataItem != null)
{
int intEmployeeId = Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "EmployeeId"));
string strFName = Convert.ToString(DataBinder.Eval(e.Row.DataItem, "FirstName"));
string strLName = Convert.ToString(DataBinder.Eval(e.Row.DataItem, "LastName"));

//work do as per require
}
}
}
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
if (e.Item.DataItem != null)
{
int intEmployeeId = Convert.ToInt32(DataBinder.Eval(e.Item.DataItem, "EmployeeId"));
string strFName = Convert.ToString(DataBinder.Eval(e.Item.DataItem, "FirstName"));
string strLName = Convert.ToString(DataBinder.Eval(e.Item.DataItem, "LastName"));

//work do as per require
}
}

}

Share:

Friday, October 15, 2010