Click here to Skip to main content
15,886,258 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I have a drop down list which has 5 options earrings, necklace,bangles,rings, bracelets

and beside that i have two buttons. 1 show button and 1 print button.

on clicking any of the options from drop down list, then clicking on show,the gridview data shows of that particular type.

e.g
sl.no category cost price sold price
2 earrings 200 400
3 earrings 5000 3000
7 earrings 7000 2000

now i want clicking on print button, these data to be showed in crystal report and print directly from there.

how to do so?

i have created dataset also.

i will attach the code also.

C#
private DataSet GetAllJewellery()
    {
        using (SqlConnection con = new SqlConnection(JewelleryHelper.GetConnectionString()))
        {
            using (SqlCommand cmd = new SqlCommand("spGetJeweleryOnSoldItems", con))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add("@Category", SqlDbType.VarChar).Value = ddlCategory.SelectedItem.Text;
                con.Open();
                SqlDataAdapter sda = new SqlDataAdapter(cmd);
                DataSet ds = new DataSet();
                sda.Fill(ds);
                con.Close();
                return ds;
            }
        }
    }

    protected void btnPrint_Click(object sender, EventArgs e)
    {
        SoldItemsDataSetTableAdapters.spGetJeweleryOnSoldItemsTableAdapter getAllJewellerySoldItems = new SoldItemsDataSetTableAdapters.spGetJeweleryOnSoldItemsTableAdapter();
        DataTable dt = getAllJewellerySoldItems.GetAllJewellerySoldItems(this.ddlCategory.SelectedValue);
        ReportDocument rDoc = new ReportDocument();
        rDoc.Load(Server.MapPath("soldCrystalReport.rpt"));
        rDoc.SetDataSource(dt);
        rDoc.SetParameterValue("Category", this.ddlCategory.SelectedValue);
        this.crystalReportViewer.ReportSource = rDoc;
        this.crystalReportViewer.DataBind();
        this.crystalReportViewer.Focus();
    }
}


but its not coming.

can anyone please help me.

Thanks
as i am stuck in here for the last 4 days.
Posted
Comments
Keerthi Kumar(Andar) 4-Feb-15 23:41pm    
Hi sudeshna,
in the above code you r referring a different method
ie, GetAllJewellerySoldItems(this.ddlCategory.SelectedValue);

but you are showing a different method
ie GetAllJewellery()
sudeshna from bangkok 4-Feb-15 23:55pm    
spGetJeweleryOnSoldItems is a store procedure and getalljewellerysolditems is dataset
sudeshna from bangkok 4-Feb-15 23:56pm    
if you think its wrong then can you tell me the code please as to what to do?
Sinisa Hajnal 5-Feb-15 2:41am    
Is the printer you're trying to print to default on the system? If you're trying to print on the user computer, you don't have control over it. I would suggest you create separate page formatted for printing. Give it the data neeeded and call in that page onload event window.print(); Or if you want the user to preview before he prints then have print button that will trigger this.

There is an option to print from CR, but you'll have to check their documentation, I always found it too cumbersome.

1 solution

This is simple method I am going to tell you, you can make it according to your need.
1-Make a crystal report with same columns present in the DataGridView.
2-Make your Datatable according to your requirements and then assign that datatable used for DataGridView and used as Datasource for Crystal Report.

Here is a detailed complete article you can take help from it if you are beginner.
DataGridView to Crystal Report in C#[^]

Cheers,Enjoy Coding :)
 
Share this answer
 
v2

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