Click here to Skip to main content
15,891,864 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hiii Friends...
I have written following code on my button click event...instead i m getting all records.I want perticular one record for selected value of dropdown..Help me If u guys know the solution..

C#
protected void Page_Load(object sender, EventArgs e)
   {
       if (!IsPostBack)
       {
           //BindGrid();
           BindVoucher();
           //BindDrpDown();
       }

   }

public void BindVoucher()
   {
       string str = string.Format("select VoucherNo from vw_Expense");
       DataTable dt1 = db.GetDataTable(str);
       DropDownList1.Items.Clear();
       DropDownList1.DataSource = dt1;
       DropDownList1.DataBind();
       DropDownList1.Items.Insert(0, "Select");
   }

protected void Button1_Click(object sender, EventArgs e)
    {
        ReportDocument cryRpt = new ReportDocument();
        cryRpt.Load(Server.MapPath("CryRpt.rpt"));
        cryRpt.SetDatabaseLogon("sa", "indmxabeais", @"VISHWANATH\SQL2008", "EMS");

        string sqlstr = string.Format("select VoucherNo,ExpDate,Reimbursetype,Amount,Advance,StaffName from vw_Expense where VoucherNo='" + DropDownList1.SelectedValue + "'");
        DataTable dt = db.GetDataTable(sqlstr);

        cryRpt.SetDataSource(dt);
        CrystalReportViewer1.ReportSource = cryRpt;
        CrystalReportViewer1.RefreshReport();
        
    }
Posted
Comments
manognya kota 10-Sep-12 1:50am    
Hi,

I can see a where clause with regard to your dropdown selection.That is what you wanted.If not, please let us know what is your question.
dimpledevani 10-Sep-12 1:51am    
try Debugging your code and you will get it

1 solution

on selection change, write your code code:
C#
string sqlstr = string.Format("select VoucherNo,ExpDate,Reimbursetype,Amount,Advance,StaffName from vw_Expense where VoucherNo='" + DropDownList1.SelectedValue + "'");
        DataTable dt = db.GetDataTable(sqlstr);
 
        cryRpt.SetDataSource(dt);
        CrystalReportViewer1.ReportSource = cryRpt;
        CrystalReportViewer1.RefreshReport();
 
Share this answer
 

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