Click here to Skip to main content
15,888,156 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
XML
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();


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
Posted

1 solution

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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900