ASP NET Chart Control sorting HD
Link for all dot net and sql server video tutorial playlists http://www.youtube.com/user/kudvenkat/playlists Link for slides, code samples and text version of the video http://csharp-video-tutorials.blogspot.com/2014/10/aspnet-chart-control-sorting.html In this video we will discuss ASP.NET Chart Control sorting. This is continuation to Part 8. Please watch Part 8 before proceeding. The end user should be able to sort chart data by StudentName and TotalMarks in ascending and descending order. To support this we want 2 DropDownLists on the WebForm1.aspx. One DropDownList will contain the fields to sort the data by i.e StudentName TotalMarks The other DropDownList will contain the sort direction i.e Ascending Descending Here is the HTML used in the demo [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="StudentName"][/asp:ListItem] [asp:ListItem Text="Total Marks" Value="TotalMarks"][/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] and the code for the code-behind file 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) { // Use the default sort - Sort by TotalMarks in Ascending order GetChartData(null); } } private void GetChartData(string sortExpression) { DataSet ds = new DataSet(); // Read the data from XML file into DataSet ds.ReadXml(Server.MapPath("~/Students.xml")); // Specify the column that contains values for X-AXIS Chart1.Series["Series1"].XValueMember = "StudentName"; // Specify the column that contains values for Y-AXIS Chart1.Series["Series1"].YValueMembers = "TotalMarks"; // Create the DataView DataView dataView = ds.Tables[0].DefaultView; // Specify how the data should be sor
Похожие видео
Показать еще