dharmendr says:
Hi nagaraju60,
Ok let’s say 10 maximum columns.
But let me explain if you are generate 2 columns then how do you pass column name to the insert query and if its 8 then how do you pass column name to the insert query.
As we need to pass column name to the insert query since we are generating number of columns based on textbox value.
One option is you need to check condition 10 times and most important you can't assign column name randomly you have to assign sequentially.
Thanks for reply @dharmendr,
first i will pass the column value in to datatable after next i will insert in to database.
protected void GenerateGridView(object sender, EventArgs e)
{
gvData.Columns.Clear();
DataTable dt = new DataTable();
int cols = Convert.ToInt32(txtColumns.Text.Trim());
int rows = Convert.ToInt32(txtRows.Text.Trim());
for (int i = 0; i < cols; i++)
{
TemplateField field = new TemplateField();
field.HeaderText = "Column" + i.ToString();
field.ItemTemplate = new GridViewTemplate("Column" + i.ToString(), i.ToString());
gvData.Columns.Add(field);
}
for (int i = 0; i < rows; i++)
{
dt.Rows.Add();
}
gvData.DataSource = dt;
gvData.DataBind();
}
by changing above code i will get column name individually.
please help me how to store those column values in data table