Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > How to bring paging, sorting and hyperlinking functioanlities in a datagrid?

Reply
Thread Tools

How to bring paging, sorting and hyperlinking functioanlities in a datagrid?

 
 
Crazy Learner
Guest
Posts: n/a
 
      07-22-2003
Hi there,
I just started asp.net code 3 days ago from now.
I have a situation in one of my pages that i need to provide all three
functionailities paging, sorting all of the columns and hyperlinking of
the two columns in the datagrid. I am very glad that
i could page and sort and enjoyed the result.
inorder to hyperlink couple of columns in the
datagrid i made AutoGenerateColumns="False"
(if i don't set this value "False" the datagrid displaying duplicate
columns) and used
<asp:hyperlinkcolumn> to the column i want
hyperlink and <asp:boundcolumn> for the rest of the
columns to display them asusual in the datagrid. I
am able to hyperlink the mentioned columns in the
order i wanted to and also able to page the results now.
But unfortunately i lost sorting functionality. Now i
am only able to page and hyperlink but not sorting.
Hope you got where i am strucking at. Please help me
to get out of this problem.thanks much and appreciate
your encouragement for the new programers thanks
once again. I am pasting my Html and code behind pages
underneath. i am just using customers table in
northwind database in sqlserver 2000.
*************** Html part of the.aspx***************

<%@ Register TagPrefix="mbrsc"
Namespace="MetaBuilders.WebControls"
Assembly="MetaBuilders.WebControls.RowSelectorColu mn"
%>
<%@ Page Language="vb" Src="project_listing.aspx.vb"
Inherits="project_listing" %>
<html>
<head>
<title>Paging and Sorting in a DataGrid</title>
<meta name="GENERATOR" content="Microsoft Visual
Studio.NET 7.0">
<meta name="CODE_LANGUAGE" content="Visual Basic
7.0">
<meta name=vs_defaultClientScript
content="JavaScript">
<meta name=vs_targetSchema

content="http://schemas.microsoft.com/intellisense/ie5"
</head>
<body>
<h3 align=center><font face="Verdana">Project
Listing</font></h3>
<form runat="server">

<table>
<tr><td>
<asp:radiobutton id="Radiobutton1" runat="server"
groupname="projectselection"></asp:radiobutton>My
</td>
<td>Projects
<asp:radiobutton id="Radiobutton2" runat="server"
groupname="projectselection"></asp:radiobutton>Shared
</td>
<td>Projects
<asp:radiobutton id="Radiobutton3" runat="server"
groupname="projectselection"
checked="true"></asp:radiobutton>All</td>
</table>
<p></p>
<P></P>
<asp:Label id="lblOrderBy" runat="server"
Visible="False" />
<aspataGrid id="dtgCusts"
align="center"
AllowPaging="True"

OnPageIndexChanged="PageIndexChanged_Click"
PageSize="10"
PagerStyle-Mode="NumericPages"
PagerStyle-Position="Top"
PagerStyle-HorizontalAlign="Center"
PagerStyle-CssClass="pageLinks"
AutoGenerateColumns="False"
AllowSorting="True"
OnSortCommand="SortCommand_Click"

runat="server">
<Columns>
<mbrsc:RowSelectorColumn selectionMode="Single"
/>
<asp:boundcolumn headertext="Company Name"
datafield="CompanyName" />
<asp:HyperLinkColumn DataTextField="Contactname"
HeaderText="Contact Name"
DataNavigateUrlField="contactname"

datanavigateurlformatstring="mainIndex.aspx?Id={0} >"
/>
<asp:boundcolumn headertext="ContactTitle"
datafield="ContactTitle" />
</Columns>
</asp:datagrid>

<p></p>
<p></p>


<table align="center" border="0">
<tr>
<td><asp:button id="tbnNew" text="New"
runat="server" /></td>
<td> </td>
<td><asp:button id="btnAssign" text="Assign"
runat="server" /></td>
<td> </td>
<td><asp:button id="btnDelete" text="Delete"
runat="server" /></td>
</tr>
</table>
</form>
</body>
</html>
***************End of the html part .aspx

***** code behind code part of the
.aspx.vb**********
Imports System
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration

Public Class project_listing : Inherits Page

Protected dtgCusts As DataGrid
Protected lblOrderBy As Label
Protected strSql As String = "SELECT
CompanyName,
ContactName, ContactTitle, Phone FROM Customers"

Sub Page_Load(ByVal sender As Object, ByVal e As
EventArgs)
If Not Page.IsPostBack Then
BindTheData()
End If
End Sub

Sub BindTheData()
'Dim strConn As String
'strConn =

ConfigurationSettings.AppSettings"NorthwindConnect ion")

Dim strConn As String =
"server=movva;database=NorthWind;user
id=sa;password=pradev"
strSql = strSql + lblOrderBy.Text
Dim myDataSet As DataSet = New DataSet()
Dim myDataAdapter As SqlDataAdapter = New
SqlDataAdapter(strSql, strConn)
myDataAdapter.Fill(myDataSet, "Customers")

dtgCusts.DataSource =
myDataSet.Tables("Customers")

dtgCusts.DataBind()
End Sub

Sub PageIndexChanged_Click(ByVal sender As
Object,
ByVal e As DataGridPageChangedEventArgs)
dtgCusts.CurrentPageIndex = e.NewPageIndex
BindTheData()
End Sub

Sub SortCommand_Click(ByVal sender As Object,
ByVal e As DataGridSortCommandEventArgs)
lblOrderBy.Text = " ORDER BY " &
e.SortExpression
BindTheData()
End Sub

End Class

****************** end of the codebehind coe**********





 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Re: Hyperlinking and ASP.NEt Session Nedu N ASP .Net 5 09-07-2006 08:15 AM
Hyperlinking folders and or files in an xls file lafftrax Computer Support 1 12-24-2004 07:57 PM
Hyperlinking folders and or files in an xls file thumbs Computer Support 0 12-24-2004 05:10 PM
Hyperlinking and ASP.NEt Session Nedu N ASP .Net Building Controls 5 12-09-2003 10:08 PM



Advertisments