Wednesday, August 11, 2010

How can i use recordset to populate DataGrid and DataCombo without dropping ado control on the form.?

Visual Basic


Dim cn as ADODB.connection


Dim rs as ADODB.recordset





' without dropping adodb data control on the form at design timeHow can i use recordset to populate DataGrid and DataCombo without dropping ado control on the form.?
if (recordset.rows.count %26gt;0)


{


System.Web.UI.WebControls.GridView gvSegBuilCostAll = new System.Web.UI.WebControls.GridView();


//Assigning properties to the gridview.


gvSegBuilCostAll.AutoGenerateColumns = true;


gvSegBuilCostAll.Width = 100;


//Declaring a datatable


DataTable dt = new DataTable();


//populate the datatable with the dataset returned from the database.


dt = dsTest.Tables[i];





//populate the Grid with the values of the datatable dt.


gvSegBuilCostAll.DataSource = dt;





//Assigning id of the datagrid appended with the loop string.


gvSegBuilCostAll.ID = ';DataGrid'; + i.ToString();





//assign the gridview client ID as the id of the datagrid.


gvClientID = gvSegBuilCostAll.ID;





//Firing the row databound event of the datagrid.


gvSegBuilCostAll.RowDataBound += new GridViewRowEventHandler(gvSegBuilCostAll鈥?br>




//Binding the datagrid.


gvSegBuilCostAll.DataBind();





//Setting the properties of the datagrid.


gvSegBuilCostAll.Width = 500;


gvSegBuilCostAll.GridLines = GridLines.Both;


gvSegBuilCostAll.CellPadding = 1;


gvSegBuilCostAll.ForeColor = System.Drawing.Color.Black;





//Setting the properties for the grid header.


gvSegBuilCostAll.CssClass = ';GridItem';;


gvSegBuilCostAll.HeaderStyle.BackColor = System.Drawing.Color.Black;


gvSegBuilCostAll.HeaderStyle.ForeColor = System.Drawing.Color.White;


gvSegBuilCostAll.HeaderStyle.CssClass = ';GridHeader';;





//Adding the datagrid to the placeholder.


plchGrid.Controls.Add(gvSegBuilCostAll);








}





just change the control name as per ur requirement so that the control is dynamically generated.





use find control method to identify the control

No comments:

Post a Comment