//for binding Grid protected void getdata() { try { DataTable dt = new DataTable(); for (int i = 0; i < int.Parse(txtcolumns.Text); i++) { DataColumn dcol = new DataColumn(); //dcol.AutoIncrement = true; dt.Columns.Add(dcol); } for (int i = 0; i < int.Parse(txtrows.Text); i++) { DataRow dr = dt.NewRow(); dt.Rows.Add(dr); } GridView1.DataSource = dt; GridView1.DataBind(); } catch (Exception ex) { lblerror.Visible = true; lblerror.Text = ex.Message; } }
//Rowdatabound try { int inte = e.Row.RowIndex + 1; if (cbxseats.Checked == true) { if (inte == int.Parse(txtdivider.Text)) { if (e.Row.RowType == DataControlRowType.DataRow) { for (int i = 0; i < int.Parse(txtcolumns.Text); i++) { TextBox tbx = new TextBox(); tbx.Width = 40; tbx.Height = 20; tbx.ID = "txtbox" + inte + i; //tbx.Text = "45"; //tbx.ReadOnly = true; if (i + 1 == int.Parse(txtcolumns.Text)) { e.Row.Cells[i].Controls.Add(tbx); } } } } else { for (int i = 0; i < int.Parse(txtcolumns.Text); i++) { if (e.Row.RowType == DataControlRowType.DataRow) { TextBox tbx = new TextBox(); tbx.Width = 40; tbx.Height = 20; tbx.ID = "txtbox" + inte + i; e.Row.Cells[i].Controls.Add(tbx); } } } } else if (cbxbearths.Checked == true) { if (inte == int.Parse(txtdivider.Text)) { if (e.Row.RowType == DataControlRowType.DataRow) { e.Row.Cells[0].Controls.Add(new LiteralControl("<br/>")); } } else { for (int i = 0; i < int.Parse(txtcolumns.Text); i++) { if (e.Row.RowType == DataControlRowType.DataRow) { TextBox tbx = new TextBox(); tbx.Width = 80; tbx.Height = 20; tbx.ID = "txtbox" + inte + i; e.Row.Cells[i].Controls.Add(tbx); } } } } catch (Exception ex) { lblerror.Visible = true; lblerror.Text = ex.Message; } }
//on button click event i am calling that getdata() to bind the gridview protected void btnlayout_Click(object sender, EventArgs e) { try { getdata(); lbllower.Visible = true; //btnupperdeck_Click(sender, e); } catch (Exception ex) { lblerror.Visible = true; lblerror.Text = ex.Message; } }
DataTable dt = new DataTable();
getData
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)