How to get three drop-down's data together in C#

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

Add Comment
1 Answer(s)

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

Answered on August 30, 2020.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.