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(" ") = "<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(" ") = "<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 1 1061
Consider storing the results in the DataCache.
-Brock
DevelopMentor http://staff.develop.com/ballen 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(" ") = "<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(" ") = "<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).Item Array) '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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Raaijmakers, Vincent (IndSys,GE Interlogix) |
last post by:
Looking at all the materials available, books, technologies etc etc..
I try to make a decision on what technology to select for a web server design, but I need help.
I know, this question has...
|
by: Michel |
last post by:
Hi all,
Is there some intelligent way to trigger a clientside JavaScript function
before a postback is triggerd by any of the controls on a page?
Thanks in advance,
Michel Mathijssen
|
by: Earl Teigrob |
last post by:
I did a ton of searching to try and find a simple solution to this issue and finally wrote my own, which I am sharing with everyone. In my searching, I did find a very complete and robust solution at...
|
by: Robert Galvin |
last post by:
Is it possible to tell which control caused a postback?
|
by: antonyliu2002 |
last post by:
I know that this has been asked and answered thousands of times. As a
matter of fact, I know that I need to say
If Not Page.IsPostBack Then
'Do something
End If
for things that needs to be...
|
by: Sehboo |
last post by:
We want to prevent user from being able to click on a button twice or
click on other controls while processing is going on. I tried the
following javascript code (which was suggested in this group...
|
by: Singulus |
last post by:
Hello all,
I've searched for similar threads, I've found some bit of useful info
here and there, but nevertheless I want to post my questions...So, how
can I (we, in fact the forum can benefit...
|
by: stevenjs |
last post by:
Greeings, all,
Flash 8 has quiz templates which are coded for multiple choice, true/false, text statement, and matching types of questions, along with hotspots and probably anoher type I am...
|
by: Eraser |
last post by:
Hi to all .NET guru guys...
I have a problem in my delete button inside gridview. How to avoid postback on when i select cancel on confirmation message? But postback is okay on Ok confirmation....
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |