Sunday, 1 September 2013

Bind data dynamically to div without using server side controls

Steps :- Here i have data in List control and i will bind it to Div with id(DivSupp_Services).


List<string> columnNames = new List<string>();
     
        //Binding Data Dynamically to Div :-

        System.Web.UI.WebControls.Table otable = new System.Web.UI.WebControls.Table();
        TableRow orow = new TableRow();   // Row Creation.
        TableCell ocell;   // Cell Creation.

        for (int i = 0; i < columnNames.Count; i++)
        {
            //orow = new TableRow();  //Write if data binding should be Vertical.
            ocell = new TableCell();
            ocell.Text = columnNames[i].ToString();
            orow.Cells.Add(ocell);          
            otable.Rows.Add(orow);
        }

        DivSupp_services.Controls.Add(otable);   // Binding of Dynamically Created table to Div.
    }

No comments:

Post a Comment