-1

I would appreciate if anyone could help me here:

I had two dropdowns and added the third one (Category) in a C# report page, how to get the data of all dropdowns from sql server.

1st dropdown: ddlReportType 2nd dropdown: ddlGroup 3rd dropdown: ddlcategory

below is my code:

  public void Reportquery()
    {
        switch (this.ddlReportType.SelectedValue)
        {
            case "1":
                //successfully Loaded
                switch (ddlGroup.SelectedValue)
                {
                    case "All":
                        Session["Select_Query"] = "Select ID, CONVERT(CHAR(10), SCAN_DATE, 111) SCAN_DATE,Substring(SUBSCRIBER,1,20) DEALER_ID," + " MSISDN,FILE_PATH,USERNAME, Category, 'File Uploaded' Report_Criteria  from UPLOAD where scan_date between'" + cldrFrom.SelectedValue + "' and '" + cldrTo.SelectedValue + "'";

                        Session["Count_Query"] = "Select Count(*) as Cnt from UPLOAD" + " where scan_date between'" + cldrFrom.SelectedValue + "' and '" + cldrTo.SelectedValue + "'";
                        break;
                    default:
                        Session["Select_Query"] = "Select ID, CONVERT(CHAR(10), SCAN_DATE, 111) SCAN_DATE,Substring(SUBSCRIBER,1,20) DEALER_ID," + " MSISDN,FILE_PATH,USERNAME,Category, 'File Uploaded' Report_Criteria  from UPLOAD  " + " where scan_date between'" + cldrFrom.SelectedValue + "' and '" + cldrTo.SelectedValue + "' and rtrim(ltrim(Subscriber)) ='" + ddlGroup.SelectedItem.Text.Trim() + "'";

                        Session["Count_Query"] = "Select Count(*) as Cnt from UPLOAD" + " where scan_date between'" + cldrFrom.SelectedValue + "' and '" + cldrTo.SelectedValue + "' and rtrim(ltrim(Subscriber)) ='" + ddlGroup.SelectedItem.Text.Trim() + "'";

                        break;
                }
                break;

            case "2":
                //Failed to laod
                switch (ddlGroup.SelectedValue)
                {
                    case "All":
                        Session["Select_Query"] = "Select Value as ID, CONVERT(CHAR(10), SCAN_DATE, 111) SCAN_DATE, SUBSCRIBER as Dealer_ID, " + " FileName as MSISDN,File_Path, username, Category, 'File Rejected' as Report_Criteria  from CRI_Rejected a, code_rejected b " + " where a.Rejection_Code=b.id  and scan_date between'" + cldrFrom.SelectedValue + "' and '" + cldrTo.SelectedValue + "'";

                        Session["Count_Query"] = "Select count(a.ID) as cnt  from CRI_Rejected a, code_rejected b " + " where a.Rejection_Code=b.id and scan_date between'" + cldrFrom.SelectedValue + "' and '" + cldrTo.SelectedValue + "'";
                        break;
                    default:
                        Session["Select_Query"] = "Select Value as ID, CONVERT(CHAR(10), SCAN_DATE, 111) SCAN_DATE, SUBSCRIBER as Dealer_ID, " + " FileName as MSISDN,File_Path, username,  Category, 'File Rejected' as Report_Criteria  from CRI_Rejected a, code_rejected b " + " where a.Rejection_Code=b.id  and scan_date between'" + cldrFrom.SelectedValue + "' and '" + cldrTo.SelectedValue + "'" + " and rtrim(ltrim(Subscriber)) ='" + ddlGroup.SelectedItem.Text.Trim() + "'";

                        Session["Count_Query"] = "select count(*) as cnt from CRI_Rejected where scan_date between'" + cldrFrom.SelectedValue + "' and '" + cldrTo.SelectedValue + "'" + " and rtrim(ltrim(Subscriber)) ='" + ddlGroup.SelectedItem.Text.Trim() + "'";

                        break;
                }
                break;
        }
    }

report page screenshot

Stubborn
  • 1
  • 2
  • Please [parameterise your queries](https://stackoverflow.com/questions/7505808/why-do-we-always-prefer-using-parameters-in-sql-statements) to avoid a huge security hole. – Hayden Aug 20 '20 at 06:47

1 Answers1

0

Use a datasource and then bind it to the dropdownlist, be sure to set the datatext and dataavalue values. Its pretty simple, see here https://www.aspsnippets.com/Articles/Bind-Fill-Populate-DropDownList-control-from-database-in-ASPNet-using-C-and-VBNet.aspx

JobesK
  • 347
  • 1
  • 2
  • 6