问题描述
Background: I want to use GridView bind a Stored Procedure with some TextBox passing parameters.
I found two ways: First is Graphically setting GridView Bind a DataSourceLike This:
<asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1" >
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:DataBaseConnectionString %>"
SelectCommand="SearchDataSP" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:ControlParameter ControlID="Label1" Name="Tolerance"/> ...
Second way is using CodeBehind like
<pre lang="c#">String strConnString = ...
SqlConnection con = new SqlConnection(strConnString);
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "SearchDataSP";
cmd.Parameters.Add("@Tolerance", SqlDbType.TinyInt).Value = DbNullIfNullOrEmpty(Label1.Text);
GridView1.DataSource = cmd.ExecuteReader();
GridView1.DataBind();
所以我的问题是:如果我使用具有自动分页的First Solution,Auto - 分类,但是当我点击按钮时,没有结果,我认为参数不是传递到存储过程,但为什么?
第二个解决方案我可以得到数据,但没有自动分页,自动分类和选择。
请给我一些建议。
我真诚地感谢您的帮助
So My Problem is: If I use First Solution which has auto-Paging, Auto-Sorting, but When I click button, there is no result, I think the Parameter is not Passing to Stored Procedure, but Why??
Second solution I can get data but there is no auto-paging, auto-sorting and selection.
Please give me some advice for this.
I sincerely honestly appreciated your help
推荐答案
所以我的问题是:如果我使用具有自动分页的First Solution,Auto - 分类,但是当我点击按钮时,没有结果,我认为参数不是传递到存储过程,但为什么?
第二个解决方案我可以得到数据,但没有自动分页,自动分类和选择。
请给我一些建议。
我真诚地感谢您的帮助
So My Problem is: If I use First Solution which has auto-Paging, Auto-Sorting, but When I click button, there is no result, I think the Parameter is not Passing to Stored Procedure, but Why??
Second solution I can get data but there is no auto-paging, auto-sorting and selection.
Please give me some advice for this.
I sincerely honestly appreciated your help
<asp:ControlParameter ControlID="Label1" Name="Tolerance" Type="String" PropertyName="Text" />
这篇关于GridView绑定存储参数和参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!