filmov
tv
Sorting ASP NET Chart Control using Sort method

Показать описание
Text version of the video
Healthy diet is very important both for the body and mind. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking our YouTube channel. Hope you can help.
Slides
All ASP .NET Chart Control Text Articles and Slides
ASP.NET Charts Playlist
All Dot Net and SQL Server Tutorials in English
All Dot Net and SQL Server Tutorials in Arabic
In this video we will discuss sorting ASP.NET chart control using Sort() method. This is continuation to Part 9. Please watch Part 9 before proceeding.
To use Sort() method
[table style="font-family: Arial; border: 1px solid black"]
[tr]
[td]
Sort By :
[asp:DropDownList ID="ddlSortBy" AutoPostBack="true" runat="server"
OnSelectedIndexChanged="ddlSortBy_SelectedIndexChanged"]
[asp:ListItem Text="Student Name" Value="AxisLabel"][/asp:ListItem]
[asp:ListItem Text="Total Marks" Value="Y"][/asp:ListItem]
[/asp:DropDownList]
[/td]
[td]
Sort Direction :
[asp:DropDownList ID="ddlSortDirection" AutoPostBack="true" runat="server"
OnSelectedIndexChanged="ddlSortDirection_SelectedIndexChanged"]
[asp:ListItem Text="Ascending" Value="ASC"][/asp:ListItem]
[asp:ListItem Text="Descending" Value="DESC"][/asp:ListItem]
[/asp:DropDownList]
[/td]
[/tr]
[tr]
[td colspan="2"]
[asp:Chart ID="Chart1" runat="server"]
[Series]
[asp:Series Name="Series1"]
[/asp:Series]
[/Series]
[ChartAreas]
[asp:ChartArea Name="ChartArea1"]
[/asp:ChartArea]
[/ChartAreas]
[/asp:Chart]
[/td]
[/tr]
[/table]
Step 2 : Modify the code in the code-behind file as shown below.
using System;
using System.Data;
namespace ChartsDemo
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GetChartData();
}
}
private void GetChartData()
{
DataSet ds = new DataSet();
Chart1.Series["Series1"].XValueMember = "StudentName";
Chart1.Series["Series1"].YValueMembers = "TotalMarks";
Chart1.DataSource = ds;
Chart1.DataBind();
// Sorting
if (ddlSortDirection.SelectedValue == "ASC")
{
Chart1.Series["Series1"].Sort(System.Web.UI.DataVisualization.Charting.PointSortOrder.Ascending, ddlSortBy.SelectedValue);
// OR
// Chart1.DataManipulator.Sort(System.Web.UI.DataVisualization.Charting.PointSortOrder.Ascending, ddlSortBy.SelectedValue, "Series1");
}
else
{
Chart1.Series["Series1"].Sort(System.Web.UI.DataVisualization.Charting.PointSortOrder.Descending, ddlSortBy.SelectedValue);
// OR
// Chart1.DataManipulator.Sort(System.Web.UI.DataVisualization.Charting.PointSortOrder.Descending, ddlSortBy.SelectedValue, "Series1");
}
}
protected void ddlSortBy_SelectedIndexChanged(object sender, EventArgs e)
{
GetChartData();
}
protected void ddlSortDirection_SelectedIndexChanged(object sender, EventArgs e)
{
GetChartData();
}
}
}
References :
Healthy diet is very important both for the body and mind. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking our YouTube channel. Hope you can help.
Slides
All ASP .NET Chart Control Text Articles and Slides
ASP.NET Charts Playlist
All Dot Net and SQL Server Tutorials in English
All Dot Net and SQL Server Tutorials in Arabic
In this video we will discuss sorting ASP.NET chart control using Sort() method. This is continuation to Part 9. Please watch Part 9 before proceeding.
To use Sort() method
[table style="font-family: Arial; border: 1px solid black"]
[tr]
[td]
Sort By :
[asp:DropDownList ID="ddlSortBy" AutoPostBack="true" runat="server"
OnSelectedIndexChanged="ddlSortBy_SelectedIndexChanged"]
[asp:ListItem Text="Student Name" Value="AxisLabel"][/asp:ListItem]
[asp:ListItem Text="Total Marks" Value="Y"][/asp:ListItem]
[/asp:DropDownList]
[/td]
[td]
Sort Direction :
[asp:DropDownList ID="ddlSortDirection" AutoPostBack="true" runat="server"
OnSelectedIndexChanged="ddlSortDirection_SelectedIndexChanged"]
[asp:ListItem Text="Ascending" Value="ASC"][/asp:ListItem]
[asp:ListItem Text="Descending" Value="DESC"][/asp:ListItem]
[/asp:DropDownList]
[/td]
[/tr]
[tr]
[td colspan="2"]
[asp:Chart ID="Chart1" runat="server"]
[Series]
[asp:Series Name="Series1"]
[/asp:Series]
[/Series]
[ChartAreas]
[asp:ChartArea Name="ChartArea1"]
[/asp:ChartArea]
[/ChartAreas]
[/asp:Chart]
[/td]
[/tr]
[/table]
Step 2 : Modify the code in the code-behind file as shown below.
using System;
using System.Data;
namespace ChartsDemo
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GetChartData();
}
}
private void GetChartData()
{
DataSet ds = new DataSet();
Chart1.Series["Series1"].XValueMember = "StudentName";
Chart1.Series["Series1"].YValueMembers = "TotalMarks";
Chart1.DataSource = ds;
Chart1.DataBind();
// Sorting
if (ddlSortDirection.SelectedValue == "ASC")
{
Chart1.Series["Series1"].Sort(System.Web.UI.DataVisualization.Charting.PointSortOrder.Ascending, ddlSortBy.SelectedValue);
// OR
// Chart1.DataManipulator.Sort(System.Web.UI.DataVisualization.Charting.PointSortOrder.Ascending, ddlSortBy.SelectedValue, "Series1");
}
else
{
Chart1.Series["Series1"].Sort(System.Web.UI.DataVisualization.Charting.PointSortOrder.Descending, ddlSortBy.SelectedValue);
// OR
// Chart1.DataManipulator.Sort(System.Web.UI.DataVisualization.Charting.PointSortOrder.Descending, ddlSortBy.SelectedValue, "Series1");
}
}
protected void ddlSortBy_SelectedIndexChanged(object sender, EventArgs e)
{
GetChartData();
}
protected void ddlSortDirection_SelectedIndexChanged(object sender, EventArgs e)
{
GetChartData();
}
}
}
References :
Комментарии