Simple Datagrid sort problem

N

Nithin

Hi all,
I am trying to sort columns in a datagrid. I have a page with a
calendar control and a button that invokes btnGetReport_Click.
I am able to retrieve data in a datagrid but I am unable to sort on
the column headers. Whenever I click the column header it displays
nothing. Am I having a postback problem or
something else. I did look into a few examples on quickstart tutorial
but not of much use to me. Any help will be appreciated. Thanks.

---------------------------------------------------------------------------------------------------------------------------------------------

' This porogram uses Stored Procedures
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration

Public Class reportcal4
Inherits System.Web.UI.Page
Dim MyConnection As New
SqlConnection("server=(local)\NetSDK;database=Northwind;Integrated
Security=SSPI")

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub

Private Sub btnGetReport_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles btnGetReport.Click
BindGrid("BCF")
End Sub

Sub MyDataGrid_Sort(ByVal Sender As Object, ByVal E As
DataGridSortCommandEventArgs)
BindGrid(E.SortExpression)
End Sub

Sub BindGrid(ByVal SortField As String)
Dim DS As DataSet
Dim MyCommand As SqlDataAdapter
Dim strSQL As String = "SELECT Date, [Site ID], Market, BSC,
BCF, [Upgrade Type], [Site Engineer], Status, Completed " & _
" FROM Tracker " & _
"WHERE Tracker.Date Between @Beginning_Date
And @Ending_Date"

MyCommand = New SqlDataAdapter(strSQL, MyConnection)
MyCommand.SelectCommand.Parameters.Add(New
SqlParameter("@Beginning_Date", SqlDbType.DateTime))
MyCommand.SelectCommand.Parameters("@Beginning_Date").Value =
BeginDate.SelectedDate

MyCommand.SelectCommand.Parameters.Add(New
SqlParameter("@Ending_Date", SqlDbType.DateTime))
MyCommand.SelectCommand.Parameters("@Ending_Date").Value =
EndDate.SelectedDate

DS = New DataSet
MyCommand.Fill(DS, "Site Report")
MyDataGrid.DataSource = DS.Tables("Site Report").DefaultView
MyDataGrid.DataBind()

End Sub

End Class

---------------------------------------------------------------------------------------------------------------------------------------------

<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="reportcal4.aspx.vb" Inherits="workalloc.reportcal4"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>calreport</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
</HEAD>
<body>
<form id="Form1" runat="server">
<h3><font face="Verdana">Site Report by Date Range</font></h3>
<table borderColor="#cccccc" width="700" border="1">
<tr>
<td vAlign="top"><b>Start Date </b>
<ASP:CALENDAR id="BeginDate" runat="server" BorderWidth="2"
BorderColor="lightblue" Font-Size="8pt"
TitleStyle-Font-Size="8pt" TitleStyle-BackColor="#cceecc"
DayHeaderStyle-BackColor="#ddffdd"
DayHeaderStyle-Font-Size="10pt"
WeekendDayStyle-BackColor="#ffffcc" SelectedDate="2003-12-01"
VisibleDate="2003-12-01"
SelectedDayStyle-BackColor="lightblue">
<DayHeaderStyle Font-Size="10pt"
BackColor="#DDFFDD"></DayHeaderStyle>
<SelectedDayStyle BackColor="LightBlue"></SelectedDayStyle>
<TitleStyle Font-Size="8pt" BackColor="#CCEECC"></TitleStyle>
<WeekendDayStyle BackColor="#FFFFCC"></WeekendDayStyle>
</ASP:CALENDAR></td>
<td vAlign="top"><b>End Date</b>
<ASP:CALENDAR id="EndDate" runat="server" BorderWidth="2"
BorderColor="lightblue" Font-Size="8pt"
TitleStyle-Font-Size="8pt" TitleStyle-BackColor="#cceecc"
DayHeaderStyle-BackColor="#ddffdd"
DayHeaderStyle-Font-Size="10pt"
WeekendDayStyle-BackColor="#ffffcc" SelectedDate="2004-01-01"
VisibleDate="2004-01-01"
SelectedDayStyle-BackColor="lightblue">
<DayHeaderStyle Font-Size="10pt"
BackColor="#DDFFDD"></DayHeaderStyle>
<SelectedDayStyle BackColor="LightBlue"></SelectedDayStyle>
<TitleStyle Font-Size="8pt" BackColor="#CCEECC"></TitleStyle>
<WeekendDayStyle BackColor="#FFFFCC"></WeekendDayStyle>
</ASP:CALENDAR></td>
<td style="PADDING-TOP: 20px" vAlign="top">
<p><asp:button id="btnGetReport" runat="server" Text="Get
Report"></asp:button></p>
</td>
</tr>
<tr>
<td style="PADDING-TOP: 20px" colSpan="3"><ASP:DATAGRID
id="MyDataGrid" runat="server" OnSortCommand="MyDataGrid_Sort"
BorderWidth="1px"
BorderColor="#999999" Font-Size="8pt" Font-Names="Verdana"
GridLines="Vertical" BorderStyle="None" Height="156px" Width="674px"
BackColor="White" CellPadding="3" Font-Name="Verdana"
HeaderStyle-BackColor="#aaaadd" EnableViewState="False"
AllowSorting="True">
<SelectedItemStyle Font-Bold="True" ForeColor="White"
BackColor="#008A8C"></SelectedItemStyle>
<AlternatingItemStyle
BackColor="Gainsboro"></AlternatingItemStyle>
<ItemStyle ForeColor="Black" BackColor="#EEEEEE"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="White"
BackColor="#000084"></HeaderStyle>
<FooterStyle ForeColor="Black"
BackColor="#CCCCCC"></FooterStyle>
<PagerStyle HorizontalAlign="Center" ForeColor="Black"
BackColor="#999999" Mode="NumericPages"></PagerStyle>
</ASP:DATAGRID></td>
</tr>
</table>
</form>
</body>
</HTML>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,071
Latest member
MetabolicSolutionsKeto

Latest Threads

Top