Monday 15 September 2014

List(Generic) | DataTable | Bind Gridview with examples

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.
    }




Share This
Previous Post
Next Post

FYJC XI standard online admisson Process and declaraton of Merit list . Cut off List For prevous year also . 10 Th Results onlne declaraton Maharashtra Region .

0 comments: