?
Solved

asp.net gridview(button field)

Posted on 2008-01-28
1
Medium Priority
?
2,991 Views
Last Modified: 2008-02-26
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

0
Comment
Question by:onebite2
1 Comment
 
LVL 16

Accepted Solution

by:
TSmooth earned 1500 total points
ID: 20767298
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

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…
This video tutorial shows you the steps to go through to set up what I believe to be the best email app on the android platform to read Exchange mail.  Get the app on your phone: The first step is to make sure you have the Samsung Email app on your …

588 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question