GridView绑定存储参数和参数 [英] GridView binding Stored Parameter with parameter

查看:48
本文介绍了GridView绑定存储参数和参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

推荐答案

ConnectionStrings:DataBaseConnectionString %>

SelectCommand = SearchDataSP SelectCommandType = StoredProcedure >
< SelectParameters >
< asp:ControlParameter ControlID = Label1 名称 = 容差 / > ...

第二种方式是使用CodeBehind,如

< pre lang = c# > 字符串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();
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


将参数更新为...

Update the parameter to...
<asp:ControlParameter ControlID="Label1" Name="Tolerance" Type="String" PropertyName="Text" />


这篇关于GridView绑定存储参数和参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆