set data from gridview into report

Сonversation on different topics
Post Reply
myintw
Posts: 29
Joined: Mon May 09, 2011 8:02 pm
Location: Perth

set data from gridview into report

Post by myintw »

Hi,

I am using Stimulsoft reporting tools. I got some difficulties when I want to shows data from gridview in my report. For instance, in my gridview I have

ProductID, ProductName, ProductType
00000001, Computer PC, Hardware
00000002, Microsft office, Software

and so on. It is all from my gridview, more than that, I would like to display some extra data relating to this columns in my report. So that I get all data which is I want to have on my report from database using sql and also i create my report in design view as well. And I used @productId as parameter so that I can pass my data into report. I have some difficulties in passing parameter into report and it's going just the last item from my gridview. In this example, just only productID 0000002 value is displayed in my report. Actually, I want this both of them on report.
foreach (GridDataItem gdi in GridView1.MasterTableView.Items)
{
foreach (GridFilteringItem filteritem in GridView1.MasterTableView.GetItems(GridItemType.FilteringItem))
{
SqlDataAdapter MyDataAdapter = new SqlDataAdapter("explore_ReportProduct", MyConnection);

//Set the command type as StoredProcedure.
MyDataAdapter.SelectCommand.CommandType = CommandType.StoredProcedure;

//Create and add a parameter to Parameters collection for the stored procedure.
MyDataAdapter.SelectCommand.Parameters.Add(new SqlParameter("@productId", SqlDbType.Int, 4));

//Assign the search value to the parameter.
MyDataAdapter.SelectCommand.Parameters["@productId"].Value = Convert.ToInt32(gdi["Id"].Text);

//Create a new DataSet to hold the records.
DataSet DS = new DataSet();

//Fill the DataSet with the rows that are returned.
MyDataAdapter.Fill(DS, "Product");


for (int i = 0; i < DS.Tables["Product"].Rows.Count; i++)
{
DataRow dr = output.NewRow();
int rowCount = GridView1.MasterTableView.GetItems(new GridItemType[] { GridItemType.Item, GridItemType.AlternatingItem }).Length;
dr["Count"] = rowCount.ToString();
dr["ProductId"] = Convert.ToInt32(gdi["Id"].Text);
dr["ProductName"] = gdi["Name"].Text.Replace(" ", "");
dr["ProductType"] = gdi["Type"].Text.Replace(" ", "");
dr["ProductPrice"] = DS.Tables["Product"].Rows["ProductPrice"];
output.Rows.Add(dr);
}

}

}

This is the way i retrieve data value from gridview and I tried to put but just the last row is going to my report and report shows just one item. Actually I want all item from Gridview , not all data from database though.

Could you please tell me how to solve this. Any sample for this issue. Thanks a lot in advance.

Regards,
win
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

set data from gridview into report

Post by Alex K. »

Hello,

Please send us your project with sample data for analysis.

Thank you.
myintw
Posts: 29
Joined: Mon May 09, 2011 8:02 pm
Location: Perth

set data from gridview into report

Post by myintw »

hi Aleksey,

I got that issue solved out. Thanks you. actually the way i doing in coding behind was wrong and got problem. I used array list and also used " where productId in {productList}" in my sql and pass array list to it. So i got the whole list from gridview.

cheers.
Andrew
Posts: 4108
Joined: Fri Jun 09, 2006 3:58 am

set data from gridview into report

Post by Andrew »

Great!

Have a nice day!
Post Reply