473,386 Members | 1,828 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

MAJOR problem with alphabetic paging

Hi...

I'm having a big problem with a datagrid that obtains data from 2 different
locations...

Active Directory and SQL Database

The data is inserted into a datatable and the sorted by a dataview...
however due to alphabetic paging and the postback ("I think") the contacts
from the SQL Database appear on ever page when you page through the datagrids
results...

How do I get around this???

Should I store the results in something else other than a datatable... what
do you recommend???

Thanks for any help!

<code>

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

'Loads user controls
Dim c1 As Control = LoadControl("../userControls/footer.ascx")
phFooter.Controls.Add(c1)
Dim c2 As Control = LoadControl("../userControls/headerMenu.ascx")
phHeaderMenu.Controls.Add(c2)
Dim c3 As Control = LoadControl("../userControls/Header.ascx")
phHeader.Controls.Add(c3)
Dim c4 As Control = LoadControl("../userControls/QuickLinks.ascx")
phQuickLinks.Controls.Add(c4)
'Create table to contain contacts
createTable()

If Not Page.IsPostBack Then
'Bind Contacts information from Active Directory for
alphabetic filtering
BindGrid()
End If

End Sub

Private Sub createTable()
Dim tbcontacts As DataTable = New DataTable("contacts")
tbcontacts.Columns.Add(" ", System.Type.GetType("System.String"))
tbcontacts.Columns.Add("Name", System.Type.GetType("System.String"))
tbcontacts.Columns.Add("Dept.", System.Type.GetType("System.String"))
tbcontacts.Columns.Add("Ext", System.Type.GetType("System.String"))
tbcontacts.Columns.Add("Email", System.Type.GetType("System.String"))
ds.Tables.Add(tbcontacts)
End Sub
'Function to Page through contacts
Sub DataGrid1_Paged(ByVal sender As Object, ByVal e As
DataGridPageChangedEventArgs)
DataGrid1.CurrentPageIndex = e.NewPageIndex
BindGrid()
End Sub
'Add's alphabetic filtering for contacts list
Private Sub DataGrid1_ItemCreated(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemCreated
If e.Item.ItemType = ListItemType.Footer Then
e.Item.Cells.Clear()
Dim tc As New TableCell
tc.ColumnSpan = 5
e.Item.Cells.Add(tc)
Dim spacer As New LiteralControl
spacer.Text = " "
tc.Controls.Add(spacer)
'Adds Alphabetical list to the footer of the DataGrid
Dim i As Integer
For i = 65 To 65 + 25
Dim l As New LinkButton
Dim lc As New LiteralControl
lc.Text = " "
l.Text = Chr(i)
l.CommandName = "alpha"
l.CommandArgument = Chr(i)
tc.Controls.Add(l)
tc.Controls.Add(lc)
Next
'Adds View All text to the footer of the DataGrid
Dim showAll As New LinkButton
showAll.Text = "...View All"
showAll.CommandName = "alpha"
showAll.CommandArgument = ""
tc.Controls.Add(showAll)
End If
End Sub
' Adds Active Directory User information into contacts table
Sub BindGrid(Optional ByVal alpha As String = "")

Dim strADPath As String
strADPath = "domain.dk"

Dim de As DirectoryEntry = New DirectoryEntry("LDAP://" & strADPath,
"username", "password")
Dim src As DirectorySearcher

If alpha = "" Then
DataGrid1.AllowPaging = True
src = New
DirectorySearcher("(&(objectCategory=Person)(objec tClass=user))")
Else
DataGrid1.AllowPaging = False
src = New
DirectorySearcher("(&(objectCategory=Person)(objec tClass=user)(sn=" & alpha &
"*))")

End If

src.SearchRoot = de
src.SearchScope = SearchScope.Subtree
For Each res As SearchResult In src.FindAll
Dim dr As DataRow = ds.Tables("contacts").NewRow
dr("&nbsp;") = "<img src='../images/user.gif'>"

If res.Properties.Contains("sn") And
res.Properties.Contains("givenName") And res.Properties.Contains("Initials")
Then
dr("Name") = CStr(res.Properties("sn")(0)) & ", " &
CStr(res.Properties("givenName")(0)) & " " &
CStr(res.Properties("Initials")(0))
Else
dr("Name") = ""
End If

If res.Properties.Contains("physicalDeliveryOfficeNam e") Then
dr("Dept.") =
CStr(res.Properties("physicalDeliveryOfficeName")( 0))
Else
dr("Dept.") = ""
End If

If res.Properties.Contains("telephoneNumber") Then
Dim TeleNumber As String =
CStr(res.Properties("telephoneNumber")(0))
dr("Ext") = "#" & Right(TeleNumber, Len(TeleNumber) -
InStr(TeleNumber, "1"))
Else
dr("Ext") = ""
End If

If res.Properties.Contains("mail") Then
dr("Email") = CStr(res.Properties("mail")(0))
Else
dr("Email") = ""
End If

ds.Tables("contacts").Rows.Add(dr)

Next
'Adds Non Active Directory Users into the DataGrid
Dim Myconn As New
SqlConnection(ConfigurationSettings.AppSettings("s trConn"))
'Dim tbcontactsNonAD As DataTable = New DataTable("contactsNonAD")
Dim cmd As New SqlCommand("NonADUsers", Myconn)
cmd.CommandType = CommandType.StoredProcedure
Myconn.Open()
Dim dread As SqlDataReader = cmd.ExecuteReader
While dread.Read()
Dim row As DataRow = ds.Tables("contacts").NewRow()
row("&nbsp;") = "<img src='../images/user.gif'>"
row("Name") = dread.GetString("0") & ", " &
dread.GetString("1") & " " & dread.GetString("2")
row("Dept.") = dread.GetString("3")
row("Ext") = dread.GetString("4")
row("Email") = dread.GetString("5")
ds.Tables("contacts").Rows.Add(row)
End While
Myconn.Close()

'For i As Integer = 0 To ds.Tables("contactsNonAD").Rows.Count - 1
'
ds.Tables("contacts").Rows.Add(ds.Tables("contacts NonAD").Rows(i).ItemArray)
'Next
'End of Non Active Directory DataGrid Addition
Dim myDataView As DataView
myDataView = New DataView(ds.Tables("contacts"))
myDataView.Sort = "Name ASC"

' Binds Contact data from Active Directory to DataGrid
DataGrid1.DataSource = myDataView
DataGrid1.DataBind()
End Sub
' Filters Contacts alphabectically when user chooses a letter
Private Sub DataGrid1_ItemCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles
DataGrid1.ItemCommand
If e.CommandName = "alpha" Then
BindGrid(e.CommandArgument)
End If
End Sub
Nov 19 '05 #1
0 1619

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Daniel Walzenbach | last post by:
Hi, I have a question regarding the DataGrid control. If paging is enabled the grid binds the data, sets the paging on the top/bottom (or however it is set up) and throws away unnecessary...
0
by: Tim::.. | last post by:
Hi... I'm having a big problem with a datagrid that obtains data from 2 different locations... Active Directory and SQL Database The data is inserted into a datatable and the sorted by a...
2
by: asad | last post by:
hello friends, how ru all I want to create a custom paging logic in ASP.NET with a next link for example if i have 100 pages record so i want to show 6 pages link on page one and next link ...
2
by: rn5a | last post by:
In a shopping cart app, a ASPX page retrieves the order details & personal details of a user from a MS-Access database table depending upon the username of the user. The order details of a...
3
by: Ronald S. Cook | last post by:
I was told that if calling lots of records from the database (let's say 100,000), that the GridView's paging feature would automatically "handle" everything. But the 100,000 records are still...
1
by: =?Utf-8?B?TG95b2xhIHN0YWxpbg==?= | last post by:
Hi, I am using ASP.Net 2.0 version and Windows'XP OS. I am useing the Grid view control to display the user details along with the paging concept provided by the grid view control. When i...
3
by: PulkitZery | last post by:
Hi all, I need some help in my project (VB.NET) here is what I need: I need to convert Alphabetic number (a. b. c. d. …..) into the integers (for example a=1, b=2, c=3 and so on). Can anyone...
8
tharden3
by: tharden3 | last post by:
Hey all, I need some help with PHP code for paging my products on my site. I posted questions asking for help in the past, and was directed to this tutorial for help. The code that the tutorial gives...
8
crystal2005
by: crystal2005 | last post by:
Hi guys, Just like the title, i'm looking for the example of C program that translates an alphabetic phone number into numeric. The idea as the following output Enter phone number:...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.