Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
someone pls give me a related sample code
Posted

You need to try first by yourself.

Follow these steps:
1. Design a form where you place few search parameters. For example, here for you - from date, to date calendars & a textbox for ID.
2. Now, place a search button as the trigger control of the search. On click event of search button you would be writing your logic.
3. In search button click, get the search parameters (like the id in textbox, dates in calendar), use it, form a query, put it in database as Stored Procedure and execute on database
4. Get the SP result back in a datatable and bind it to a grid or any other appropriate control based on your needs
5. For now, Datagrid will display the retrieved result.

Done!
 
Share this answer
 
v2
Comments
Member 8983639 23-May-12 22:47pm    
how to send textbox data into stored procedure in general in sql queries we wrtie a query string but here the case is different its a stored procedure so how to do
Hi ,
Check this
C#
    protected void Page_Load(object sender, EventArgs e)
{

    if (!IsPostBack)
    {
        //Bring all Data in First load
        Bind();
    }
    else
    {
        if (ViewState["dt"] != null)
        {
            dt = (DataTable)ViewState["dt"];
            GridView1.DataSource = dt;
            GridView1.DataBind();
        }
    }

}
DataTable dt = new DataTable();
DataTable search(int id)
{
    using (
          SqlConnection con =
              new SqlConnection(ConfigurationManager.ConnectionStrings["testConnectionString"].ConnectionString))
    {

        SqlCommand cmd = new SqlCommand("usp_Search_All", con);

        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.AddWithValue("id", id);
        SqlDataAdapter adpt = new SqlDataAdapter(cmd);
        adpt.Fill(dt);
        GridView1.DataSource = dt;
        GridView1.DataBind();
        cmd.Dispose();
        return dt;

    }
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
    GridView1.PageIndex = e.NewPageIndex;
    GridView1.DataSource =(DataTable)ViewState["dt"];
    GridView1.DataBind();

}
protected void Button1_Click(object sender, EventArgs e)
{
    dt = search(Convert.ToInt32(TextBox1.Text));
    ViewState.Add("dt", dt);
}
void Bind()
{
    using (
          SqlConnection con =
              new SqlConnection(ConfigurationManager.ConnectionStrings["testConnectionString"].ConnectionString))
    {

        SqlCommand cmd = new SqlCommand("usp_Select_All", con);
        cmd.CommandType = CommandType.StoredProcedure;
        SqlDataAdapter adpt = new SqlDataAdapter(cmd);
        adpt.Fill(dt);
        GridView1.DataSource = dt;
        GridView1.DataBind();
        cmd.Dispose();


    }
}

XML
<div>
        

<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
            onpageindexchanging="GridView1_PageIndexChanging" PageSize="5">
        </asp:GridView>
        <br />
        <br />
        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
&nbsp;
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    </div>


Best Regards
M.Mitwalli
 
Share this answer
 
v3
Comments
Member 8983639 23-May-12 22:44pm    
thanks alot and lot so much im new to .net and all one doubt is this same for windows application also?
Member 8983639 23-May-12 22:50pm    
i want to get data from stored procedure....
Mohamed Mitwalli 24-May-12 1:21am    
Check the Solution it's already updated
frankly it's a great job , but i want to know the code about the stored procedure that we created
 
Share this answer
 
Can you elaborate what you mean from stored procedure? Do you want to do filtering in stored procedures? Or do you have filtered data and want to fill data grid view with the filtered data?
 
Share this answer
 
Comments
Member 8983639 23-May-12 8:00am    
i want to filter the datagridview when user search an value in textbox where my data is present in stored procedure i have 3 parameters in it 1) from date 2)to date 3) Supervisor ID. now i need to filter the grid view from searchbox(textbox)
Member 8983639 23-May-12 8:00am    
pls help me with sample code

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