Привязать checkboxlist к datatable C#
I have a large table with roughly 70 columns. I have a checkboxlist listing the column names and when the user checks certain items from that list (limit of 3 for now), it will create a multi line/multi series graph from those selections and use the items selected to create the legend as well. I can get the graph to create but it is not graphing the columns I select and is just doing the last column in the checkboxlist. I don't know why it is only doing 1 column and not all the ones selected and I am not sure why the legend creates a series for each item in the checkbox - regardless of what is selected.
Что я уже пробовал:
с моей aspx-файл.CS страницы - привязка к таблице DataTable
protected void BindChart() { //Add columns to the DataTable string oradb = "Data Source=P3CMS;Persist Security Info=True;User ID=cmsuser;Password=cmssystem"; OracleConnection cn = new OracleConnection(oradb); cn.Open(); string cmdstr = ""; string selectedValue = ""; cmdstr = "SELECT DISTINCT CEM_READING_DATE, BATTERY_NAME, TURN "; //Build the IN string by looping through the listbox for (int i = 0; i < ListBoxSelection.Items.Count; i++) { if (ListBoxSelection.Items[i].Selected) { selectedValue = selectedValue + ", " + ListBoxSelection.Items[i].Value; } } selectedValue = selectedValue.TrimEnd(','); cmdstr = cmdstr + selectedValue + " FROM CEM_READINGS "; //Create the WHERE string strWhere = "WHERE (CEM_READING_DATE >= TO_DATE('" + tbStartDate.Text + "','MM/DD/YYYY HH:MI:SS AM')) " + "AND (BATTERY_NAME = '" + DropDownList1.SelectedValue + "') " + "AND (TURN = '" + ddlTurn.SelectedValue + "') " + "AND ROWNUM <= 100 " + "ORDER BY CEM_READING_DATE ASC"; //Add WHERE clause cmdstr = cmdstr + strWhere; OracleCommand cmd = new OracleCommand(cmdstr, cn); OracleDataAdapter adapter = new OracleDataAdapter(cmd); DataSet ds = new DataSet(); adapter.Fill(ds); DataTable dt = ds.Tables[0]; string[] x = new string[dt.Rows.Count]; int[] y = new int[dt.Rows.Count]; for (int i = 0; i < dt.Rows.Count; i++) { x[i] = dt.Rows[i][0].ToString(); CEMGRAPH.Series[0].XValueType = ChartValueType.DateTime; } for (int col = 3; col < dt.Columns.Count; col++) { Series series = new Series(); string ColName = dt.Columns[col].ColumnName; string retVal = string.Empty; bool bFound = true; for (int i = 0; i < CheckBoxList1.Items.Count; i++) { if (CheckBoxList1.Items.Count > i) if (CheckBoxList1.Items.Count == i) { selectedValue = selectedValue + ", " + CheckBoxList1.Items[i].ToString(); } } if (bFound) { for (int i = 0; i < dt.Rows.Count - 1; i++) { y[i] = Convert.ToInt32(dt.Rows[i][col]); } CEMGRAPH.Series[0].Points.DataBindXY(x, y); CEMGRAPH.Series.Add("Series" + (col).ToString()); CEMGRAPH.Series[0].ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.Line; CEMGRAPH.Legends["Default"].Enabled = true; CEMGRAPH.Series[0].IsVisibleInLegend = true; } } }
j snooze
похоже, это будет ваша проблема.
if (CheckBoxList1.Предметы.Граф = = я)
{
selectedValue = selectedValue + ", " + CheckBoxList1.Элементы[я].Метод toString();
}
я буду равняться только количеству элементов checkboxlist в последний раз. или, возможно, я не понимаю, чего пытается достичь этот код.