示例我有一个文本框输入,输入文本框的内容自定义查询用户输入的内容,文本框中的示例,我尝试输入文本"从国家/地区选择ID,名称,国家/地区#34; ..从sql查询对国家表的3 coloumn的结果,我问如何取列数,文本框自定义输入的列名..到我要在文本框中显示的列数和gridview中的行数在查询中适当的列数,对于我想在gridview中显示的列的名称..
private void BindReportColumn(String report_id)
{
dt = mda.GetData("SELECT column_name,column_text,size,back_color,fore_color FROM report_column INNER JOIN report ON report_column.report_id = report.report_id and report.report_id='" + report_id + "'", connStr).Tables[0];
GridCustomColumn.DataSource = dt;
GridCustomColumn.DataBind();
}
private void addcolumn()
{
int i;
//Add the items to the gridview
DataTable dt = new DataTable();
//Assign the viewstate to the datatable
if (!IsNumeric(txtcolumn_count.Text)) txtcolumn_count.Text = "0";
dt = (DataTable)ViewState["columnreport"];
for (i = 1; i <= Convert.ToInt32(txtcolumn_count.Text); i++)
{
DataRow dr = dt.NewRow();
//dr["report_id"] = txtreport_id.Text;
dr["column_name"] = "";
dr["column_text"] = " ";
dr["size"] = 0;
dr["back_color"] = "";
dr["fore_color"] = "";
//Add the datarow to the datatable
dt.Rows.Add(dr);
//Now bind the datatable to the gridview
GridCustomColumn.DataSource = dt;
GridCustomColumn.DataBind();
//Add the details to viewstate also
ViewState["columnreport"] = dt;
}
}
提前致谢