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 } } }
Showing posts with label DataTable. Show all posts
Showing posts with label DataTable. Show all posts
Monday, November 15, 2010
Friday, October 15, 2010
Filter Rows from DataTable Using Filter
Written by sureshsharmadotnet
on October 15, 2010
in Asp.net, C#, DataSet, DataTable
with
No comments
public static DataTable FilterRows(DataTable source) { string root = parentID; DataTable result = source.Clone(); string filter = "CategoryID = '" + root + "'"; DataRow[] rows = source.Select(filter); foreach (DataRow row in rows) { result.ImportRow(row); } return result; }