因此,为了让您了解我在使用什么,我有两个下拉框。第一个下拉框有 4 个应用程序的列表。第二个下拉框会随着我在第一个下拉框中的选择而动态变化。我在第二个下拉框中的每个选择都有一个图表。我总共有 16 个图表。每次我更改第二个选择时,图表都会更改,因此一次只显示一个图表。我使用 if else 语句,它已经变得难以跟上。我也有标签,我必须与每个图表切换,这样它就会失控。这是我的一个 else if 语句的一个小例子。
else if (ddlApplication.SelectedItem.Text == "Rapp" && ddlTests.SelectedItem.Text == "Total Test Runs")
{
string query = string.Format("select TestName,Count (TestName) AS Counts from VExecutionGlobalHistory where TestTypeID = 2 group by TestName", ddlTests.SelectedItem.Value);
DataTable dt = GetData(query);
//Loop and add each datatable row to the Pie Chart Values
foreach (DataRow row in dt.Rows)
{
SpecificTestsRapp.PieChartValues.Add(new AjaxControlToolkit.PieChartValue
{
Category = row["TestName"].ToString(),
Data = Convert.ToDecimal(row["Counts"])
});
}
string SpecificTestsRappS = null;
string sql2 = "select Count (TestName) AS Counts from VExecutionGlobalHistory where TestTypeID = 2 ";
string connString2 = ";Initial Catalog=Performance;User ID=;Password=";
using (SqlConnection conn = new SqlConnection(connString2))
{
conn.Open();
using (SqlCommand command = new SqlCommand(sql2, conn))
{
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
SpecificTestsRappS = reader[0].ToString();
lblTotalTestsRapp.Text = SpecificTestsRappS;
break;
}
}
conn.Close();
}
SpecificTestsRapp.ChartTitle = "Total Tests Run";
TotalTestsWeb6.Visible = false;
HoursWeb6.Visible = false;
TotalValidationsWeb6.Visible = false;
CostComparisonWeb6.Visible = false;
SpecificTestsWeb6.Visible = false;
TotalTestsRapp.Visible = false;
TotalValidationsRapp.Visible = false;
SpecificTestsRapp.Visible = true;
HoursRapp.Visible = false;
IONChart.Visible = false;
CostComparisonRapp.Visible = false;
txtTotalHoursRapp.Visible = false;
lblTotalHoursRapp.Visible = false;
txtTotalHoursRappA.Visible = false;
lblTotalHoursRappA.Visible = false;
txtTotalCostRappM.Visible = false;
lblTotalCostRappM.Visible = false;
txtTotalCostRappA.Visible = false;
lblTotalCostRappA.Visible = false;
txtTotalTestsRapp.Visible = true;
lblTotalTestsRapp.Visible = true;
lblTotalValidationsRapp.Visible = false;
txtTotalValidationsRapp.Visible = false;
lblTotalValidations.Visible = false;
txtTotalValidations.Visible = false;
lblTotalTests.Visible = false;
txtTotalTests.Visible = false;
txtTotalHours.Visible = false;
lblTotalHours.Visible = false;
txtTotalHoursA.Visible = false;
lblTotalHoursA.Visible = false;
txtTotalCostA.Visible = false;
lblTotalCostA.Visible = false;
txtTotalCostM.Visible = false;
lblTotalCostM.Visible = false;
Label1.Visible = false;
Label2.Visible = false;
}
从技术上讲,当我完成时,我需要其中的 16 个,因为我有 16 个图表。必须有一种更有效的方法来做到这一点。有什么建议么?