public void ClearTextBoxes(Control ctr)
{
foreach (Control ctrl in ctr.Controls)
{
if (ctrl is TextBox)
{
TextBox t = ctrl as TextBox;
if (t != null)
{
t.Text = String.Empty;
}
}
else
{
if (ctrl.Controls.Count > 0)
{
ClearTextBoxes(ctrl);
}
}
}
}
Chart.DataBindTable |
|
|
Chart.DataSource and Chart.DataBind |
|
|
Points.DataBind(X)Y |
|
|
Points.DataBind |
|
|
Chart.DataBindCrossTab |
|
|
Chart.DataBindTable method
The Chart.DataBindTable method is the simplest way to bind chart to a table with several columns. New series will be automatically created for each of the columns and you can optionally use one column for the X value for all series.
Example
Imagine you have a data source containing these columns: Prod A, Prod B, Prod C, Prod D, Prod E, Other and SalesName, you can easily create chart below with a single line of code:
Chart1.DataBindTable(myReader, "SalesName");
PointProperty=Field[{Format}] [,PointProperty= Field[{Format}]].
A list of these properties are as follows: AxisLabel, Tooltip, Label, LegendText, LegendTooltipand CustomPropertyName (the name of a custom property). For more information on possible formats see the Formatting Types topic in the MSDN library.// Group by "Name" column, bind X values to "Year", Y values to "Sales", |
// and Label property to "Commissions. |
chart1.DataBindCrossTab(myReader, "Name", "Year", "Sales", "Label=Commissions"); |
PointProperty=FieldName[{Format}][,PointProperty= FieldName[{Format}]]
A list of these properties includes: AxisLabel, Tooltip, Label, LegendText, LegendTooltip andCustomPropertyName (the name of a custom property).// Initialize an array of doubles. |
double [] array = { 2.8, 4.4, 6.5, 8.3, 3.6, 5.6, 7.3, 9.2, 1.0}; |
// Bind the double array to the Y axis points of the data series. |
Chart1.Series["Series1"].Points.DataBindY(array); |
// Resolve the address to the Access database'Manual' series population
In case you need to perform some custom actions while binding and none of the above methods works, you can always 'manually' bind chart by iterating through the data source and add data points to the series as needed. This approach is also very useful when series data is calculated using some formula.
Example
// Resolve the address to the Access database string fileNameString = this.MapPath("."); fileNameString += "..\\..\\..\\data\\chartdata.mdb"; // Initialize a connection string string myConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileNameString; // Define the database query string mySelectQuery="SELECT * FROM SALESCOUNTS;"; // Create a database connection object using the connection string OleDbConnection myConnection = newOleDbConnection(myConnectionString); // Create a database command on the connection using query OleDbCommand myCommand = new OleDbCommand(mySelectQuery, myConnection); // Open the connection myCommand.Connection.Open(); // Initializes a new instance of the OleDbDataAdapter class OleDbDataAdapter myDataAdapter = new OleDbDataAdapter(); myDataAdapter.SelectCommand = myCommand; // Initializes a new instance of the DataSet class DataSet myDataSet = new DataSet(); // Adds rows in the DataSet myDataAdapter.Fill(myDataSet, "Query"); foreach(DataRow row in myDataSet.Tables["Query"].Rows) { // For each Row add a new series string seriesName = row["SalesRep"].ToString(); Chart1.Series.Add(seriesName); Chart1.Series[seriesName].ChartType = SeriesChartType.Line; Chart1.Series[seriesName].BorderWidth = 2; for(int colIndex = 1; colIndex < myDataSet.Tables["Query"].Columns.Count; colIndex++) { // For each column (column 1 and onward) add the value as a point string columnName = myDataSet.Tables["Query"].Columns[colIndex].ColumnName; int YVal = (int) row[columnName]; Chart1.Series[seriesName].Points.AddXY(columnName, YVal); } } DataGrid.DataSource = myDataSet; DataGrid.DataBind(); // Closes the connection to the data source. This is the preferred // method of closing any open connection. myCommand.Connection.Close();
To learn machine learning, you will need to acquire a combination of technical skills and domain knowledge. Here are some of the things yo...