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();
<asp:ControlParameter ControlID="Label1" Name="Tolerance" Type="String" PropertyName="Text" />
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)