asp.net gridview(button field)

I have a grid view which displays 3 columns(Date,orders,amount)..when clicked on Date  it should show all details I mean products sold on that date in other grid with 2 columns(Date and products).

I could bind the other grid too but instead of bringing only particular date when clicked on that it is bringing the entire data.....I mean when I click on date:1/21/2008 it should bring orders sold only on that date in the second grid.....instead it is showing me all the orders on all dates.....how should I pass this to the second grid???

Here is my sample code for second grid.
I appreciate if I get some help....
Thanks!
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
 
        GetData();
        
 
    }
    public void GetData()
    {
        DataTable dt = new DataTable();
      
        string sql = " select  Convert(Varchar(15),a.DateStarted, 101)as Date, b.product " +
                     " FROM Orders a " +
                     " INNER JOIN  OrdersUserIDs b ON a.OrderID = b.OrderID " +
                     " group by Convert(Varchar(15),a.DateStarted, 101), b.product " +
                     " order by Convert(Varchar(15),a.DateStarted, 101)";
       
        List<SqlParameter> Params = new List<SqlParameter>(0);
 
        
         
 
        dt = DataAccess.LoadDataTable(sql, Params);
        dt.Select("Date ='" + GridView1.SelectedValue + "'");
        GridView2.DataSource = dt;
        GridView2.DataBind();
 
 
    }
 
Data.cs:
 
public DataTable LoadDataTable(string sql, List<SqlParameter> inParameters)
    
    {
        int paramCount, index;
        string retVal = string.Empty;
        DataTable dt = new DataTable();
 
        //Database db = DatabaseFactory.CreateDatabase();
        //DbCommand dbcmd = db.GetSqlStringCommand(sql);
 
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["dbconn"].ConnectionString);
        SqlCommand cmd = new SqlCommand(sql, con);
 
        paramCount = inParameters.Count;
        index = 0;
        while (index < paramCount)
        {
            cmd.Parameters.Add(inParameters[index++]);
        }
 
        cmd.CommandType = CommandType.Text;
        SqlDataAdapter adapter = new SqlDataAdapter(cmd);
 
        adapter.Fill(dt);
        return dt;
    }

Open in new window

onebite2Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TSmoothCommented:
The dt.Select() method returns a new DataTable with the filtered results I believe but it does not change the actual DataTable that you call it on. Change the lines as shown below:
// Change these lines
dt.Select("Date ='" + GridView1.SelectedValue + "'");
GridView2.DataSource = dt;
 
// To this
GridView2.DataSource = dt.Select("Date ='" + GridView1.SelectedValue + "'");

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.