»Dotnet Ads
»Message Boards
Message Boards
Dotnet Books
»Member Details
Register
Login
LogOut
Submit Code
Submit Jobs
Submit Projects
»Competition
Community
Winners
Prizes
Write For Us
Members
»Other Resources
Links
Dotnet Resources
|
Creates the Dynamic Label and TextBox controls SqlConnection con = new SqlConnection();
SqlCommand cmd = new SqlCommand();
SqlDataAdapter da = new SqlDataAdapter();
protected void Page_Load(object sender, EventArgs e)
{
dynamicControlCreation();
}
// Execute the required SQL Command and send the result in DataSet
public DataSet executeSqlCmd(string sqlCmd)
{
DataSet ds = new DataSet();
cmd = new SqlCommand(sqlCmd, con);
cmd.Connection = con;
da.SelectCommand = cmd;
da.Fill(ds);
return ds;
}
// Creates the Dynamic Label and TextBox controls
public void dynamicControlCreation()
{
DataSet ds = new DataSet();
ds = executeSqlCmd("select names,age,emailId,phoneNo from tab_nightshift");
for (int j = 0; j < ds.Tables[0].Rows.Count; j++)
{
for (int k = 0; k < ds.Tables[0].Columns.Count; k++)
{
TextBox txtBox = new TextBox();
txtBox.Text = ds.Tables[0].Rows[j][k].ToString();
form1.Controls.Add(txtBox);
}
form1.Controls.Add(new LiteralControl("<br>"));
}
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
Table ourTable = new Table();
TableRow ourTrow = new TableRow();
TableCell ourTcolumn1 = new TableCell();
TableCell ourTcolumn2 = new TableCell();
TableCell ourTcolumn3 = new TableCell();
Label ourLabel = new Label();
TextBox ourText = new TextBox();
TextBox ourText2 = new TextBox();
ourLabel.Text = ds.Tables[0].Rows[i][0].ToString();
ourText.Text = ds.Tables[0].Rows[i][1].ToString();
ourText2.Text = ds.Tables[0].Rows[i][2].ToString();
ourTcolumn1.Controls.Add(ourText);
|