In this article i amGgoing to show how to create temporary table and fetch data in list to perform generics process and later on to bind Gridview. with examples.
private void Genericswithtable()
{
DataTable temporarytableDt = new DataTable();
temporarytableDt.Columns.Add("Id");
temporarytableDt.Columns.Add("Name", typeof(String));
temporarytableDt.Columns.Add("Email", typeof(String));
temporarytableDt.Rows.Add(1, "dev", "dev@cxom");
temporarytableDt.Rows.Add(2, "deva", "deva@cxom");
//created temporary table so here i am not using any sql server connection just created
temporary table for example.
List<string> listtable = new List<string>();
Declaration of list type string
for (int i = 0; i < temporarytableDt.Rows.Count;i++)
{
listtable.Insert(i, temporarytableDt.Rows[i]["Name"].ToString() +
" / " + temporarytableDt.Rows[i]["Email"].ToString());
}
//untill there will be rows in table all rows value will be inserted in List
//listtable.RemoveAt(1);
listtable.Insert(2, "Raj");
listtable.Add("Raja");
//Now here we can add more value wchich will appear after table value will be displayed.
gridlist.DataSource = listtable;
gridlist.DataBind();
//now we bind list to gridview there are many ways to take table value in list but this was simple method .
no need to create class or implement any kind of interface.
}
private void Genericswithtable()
{
DataTable temporarytableDt = new DataTable();
temporarytableDt.Columns.Add("Id");
temporarytableDt.Columns.Add("Name", typeof(String));
temporarytableDt.Columns.Add("Email", typeof(String));
temporarytableDt.Rows.Add(1, "dev", "dev@cxom");
temporarytableDt.Rows.Add(2, "deva", "deva@cxom");
//created temporary table so here i am not using any sql server connection just created
temporary table for example.
List<string> listtable = new List<string>();
Declaration of list type string
for (int i = 0; i < temporarytableDt.Rows.Count;i++)
{
listtable.Insert(i, temporarytableDt.Rows[i]["Name"].ToString() +
" / " + temporarytableDt.Rows[i]["Email"].ToString());
}
//untill there will be rows in table all rows value will be inserted in List
//listtable.RemoveAt(1);
listtable.Insert(2, "Raj");
listtable.Add("Raja");
//Now here we can add more value wchich will appear after table value will be displayed.
gridlist.DataSource = listtable;
gridlist.DataBind();
//now we bind list to gridview there are many ways to take table value in list but this was simple method .
no need to create class or implement any kind of interface.
}
0 comments: