J
JohnE
Have a gridview that is to have a search available for one column. The
column is called ChangeRequest, with header text of Change Request. Outside
the grid there is a textbox (txtSearch) that the user can type into and the
click a button to search the column. Below is the code for the search button
click. The error I am getting is 'Cannot find column [ChangeRequest].' The
column is there otherwise there wouldn't be any info in it. The sql is the
same one that initially fills the gridview. Just to make sure, I copied the
connection info into the button click to see if that was the cause.
string connStr =
ConfigurationManager.ConnectionStrings["ProteusConnectionString"].ConnectionString;
string sql = "SEL_GridviewList";
SqlDataAdapter sqlDa = new SqlDataAdapter(sql, connStr);
DataSet ds = new DataSet();
sqlDa.Fill(ds);
//DataView dv = new DataView();
DataTable dt = new DataTable();
DataView dv = new DataView(dt);
string SearchExpression = null;
if (!String.IsNullOrEmpty(txtSearch.Text))
{
SearchExpression = string.Format("{0}'%{1}%'",
GridView1.SortExpression, txtSearch.Text);
}
dv.RowFilter = "ChangeRequest like " + SearchExpression;
GridView1.DataSource = dv;
GridView1.DataBind();
Can anyone see what is missing or what else might be causing the error?
Thanks.
John
column is called ChangeRequest, with header text of Change Request. Outside
the grid there is a textbox (txtSearch) that the user can type into and the
click a button to search the column. Below is the code for the search button
click. The error I am getting is 'Cannot find column [ChangeRequest].' The
column is there otherwise there wouldn't be any info in it. The sql is the
same one that initially fills the gridview. Just to make sure, I copied the
connection info into the button click to see if that was the cause.
string connStr =
ConfigurationManager.ConnectionStrings["ProteusConnectionString"].ConnectionString;
string sql = "SEL_GridviewList";
SqlDataAdapter sqlDa = new SqlDataAdapter(sql, connStr);
DataSet ds = new DataSet();
sqlDa.Fill(ds);
//DataView dv = new DataView();
DataTable dt = new DataTable();
DataView dv = new DataView(dt);
string SearchExpression = null;
if (!String.IsNullOrEmpty(txtSearch.Text))
{
SearchExpression = string.Format("{0}'%{1}%'",
GridView1.SortExpression, txtSearch.Text);
}
dv.RowFilter = "ChangeRequest like " + SearchExpression;
GridView1.DataSource = dv;
GridView1.DataBind();
Can anyone see what is missing or what else might be causing the error?
Thanks.
John