selectcommand

SqlDataSource set SelectCommand dynamically

人走茶凉 提交于 2019-12-11 14:30:06
问题 I'm using a SqlDataSource and to avoid writing long queries directly in my code I thought I could make a Query class that returns the query I want as a string. I tried the code below but I just get "Server tags cannot contain <% ... %> constructs." Before I was using stored procedures but my webhosting doesn't allow that, so thats when I thought about the Query class solution. I also need to add that I don't want to do databinding in codebehind. Is there a way of doing this? <asp

Changing SqlDataSource.SelectCommand at runtime breaks pagination

余生颓废 提交于 2019-11-29 05:02:16
I have a GridView bound to a SqlDataSource with a default SelectCommand defined as such: <asp:SqlDataSource ID="SqlDataSource1" runat="server" DataSourceMode="DataSet" ConnectionString="<%$ ConnectionStrings:MyConn %>" ProviderName="MySql.Data.MySqlClient" SelectCommand="select * from blah blah" /> There are cases where I have to change this query dynamically at runtime, so I do the following: SqlDataSource1.SelectCommand = sql; // 'sql' is the new query GridView1.PageIndex = 0; GridView1.EditIndex = -1; GridView1.SelectedIndex = -1; GridView1.DataBind(); updatePanel.Update(); This works just

Changing SqlDataSource.SelectCommand at runtime breaks pagination

末鹿安然 提交于 2019-11-27 18:51:57
问题 I have a GridView bound to a SqlDataSource with a default SelectCommand defined as such: <asp:SqlDataSource ID="SqlDataSource1" runat="server" DataSourceMode="DataSet" ConnectionString="<%$ ConnectionStrings:MyConn %>" ProviderName="MySql.Data.MySqlClient" SelectCommand="select * from blah blah" /> There are cases where I have to change this query dynamically at runtime, so I do the following: SqlDataSource1.SelectCommand = sql; // 'sql' is the new query GridView1.PageIndex = 0; GridView1