I have a pie chart that takes values from a datatable.
This is my code:
ASP.NET Code:
<asp:Chart ID="Chart1" runat="server" EnableViewState="True">
<Series>
<asp:Series ChartType="Pie" Legend="% Completed" Name="Series1" XAxisType="Secondary" XValueType="Double" YValueType="Double">
</asp:Series>
</Series>
<ChartAreas>
<asp:ChartArea BorderWidth="5" Name="ChartArea1">
<Area3DStyle Enable3D="True" WallWidth="15" />
</asp:ChartArea>
</ChartAreas>
<Legends>
<asp:Legend Name="% Completed" Title="% Completed">
</asp:Legend>
</Legends>
<Titles>
<asp:Title Name="Completed" Text="Completed">
</asp:Title>
<asp:Title Name="Title1">
</asp:Title>
</Titles>
</asp:Chart>
VB.NET Code:
Sets Session Variables for GetTable()
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load, Chart1.Load
Dim ProjectID As Integer = Session("project_id")
Session("ProjectID") = ProjectID
lblProjNameHeading.Text = "[ " + ProjectID.ToString + " ]"
Dim conn As New SqlConnection("Data Source=BRIAN-PC\SQLEXPRESS;Initial Catalog=master_db;Integrated Security=True")
Dim projComm As String = "SELECT project_id, project_start, project_finish, project_budget, project_cost FROM projects WHERE project_id=#parameter"
Dim projSQL As New SqlCommand
conn.Open()
projSQL = New SqlCommand(projComm, conn)
projSQL.Parameters.AddWithValue("#parameter", ProjectID.ToString)
Dim datareader As SqlDataReader = projSQL.ExecuteReader()
While datareader.Read
lblProjectCode.Text = datareader("project_id").ToString
lblProjectStart.Text = datareader("project_start").ToString
lblProjectStart2.Text = datareader("project_start").ToString
lblProjectEnd.Text = datareader("project_finish").ToString
lblProjectEnd2.Text = datareader("project_finish").ToString
lblProjectBudget.Text = datareader("project_budget").ToString
lblProjectBudget2.Text = datareader("project_budget").ToString
lblProjectCost.Text = datareader("project_cost").ToString
lblProjectCost2.Text = datareader("project_cost").ToString
' lblProjectLeader.Text = datareader("project_cost").ToString
'lblProjectExpenditures.Text = agdgssag
Dim StartDate As DateTime = datareader("project_start")
Dim FinishDate As DateTime = datareader("project_finish")
Dim today As DateTime = DateTime.Now
Dim sumDays = (FinishDate - StartDate).TotalDays
Dim daysToNow = (today - StartDate).TotalDays
Dim percentage = daysToNow / sumDays * 100
Dim percentageLeft = 100 - percentage
Session("PercentageCompleted") = percentage
Session("PercentageLeft") = percentageLeft
GetTable()
lblProjectPercentage.Text = percentage.ToString("N2") + "%"
End While
datareader.Close()
conn.Close()
If Not Page.IsPostBack Then
BindData()
End If
End Sub
The Problem is that when I run the code, the pie chart is not displayed.
Can someone tell me what's wrong?
I think the issue is you haven't set the XvalueMember and YvalueMember for the chart.
<Series>
<asp:Series ChartType="Pie" Legend="% Completed" Name="Series1" XAxisType="Secondary" XValueType="Double" YValueType="Double" XValueMember="yourXValue" YValueMember="YourYvalue">
</asp:Series>
</Series>
Check out the below example.
http://itzonesl.blogspot.com/search/label/Charts
Related
I'm trying to export data however it only extract the data in current paging. And I need to go to another paging to download another. Is there any where to download all data in the source?
Below is my aspx code:
<asp:datagrid id="dgAmount" Visible=false runat="server" CssClass="item01Nxx08" Width="100%" CellPadding="3"
BorderColor="#DEDFDE" BorderStyle="None" PageSize="50" AutoGenerateColumns="False" AllowSorting="True"
AllowPaging="True" BackColor="White" BorderWidth="1px" GridLines="Vertical" ForeColor="Black">
<asp:BoundColumn DataField="No" SortExpression="No" HeaderText="No" visible="False"></asp:BoundColumn>
<asp:BoundColumn DataField="Action" SortExpression="Action" HeaderText="Action"></asp:BoundColumn>
<asp:BoundColumn DataField="AppName" SortExpression="AppName" HeaderText="Approver Name"></asp:BoundColumn>
<asp:BoundColumn DataField="MIAmount" SortExpression="MIAmount" HeaderText="MI Amount"></asp:BoundColumn>
<asp:BoundColumn DataField="By" SortExpression="By" HeaderText="By">
</asp:BoundColumn>
<asp:BoundColumn DataField="Date" SortExpression="Date" HeaderText="Date">
</asp:BoundColumn>
</asp:DataGrid>
And below is my vb code:
System.Web.HttpContext.Current.Response.Clear()
System.Web.HttpContext.Current.Response.Buffer = True
System.Web.HttpContext.Current.Response.AddHeader("Content-Disposition", "filename=" & fileName & ".xls;")
System.Web.HttpContext.Current.Response.ContentType = "application/vnd.ms-excel"
System.Web.HttpContext.Current.Response.Charset = ""
'set the response mime type for excel
'create a string writer
Dim stringWrite As System.IO.StringWriter = New System.IO.StringWriter
'create an htmltextwriter which uses the stringwriter
Dim htmlWrite As System.Web.UI.HtmlTextWriter = New System.Web.UI.HtmlTextWriter(stringWrite)
htmlWrite.WriteLine("<b><u>" & header & "</u></b><br /><br />")
'instantiate a datagrid
Dim dg As New DataGrid()
Dim dt As New DataTable, dr As DataRow
dt.Columns.Add(New DataColumn("No", GetType(Integer)))
dt.Columns.Add(New DataColumn("Action", GetType(String)))
dt.Columns.Add(New DataColumn("Approver Name", GetType(String)))
dt.Columns.Add(New DataColumn("MI Amount", GetType(String)))
dt.Columns.Add(New DataColumn("By", GetType(String)))
dt.Columns.Add(New DataColumn("Date", GetType(String)))
Dim tempDg As DataGrid = dgAmount
For Each item As DataGridItem In tempDg.Items
dr = dt.NewRow()
dr("No") = item.Cells(0).Text
dr("Action") = item.Cells(1).Text
dr("Approver Name") = item.Cells(2).Text
dr("MI Amount") = item.Cells(3).Text
dr("By") = item.Cells(4).Text
dr("Date") = item.Cells(5).Text
dt.Rows.Add(dr)
Next
dg.DataSource = dt
dg.DataBind()
dg.EnableViewState = False
dg.GridLines = GridLines.None
dg.HeaderStyle.Font.Name = "Verdana"
dg.HeaderStyle.Font.Size = 8
dg.HeaderStyle.Font.Bold = True
dg.HeaderStyle.HorizontalAlign = HorizontalAlign.Center
dg.HeaderStyle.ForeColor = Drawing.Color.White
dg.HeaderStyle.BackColor = Drawing.Color.Black
dg.ItemStyle.Font.Name = "Verdana"
dg.ItemStyle.Font.Size = 8
dg.ItemStyle.VerticalAlign = VerticalAlign.Top
'bind the modified datagrid
'tell the datagrid to render itself to our htmltextwriter
dg.RenderControl(htmlWrite)
'output the html
System.Web.HttpContext.Current.Response.Write(stringWrite.ToString)
System.Web.HttpContext.Current.Response.End()
System.Web.HttpContext.Current.Response.Redirect("")
Turn Paging off before bind/export. grid.AllowPaging = false;
i have successfully been able to calculate a monthly depreciable amount of an asset using straight line formula
I'm having issues using the doubline balance line formular as I'm not getting my expected result
formula = (2* depreciation ) / lifeMonth
below is my backend code
Dim acquiredDate As DateTime = Convert.ToDateTime(2019, 11, 15)
Dim startMonth As DateTime = Convert.ToDateTime(2019, 11, 15)
Dim depreciation As Double = "10000"
Dim slavege As Double = "10"
Dim lifeMonth As Integer = "12"
Dim dt As DataTable = New DataTable()
dt.Columns.Add("Month")
dt.Columns.Add("Depreciation", GetType(Decimal))
dt.Columns.Add("Accumulated", GetType(Decimal))
dt.Columns.Add("BookValue", GetType(Decimal))
Dim i As Integer = 0
Dim depreciationExpense As Double = (2 * depreciation) / lifeMonth
Dim bookValue As Double = depreciation - depreciationExpense
Dim newDepreciationExpense As Double = 0
While startMonth < acquiredDate.AddMonths(lifeMonth)
Dim dr As DataRow = dt.NewRow()
dr("Month") = startMonth.ToString("MMM yyyy")
dr("Depreciation") = depreciationExpense
If i = 0 Then
dr("Accumulated") = Math.Round(depreciationExpense, 2)
dr("BookValue") = Math.Round(bookValue, 2)
newDepreciationExpense = depreciationExpense
Else
newDepreciationExpense = newDepreciationExpense + depreciationExpense
bookValue = bookValue - depreciationExpense
dr("Accumulated") = Math.Round(newDepreciationExpense, 2)
dr("BookValue") = Math.Round(bookValue, 2)
End If
dt.Rows.Add(dr)
startMonth = startMonth.AddMonths(1)
i += 1
End While
Me.gvData.DataSource = dt
Me.gvData.DataBind()
below is my front end(html)
<asp:GridView runat="server" ID="gvData" AutoGenerateColumns="false" CssClass="table table-bordered table-striped table-depreciation">
<Columns>
<asp:BoundField DataField="Month" HeaderText="Month" />
<asp:BoundField DataField="Depreciation" HeaderText="Depriciation Expenses" DataFormatString="{0:N2}" />
<asp:BoundField DataField="Accumulated" HeaderText="Accumulate Deprication at Month-End" DataFormatString="{0:N2}" />
<asp:BoundField DataField="BookValue" HeaderText="Book Value at Month-End" DataFormatString="{0:N2}" />
</Columns>
</asp:GridView>
the result I'm getting
my expected result
I have a drop down list that I am populating from the code behind and I have a Gridview control below the drop down list that I am also populating from code behind. My goal is to select a department from the drop down list and populate the Gridview control will all employees in that department
This is my code to populate my Gridview control:
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
LoadDataGrid()
FillWithDepartments()
End If
End Sub
Private Sub LoadDataGrid()
Try
Using conn As New SqlConnection(ConfigurationManager.ConnectionStrings("###").ConnectionString)
Using cmd As New SqlCommand("SELECT Departments.ShortDescription AS [Department] , CostCentre AS [Cost Centre] , FirstName AS [Name] , LastName AS [Surname] , MedicalResults.EmployeeID AS [ID No] , EmployeeCodes.Code AS [Clock No] ,MedicalResults.[DateTested] AS [Date Tested] , MedicalResults.[NextDueDate] AS [Next Due Date] , MedicalResults.ECGDate AS [ECG] , MedicalResults.LungFunctionDate AS [Lungfunction] , MedicalResults.AudioGramDate AS [Hearing Test] , MedicalResults.EyeTestDate AS [Eye Test] , OtherProblems AS [Other Problems] , Notes FROM MedicalResults, EmployeeCodes , EmployeevsPositionLink , PositionCodes , Departments WHERE MedicalResults.ID = EmployeeCodes.ID AND EmployeevsPositionLink.EmployeeID = EmployeeCodes.ID AND EmployeevsPositionLink.PositionID = PositionCodes.ID AND PositionCodes.DepartmentCode = Departments.Code AND EmployeeCodes.TerminationDate Is Null AND EmployeevsPositionLink.PositionNumber = '1' AND MedicalResults.EmployeeID = EmployeeCodes.EmployeeID Order By DateTested DESC", conn)
Dim sda As New SqlDataAdapter(cmd)
Dim dt As New DataTable()
sda.Fill(dt)
GridView1.DataSource = dt
GridView1.DataBind()
End Using
End Using
Catch ex As Exception
End Try
End Sub
This is the code to populate my drop down list from code behind:
Protected Sub FillWithDepartments()
Using conn As New SqlConnection(ConfigurationManager.ConnectionStrings("###").ConnectionString)
'conn.Open()
Dim cmd As New SqlCommand("SELECT Code , ShortDescription FROM Departments", conn)
Dim adapter As New SqlDataAdapter(cmd)
Dim tbl As New DataTable()
adapter.Fill(tbl)
drplstDepartment.DataSource = tbl
drplstDepartment.DataTextField = "ShortDescription"
drplstDepartment.DataValueField = "Code"
drplstDepartment.DataBind()
' conn.Close()
End Using
End Sub
Front End Code for Drop Down List
<asp:DropDownList ID="drplstDepartment" OnSelectedIndexChanged="drplstDepartment_SelectedIndexChanged" CssClass="form-control mb-2 mr-sm-2" runat="server" AutoPostBack="true">
</asp:DropDownList>
Front End Code Fro Grid View
<asp:GridView RowStyle-CssClass="text-center" OnPageIndexChanging="GridView1_PageIndexChanging" OnSelectedIndexChanging="GridView1_SelectedIndexChanging" AllowPaging="true" class="table table-default table-striped table-bordered table-condensed table-responsive table-hover" border="1" ID="GridView1" runat="server" HeaderStyle-HorizontalAlign="Center" HeaderStyle-VerticalAlign="Middle" HeaderStyle-BackColor="#6C6C6C" HeaderStyle-ForeColor="White" RowStyle-BackColor="#eeeeee" AlternatingRowStyle-BackColor="White" AlternatingRowStyle-ForeColor="#000" RowStyle-ForeColor="#000" AutoGenerateColumns="false" >
<Columns>
<asp:ButtonField ItemStyle-Width = "150px" DataTextField= "Department" HeaderText = "Department"/>
<asp:ButtonField ItemStyle-Width = "150px" DataTextField= "Cost Centre" HeaderText = "Cost Centre"/>
<asp:ButtonField ItemStyle-Width = "150px" DataTextField= "Name" HeaderText = "Name" />
<asp:ButtonField ItemStyle-Width = "150px" DataTextField= "Surname" HeaderText = "Surname"/>
<asp:ButtonField ItemStyle-Width = "150px" DataTextField= "ID No" HeaderText = "ID No"/>
<asp:ButtonField ItemStyle-Width = "150px" DataTextField= "Clock No" HeaderText = "Clock No"/>
<asp:ButtonField ItemStyle-Width = "150px" DataTextFormatString="{0:dd/MM/yyyy}" DataTextField= "Date Tested" HeaderText = "Date Tested"/>
<asp:ButtonField ItemStyle-Width = "150px" DataTextFormatString="{0:dd/MM/yyyy}" DataTextField= "Next Due Date" HeaderText = "Next Due Date"/>
<asp:ButtonField ItemStyle-Width = "150px" DataTextFormatString="{0:dd/MM/yyyy}" DataTextField= "ECG" HeaderText = "ECG"/>
<asp:ButtonField ItemStyle-Width = "150px" DataTextFormatString="{0:dd/MM/yyyy}" DataTextField= "Lungfunction" HeaderText = "Lungfunction"/>
<asp:ButtonField ItemStyle-Width = "150px" DataTextFormatString="{0:dd/MM/yyyy}" DataTextField= "Hearing Test" HeaderText = "Hearing Test"/>
<asp:ButtonField ItemStyle-Width = "150px" DataTextFormatString="{0:dd/MM/yyyy}" DataTextField= "Eye Test" HeaderText = "Eye Test"/>
<asp:ButtonField ItemStyle-Width = "150px" DataTextField= "Other Problems" HeaderText = "Other Problems"/>
<asp:ButtonField ItemStyle-Width = "150px" DataTextField= "Notes" HeaderText = "Notes"/>
</Columns>
</asp:GridView>
This is the code that is not firing
Protected Sub drplstDepartment_SelectedIndexChanged(sender As Object, e As EventArgs)
Dim dt As DataTable = New DataTable()
Using conn As New SqlConnection(ConfigurationManager.ConnectionStrings("#").ToString())
Dim cmd As New SqlCommand("SELECT Departments.ShortDescription AS [Department] , CostCentre AS [ Cost Centre] , FirstName AS [Name] , LastName AS [Surname] , MedicalResults.EmployeeID AS [ID No] , EmployeeCodes.Code AS [Clock No] ,CONVERT(nvarchar(10), MedicalResults.[DateTested], 101) AS [Date Tested] ,CONVERT(nvarchar(10), MedicalResults.[NextDueDate], 101) AS [Next Due Date] , CONVERT(nvarchar(10), MedicalResults.ECGDate, 101) AS [ECG] , CONVERT(nvarchar(10), MedicalResults.LungFunctionDate, 101) AS [Lungfunction] , CONVERT(nvarchar(10), MedicalResults.AudioGramDate, 101) AS [Hearing Test] , CONVERT(nvarchar(10), MedicalResults.EyeTestDate, 101) AS [Eye Test] , OtherProblems AS [Other Problems] , Notes FROM MedicalResults, EmployeeCodes , EmployeevsPositionLink , PositionCodes , Departments WHERE MedicalResults.ID = EmployeeCodes.ID AND EmployeevsPositionLink.EmployeeID = EmployeeCodes.ID AND EmployeevsPositionLink.PositionID = PositionCodes.ID AND PositionCodes.DepartmentCode = Departments.Code AND EmployeeCodes.TerminationDate Is Null AND EmployeevsPositionLink.PositionNumber = '1' AND MedicalResults.EmployeeID = EmployeeCodes.EmployeeID AND (Departments.ShortDescription = #ShortDescription)", conn)
cmd.Parameters.AddWithValue("#ShortDescription", drplstDepartment.SelectedValue)
Dim da As New SqlDataAdapter(cmd)
da.Fill(dt)
GridView1.DataSource = dt
GridView1.DataBind()
End Using
End Sub
Try this instead in your drplstDepartment_SelectedIndexChanged event:
Dim cmd As New SqlCommand("SELECT
...
FROM
...
WHERE
...
AND (Departments.Code = #Code)", conn)
cmd.Parameters.AddWithValue("#Code", drplstDepartment.SelectedItem.Value)
#Code matches drplstDepartment.SelectedItem.Value, #ShortDescription matches drplstDepartment.SelectedItem.Text.
I am trying to use a pie chart and I expect 2 regions get displayed on it. But for my following code, only the last one is shown.
Code behind:
protected void Page_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.Add("status");
dt.Columns.Add("count");
DataRow dr = dt.NewRow();
dr["status"] = "safe";
dr["count"] = loadChart("safe");
dt.Rows.Add(dr);
dr["status"] = "unsafe";
dr["count"] = loadChart("unsafe");
dr = dt.NewRow();
dt.Rows.Add(dr);
Chart1.DataSource = dt;
Chart1.Series[0].XValueMember = "status";
Chart1.Series[0].YValueMembers = "count";
Chart1.DataBind();
}
Mark up:
<asp:Chart ID="Chart1" runat="server">
<series>
<asp:Series ChartType="Pie" Name="Series1">
</asp:Series>
</series>
<chartareas>
<asp:ChartArea Name="ChartArea1">
</asp:ChartArea>
</chartareas>
</asp:Chart>
output:
I want to see the safe portion also. I have value for it.how to resolve this issue ?
You are setting values in the same row twice:
DataRow dr = dt.NewRow();
dr["status"] = "safe";
dr["count"] = loadChart("safe");
dt.Rows.Add(dr);
//still in the same row
dr["status"] = "unsafe";
dr["count"] = loadChart("unsafe");
dr = dt.NewRow();
dt.Rows.Add(dr);
you should create new row and then set second values:
DataRow dr = dt.NewRow();
dr["status"] = "safe";
dr["count"] = loadChart("safe");
dt.Rows.Add(dr);
//new row creation
dr = dt.NewRow();
dr["status"] = "unsafe";
dr["count"] = loadChart("unsafe");
dt.Rows.Add(dr);
Here is the code:
<%# Page Language="VB" %>
<%# Import Namespace="System.Data" %>
<%# Import Namespace="System.Data.SqlClient" %>
<script runat="server">
Dim SQLConn As SqlConnection = New SqlConnection()
Dim strSQL As String
Dim strFilter As String
Dim objCmd
Dim objReader As SqlDataReader
Dim DBComm As SqlCommand
Dim DBAdapt As SqlDataAdapter
Sub DBConnect
SQLConn.ConnectionString = ConfigurationSettings.AppSettings("CString")
SQLConn.Open()
End Sub
Sub DBDisconnect
SQLConn.close()
End Sub
Sub Page_Load
Dim ThisFilter As Object = ViewState("vsFilter")
If Not (ThisFilter Is Nothing) Then
strFilter = CStr(ThisFilter)
Else
strFilter = "All"
End If
If Not Page.IsPostBack Then
BindData(True)
End If
End Sub
Sub BindData(ByVal GetFresh As Boolean)
Call DBConnect()
Dim DTable As DataTable = Nothing
If ViewState("vsSortData") Is Nothing Or GetFresh Then
If Session("Agency_Name") = "Main Company" Then
strSQL = "SELECT LOGIN.Login_ID, LOGIN.Login_Last_Name + ', ' + LOGIN.Login_First_Name + ' ' + CASE WHEN Login_Middle_Name IS NULL THEN '' ELSE CONVERT(varchar, Login_Middle_Name) END AS FullName, AGENCY.Agency_Name, '(' + Substring(Login_Phone, 0, 4) + ') ' + Substring(Login_Phone, 4, 3) + '-' + Substring(Login_Phone, 7, 4) as Phone, LOGIN.Login_Email, CASE WHEN Login_Type = 'U' THEN 'User' WHEN Login_Type = 'I' THEN 'ISC' ELSE CONVERT(varchar, Login_Type) END AS LoginType, CASE WHEN Login_Account_Active = 'T' THEN 'Yes' WHEN Login_Account_Active = 'F' THEN 'No' ELSE CONVERT(varchar, Login_Account_Active) END AS AcctActive FROM LOGIN INNER JOIN AGENCY ON LOGIN.Login_Agency_ID = AGENCY.Agency_ID WHERE LOGIN.Login_Deleted = 'F'"
Else
strSQL = "SELECT LOGIN.Login_ID, LOGIN.Login_Last_Name + ', ' + LOGIN.Login_First_Name + ' ' + CASE WHEN Login_Middle_Name IS NULL THEN '' ELSE CONVERT(varchar, Login_Middle_Name) END AS FullName, AGENCY.Agency_Name, '(' + Substring(Login_Phone, 0, 4) + ') ' + Substring(Login_Phone, 4, 3) + '-' + Substring(Login_Phone, 7, 4) as Phone, LOGIN.Login_Email, CASE WHEN Login_Type = 'U' THEN 'User' WHEN Login_Type = 'I' THEN 'ISC' ELSE CONVERT(varchar, Login_Type) END AS LoginType, CASE WHEN Login_Account_Active = 'T' THEN 'Yes' WHEN Login_Account_Active = 'F' THEN 'No' ELSE CONVERT(varchar, Login_Account_Active) END AS AcctActive FROM LOGIN INNER JOIN AGENCY ON LOGIN.Login_Agency_ID = AGENCY.Agency_ID WHERE LOGIN.Login_Deleted = 'F' AND AGENCY.Agency_Name='" & Session("Agency_Name") & "'"
End If
DBComm = New SqlCommand(strSQL, SQLConn)
DBAdapt = New SqlDataAdapter(DBComm)
Dim DSet As New DataSet()
Try
DBAdapt.Fill(DSet)
DTable = DSet.Tables(0)
Catch EXC As SqlException
Me.lblMsg2.Text = EXC.Message
Return
Finally
SQLConn.Close()
End Try
ViewState("vsSortData") = DTable
Else
DTable = CType(ViewState("vsSortData"), DataTable)
End If
If strFilter = "All" Then
DTable.DefaultView.RowFilter = String.Empty
Else
DTable.DefaultView.RowFilter = "FullName LIKE '" & strFilter & "%'"
End If
Me.datagrid.DataSource = DTable.DefaultView
Me.datagrid.DataBind()
BuildAlphaPager()
Call DBDisconnect()
End Sub
Sub BuildAlphaPager()
Dim DTable As DataTable
If ViewState(("strLetter")) Is Nothing Then
Dim arrLetters As String() = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "All"}
DTable = New DataTable()
DTable.Columns.Add(New DataColumn("Letter", GetType(String)))
Dim i As Integer
For i = 0 To arrLetters.Length - 1
Dim DRow As DataRow = DTable.NewRow()
DRow(0) = arrLetters(i)
DTable.Rows.Add(DRow)
Next i
ViewState("strLetter") = DTable
Else
DTable = CType(ViewState("strLetter"), DataTable)
End If
Me.rptLetters.DataSource = DTable.DefaultView
Me.rptLetters.DataBind()
End Sub
Protected Sub rptLetters_ItemDataBound(ByVal sender As Object, ByVal e As RepeaterItemEventArgs)
If (e.Item.ItemType = ListItemType.Header) Then
ElseIf (e.Item.ItemType = ListItemType.Item) Or (e.Item.ItemType = ListItemType.AlternatingItem) Then
Dim lnkAlpha As LinkButton = CType(e.Item.FindControl("lnkAlpha"), LinkButton)
lnkAlpha.Text = DataBinder.Eval(e.Item.DataItem, "Letter")
lnkAlpha.CommandName = "Filter"
lnkAlpha.CommandArgument = DataBinder.Eval(e.Item.DataItem, "Letter")
Dim DRView As DataRowView = CType(e.Item.DataItem, DataRowView)
If CStr(DRView(0)) = strFilter Then
lnkAlpha.Enabled = False
End If
ElseIf (e.Item.ItemType = ListItemType.Footer) Then
End If
End Sub
Protected Sub rptLetters_ItemCommand(ByVal source As Object, ByVal e As RepeaterCommandEventArgs)
If e.CommandName = "Filter" Then
strFilter = CStr(e.CommandArgument)
ViewState("vsFilter") = strFilter
BindData(False)
End If
End Sub
</script>
<html>
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form runat="server">
<font size="1" color="#FF0000"><strong><asp:label id="lblMsg2" runat="server" /></strong></font>
<div align="center"><h3>
<asp:Repeater ID="rptLetters" runat="server" OnItemDataBound="rptLetters_ItemDataBound" OnItemCommand="rptLetters_ItemCommand">
<ItemTemplate>
<asp:LinkButton ID="lnkAlpha" runat="server" />
</ItemTemplate>
</asp:Repeater>
</h3></div>
<asp:DataGrid ID="datagrid" runat="server" AutoGenerateColumns="False" AllowSorting="true" width="725px" BackColor="Gray" BorderWidth="0" BorderStyle="None" BorderColor="#DEBA84" Font-Size="XX-Small" CellPadding="3" CellSpacing="1">
<HeaderStyle font-size="XX-Small" font-names="Verdana" font-bold="True" horizontalalign="Center" forecolor="White" bordercolor="White" backcolor="#1E3769" />
<AlternatingItemStyle BackColor = "Gray" CssClass = "row" />
<ItemStyle CssClass = "row" />
<Columns>
<asp:TemplateColumn ItemStyle-Width="200px" ItemStyle-HorizontalAlign="center" HeaderText="Full Name" SortExpression="Login_Last_Name">
<ItemTemplate> <a style="color: #000000;" href="mailto:<%# Container.DataItem("Login_Email")%>">
<%# Container.DataItem("FullName")%> </a> </ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn ItemStyle-Width="160px" ItemStyle-HorizontalAlign="center" DataField="Agency_Name" HeaderText="Agency Name" SortExpression="Agency_Name"></asp:BoundColumn>
<asp:BoundColumn ItemStyle-Width="110px" ItemStyle-HorizontalAlign="center" DataField="Phone" HeaderText="Phone Number" SortExpression="Login_Phone"></asp:BoundColumn>
<asp:BoundColumn ItemStyle-Width="80px" ItemStyle-HorizontalAlign="center" DataField="LoginType" HeaderText="User Type" SortExpression="Login_Type"></asp:BoundColumn>
<asp:BoundColumn ItemStyle-Width="115px" ItemStyle-HorizontalAlign="center" DataField="AcctActive" HeaderText="Account Active" SortExpression="Login_Account_Active"></asp:BoundColumn>
<asp:TemplateColumn ItemStyle-Width="40px" ItemStyle-HorizontalAlign="center" HeaderText="Details">
<ItemTemplate>
<a style="color: #000000;" href="javascript:openDetail('userDetail.aspx?id=<%# Container.DataItem("Login_ID")%>');">
Details </a> </ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn ItemStyle-Width="25px" ItemStyle-HorizontalAlign="center" HeaderText="Edit">
<ItemTemplate> <a style="color: #000000;" href="edAccounts.aspx?f=e&id=<%# Container.DataItem("Login_ID")%>">
Edit </a> </ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
</form>
</body>
</html>
I just want the Full Name column (first column, FullName) to be in alphabetical order by default, and then if they click on a specific column then that column should arrange itself alphabetically. This used to work until I applied the above solution to paginate based on the letter in the name.
I have tried modifying the SQL queries and including "ORDER BY FullName" and "ORDER BY LOGIN.Login_Last_Name" and many other things but can't seem to get it to order by this by default, nor does any other column sort when clicked on as should occur. Somehow the alphabetic pagination is not allowing these fields to be sorted any further.
This is ASP.NET 2.0 with VB. Help?
I recommend this example and i as a personal note I would recommend using the example with the ObjectDataSource as it allows you to separate your presentation layer (pages) prom your data access layer (classes that execute sql and retrieve the data)