Last post Sep 14, 2011 12:49 AM by ilia.sir.motie
Sep 10, 2011 03:30 AM|raffi_ohanian|LINK
I have GridViewSeach and i have 8 sqldatasrouce-s I want to change the datasource dynamically during the program .
Is that possible?
GridViewSearch.DataSource = SqlDataSource1; is not working !
Sep 10, 2011 03:33 AM|PNasser|LINK
After setting the DataSource, you must bind it, GridViewSearch.DataBind();
Sep 10, 2011 03:40 AM|raffi_ohanian|LINK
Yeah sure I do that , but still not woriking .
When im selecting the datasource from the design section before Ctl+F5 its working just fine . but when im diselecting anydatasource and then trying to do it in a submit button its not working ! what could be the problem?
Sep 10, 2011 03:53 AM|PNasser|LINK
Can you post relevant code?
Sep 11, 2011 08:44 PM|Decker Dong - MSFT|LINK
You cannot offer a SqlDataSource1—— an data source control to GridView (the data presentation control) directly. You should do like this:
And any way, I suggest you trying to use several SqlDataAdapters and Fill data contents into DataSet, thus you can get several tables. And bind these tables to GridView accroding to different kinds of situations. Something like this:
using (SqlDataAdapter adapter = new SqlDataAdapter("select * from xxx","Your conn str"))
if(some condition 1)
adapter.SelectCommand.CommandText="Your new sql string";
DataTable dt = new DataTable();
GridView1.DataSource = dt;
Sep 14, 2011 12:49 AM|ilia.sir.motie|LINK
you could change the connection string name...