473,386 Members | 1,621 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.

DataGrid and JavaScript GURU...

Hi

I'm trying to create a little application that shows an image of a user when
you mouseover there details in a datagrid. The datagrid is populated from an
Active Directory Database and I presume the best way to create the popup is
by using a layer with javascript hide and show...

I intend to use a database to store the pictures in and the use the users
full name to build a relationship between the database with the images and
the Active Directory...

Can someone please tell me how I change the layer ID in the datagrid and
<div> so that it is not always the same image that is shown???

Or alternatively how do I create a user control with a placement holder in
the layer that refers to the correct image

Or suggest a better way to achieve this...

I would really appritiate any help....

<Inline Code>
<!--Popup Layer with users info-->
<DIV id="Layer1" style="BORDER-RIGHT: #000000 1px solid; BORDER-TOP: #000000
1px solid; Z-INDEX: 1; LEFT: 300px; VISIBILITY: hidden; BORDER-LEFT: #000000
1px solid; WIDTH: 120px; BORDER-BOTTOM: #000000 1px solid; POSITION:
absolute; TOP: 100px; HEIGHT: 130px; BACKGROUND-COLOR:
#ffffff"><asp:placeholder id="phIMGpopup"
runat="server"></asp:placeholder></DIV>
<!--End Popup Layer with users info-->

<asp:datagrid id="DataGrid1" runat="server" AllowSorting="True"
PagerStyle-Mode="NextPrev" AllowPaging="True"
AlternatingItemStyle-BackColor="WhiteSmoke" HeaderStyle-Font-Bold="True"
HeaderStyle-HorizontalAlign="Center" GridLines="Horizontal"
CssClass="txtArea" BorderColor="LightGray" BorderStyle="Ridge"
BorderWidth="1px" CellPadding="4" Width="70%"
OnPageIndexChanged="DataGrid1_Paged" ShowFooter="True"
AutoGenerateColumns="False">
<Columns>
<asp:HyperLinkColumn HeaderText="" Text="<a href='#'
onMouseOver=MM_showHideLayers('Layer1','','show')
onMouseOut=MM_showHideLayers('Layer1','','hide')>< img
src='../images/user.gif' border='0'></a>"></asp:HyperLinkColumn>
</Columns>
</asp:datagrid>

<CodeBehind>

Sub BindGrid(Optional ByVal alpha As String = "")

Dim strADPath As String
strADPath = "netdomain.usembassy.dk"

Dim de As DirectoryEntry = New DirectoryEntry("LDAP://" & strADPath,
"netadmin", "N37au7h0R")
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("givenName")(0)) & ", " &
CStr(res.Properties("sn")(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
' Binds Contact data from Active Directory to DataGrid
DataGrid1.DataSource = ds.Tables("contacts")
DataGrid1.DataBind()
End Sub

Nov 19 '05 #1
2 2824
You could make it a little easier with the Replace method of javascript..
that's what I use in situations like this if there's not a better way (and
the time is there to do it)

1. In your MM_showHideLayers function also send the object you are on with
"this" paramameter. so it looks like this..

onMouseOver=MM_showHideLayers('Layer1','','show', this);

2. Then in the function you can get the right client name from:

alert(this.id); with will give you something like
"DataGrid1_HyperLinkColumn... " plus an number that will represent the
ItemIndex of your Grid.. so that will tell you what row you are on.. and if
you make your DIV runat server and give it an ID that DIV will have a long
name and also the same ID in the end.... (You might want to enter an ID for
the HyperLinkColumn or actually use a Template Column instead and have just
a normal asp:HyperLink to give if your own ID)

3. Replace the HyperLinkColumnName that you have with the DIV name to create
a string that will be the ID for the DIV on that row and then create an
object reference to that DIV and Boom you will access the right DIV.

------------------------------------------------------------------------------------------------------------------------------
Here's some javascript code I used to show a DIV upon clicking a Plus Symbol
that would "expand" the datagrid Item. The Name of the Image to click was
named "ibtnExpandResource" and my div was simply named "div" as you see from
the first 3 rows of the function.

function OnPlusClick(sender) {
newWord = new String()
newWord = 'div';
divID = sender.id.replace(/ibtnExpandResource/, newWord);

theDiv = document.getElementById(divID)
if ( theDiv.style.display=="none") {
theDiv.style.display="";
sender.src ='../Images/minus.gif';
}else {
theDiv.style.display="none";
sender.src ='../Images/plus.gif';
}
}

Here's my Image Tag:

<asp:Image runat="server" ID="ibtnExpandResource"
ImageUrl="../images/plus.gif" onclick="javascript: OnPlusClick(this);"
style="cursor:hand;"></asp:Image>

And Here's my DIV tag:

<div runat="server" id='div' style="BORDER-RIGHT: black 1px solid;
PADDING-RIGHT: 5px; BORDER-TOP: black 1px solid; PADDING-LEFT: 5px;
PADDING-BOTTOM: 5px; BORDER-LEFT: black 1px solid; PADDING-TOP: 5px;
BORDER-BOTTOM: black 1px solid; BACKGROUND-COLOR: white; display:none;">

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

Pretty Simple right?

Best Regards/
Lars Netzel

"Tim::.." <myatix_at_hotmail.com> wrote in message
news:8D**********************************@microsof t.com...
Hi

I'm trying to create a little application that shows an image of a user
when
you mouseover there details in a datagrid. The datagrid is populated from
an
Active Directory Database and I presume the best way to create the popup
is
by using a layer with javascript hide and show...

I intend to use a database to store the pictures in and the use the users
full name to build a relationship between the database with the images and
the Active Directory...

Can someone please tell me how I change the layer ID in the datagrid and
<div> so that it is not always the same image that is shown???

Or alternatively how do I create a user control with a placement holder in
the layer that refers to the correct image

Or suggest a better way to achieve this...

I would really appritiate any help....

<Inline Code>
<!--Popup Layer with users info-->
<DIV id="Layer1" style="BORDER-RIGHT: #000000 1px solid; BORDER-TOP:
#000000
1px solid; Z-INDEX: 1; LEFT: 300px; VISIBILITY: hidden; BORDER-LEFT:
#000000
1px solid; WIDTH: 120px; BORDER-BOTTOM: #000000 1px solid; POSITION:
absolute; TOP: 100px; HEIGHT: 130px; BACKGROUND-COLOR:
#ffffff"><asp:placeholder id="phIMGpopup"
runat="server"></asp:placeholder></DIV>
<!--End Popup Layer with users info-->

<asp:datagrid id="DataGrid1" runat="server" AllowSorting="True"
PagerStyle-Mode="NextPrev" AllowPaging="True"
AlternatingItemStyle-BackColor="WhiteSmoke" HeaderStyle-Font-Bold="True"
HeaderStyle-HorizontalAlign="Center" GridLines="Horizontal"
CssClass="txtArea" BorderColor="LightGray" BorderStyle="Ridge"
BorderWidth="1px" CellPadding="4" Width="70%"
OnPageIndexChanged="DataGrid1_Paged" ShowFooter="True"
AutoGenerateColumns="False">
<Columns>
<asp:HyperLinkColumn HeaderText="" Text="<a href='#'
onMouseOver=MM_showHideLayers('Layer1','','show')
onMouseOut=MM_showHideLayers('Layer1','','hide')>< img
src='../images/user.gif' border='0'></a>"></asp:HyperLinkColumn>
</Columns>
</asp:datagrid>

<CodeBehind>

Sub BindGrid(Optional ByVal alpha As String = "")

Dim strADPath As String
strADPath = "netdomain.usembassy.dk"

Dim de As DirectoryEntry = New DirectoryEntry("LDAP://" &
strADPath,
"netadmin", "N37au7h0R")
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("givenName")(0)) & ", " &
CStr(res.Properties("sn")(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
' Binds Contact data from Active Directory to DataGrid
DataGrid1.DataSource = ds.Tables("contacts")
DataGrid1.DataBind()
End Sub

Nov 19 '05 #2
Hi Lars,

Thanks alot for the advice I will give it a go...

You make it sound pretty simple...

Tak

"Lars Netzel" wrote:
You could make it a little easier with the Replace method of javascript..
that's what I use in situations like this if there's not a better way (and
the time is there to do it)

1. In your MM_showHideLayers function also send the object you are on with
"this" paramameter. so it looks like this..

onMouseOver=MM_showHideLayers('Layer1','','show', this);

2. Then in the function you can get the right client name from:

alert(this.id); with will give you something like
"DataGrid1_HyperLinkColumn... " plus an number that will represent the
ItemIndex of your Grid.. so that will tell you what row you are on.. and if
you make your DIV runat server and give it an ID that DIV will have a long
name and also the same ID in the end.... (You might want to enter an ID for
the HyperLinkColumn or actually use a Template Column instead and have just
a normal asp:HyperLink to give if your own ID)

3. Replace the HyperLinkColumnName that you have with the DIV name to create
a string that will be the ID for the DIV on that row and then create an
object reference to that DIV and Boom you will access the right DIV.

------------------------------------------------------------------------------------------------------------------------------
Here's some javascript code I used to show a DIV upon clicking a Plus Symbol
that would "expand" the datagrid Item. The Name of the Image to click was
named "ibtnExpandResource" and my div was simply named "div" as you see from
the first 3 rows of the function.

function OnPlusClick(sender) {
newWord = new String()
newWord = 'div';
divID = sender.id.replace(/ibtnExpandResource/, newWord);

theDiv = document.getElementById(divID)
if ( theDiv.style.display=="none") {
theDiv.style.display="";
sender.src ='../Images/minus.gif';
}else {
theDiv.style.display="none";
sender.src ='../Images/plus.gif';
}
}

Here's my Image Tag:

<asp:Image runat="server" ID="ibtnExpandResource"
ImageUrl="../images/plus.gif" onclick="javascript: OnPlusClick(this);"
style="cursor:hand;"></asp:Image>

And Here's my DIV tag:

<div runat="server" id='div' style="BORDER-RIGHT: black 1px solid;
PADDING-RIGHT: 5px; BORDER-TOP: black 1px solid; PADDING-LEFT: 5px;
PADDING-BOTTOM: 5px; BORDER-LEFT: black 1px solid; PADDING-TOP: 5px;
BORDER-BOTTOM: black 1px solid; BACKGROUND-COLOR: white; display:none;">

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

Pretty Simple right?

Best Regards/
Lars Netzel

"Tim::.." <myatix_at_hotmail.com> wrote in message
news:8D**********************************@microsof t.com...
Hi

I'm trying to create a little application that shows an image of a user
when
you mouseover there details in a datagrid. The datagrid is populated from
an
Active Directory Database and I presume the best way to create the popup
is
by using a layer with javascript hide and show...

I intend to use a database to store the pictures in and the use the users
full name to build a relationship between the database with the images and
the Active Directory...

Can someone please tell me how I change the layer ID in the datagrid and
<div> so that it is not always the same image that is shown???

Or alternatively how do I create a user control with a placement holder in
the layer that refers to the correct image

Or suggest a better way to achieve this...

I would really appritiate any help....

<Inline Code>
<!--Popup Layer with users info-->
<DIV id="Layer1" style="BORDER-RIGHT: #000000 1px solid; BORDER-TOP:
#000000
1px solid; Z-INDEX: 1; LEFT: 300px; VISIBILITY: hidden; BORDER-LEFT:
#000000
1px solid; WIDTH: 120px; BORDER-BOTTOM: #000000 1px solid; POSITION:
absolute; TOP: 100px; HEIGHT: 130px; BACKGROUND-COLOR:
#ffffff"><asp:placeholder id="phIMGpopup"
runat="server"></asp:placeholder></DIV>
<!--End Popup Layer with users info-->

<asp:datagrid id="DataGrid1" runat="server" AllowSorting="True"
PagerStyle-Mode="NextPrev" AllowPaging="True"
AlternatingItemStyle-BackColor="WhiteSmoke" HeaderStyle-Font-Bold="True"
HeaderStyle-HorizontalAlign="Center" GridLines="Horizontal"
CssClass="txtArea" BorderColor="LightGray" BorderStyle="Ridge"
BorderWidth="1px" CellPadding="4" Width="70%"
OnPageIndexChanged="DataGrid1_Paged" ShowFooter="True"
AutoGenerateColumns="False">
<Columns>
<asp:HyperLinkColumn HeaderText="" Text="<a href='#'
onMouseOver=MM_showHideLayers('Layer1','','show')
onMouseOut=MM_showHideLayers('Layer1','','hide')>< img
src='../images/user.gif' border='0'></a>"></asp:HyperLinkColumn>
</Columns>
</asp:datagrid>

<CodeBehind>

Sub BindGrid(Optional ByVal alpha As String = "")

Dim strADPath As String
strADPath = "netdomain.usembassy.dk"

Dim de As DirectoryEntry = New DirectoryEntry("LDAP://" &
strADPath,
"netadmin", "N37au7h0R")
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("givenName")(0)) & ", " &
CStr(res.Properties("sn")(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
' Binds Contact data from Active Directory to DataGrid
DataGrid1.DataSource = ds.Tables("contacts")
DataGrid1.DataBind()
End Sub


Nov 19 '05 #3

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

Similar topics

3
by: Andy | last post by:
Hi, I am complete JavaScript novice and would really appreciate some help with this code: ===================================================================== <%@LANGUAGE="VBSCRIPT"...
6
by: KKramsch | last post by:
OK, here's the scenario: I have a CGI script that generates a page with frames (BTW, I'm not crazy about frames, but in this case the decision to use them is out of my hands). In a typical...
1
by: Jarrod Hyder | last post by:
Ok, I wrote my own weblog and I'm working on the web interface for adding/editing my posts. I decided to add a little preview button...when the button is clicked it is suppose to open a pop-up...
1
by: Jay | last post by:
Hi All, My users are complaining about the page refreshing when they are selecting multiple rows in a datagrid. Has anyone tried to manage this using javascript? I tried smartnavigation but that...
0
by: Xavier Pacheco | last post by:
This is probably a simple one, but I cannot seem to find an example. I have a datagrid with each row containing Checkbox | Textbox | Validation When the checkbox column is checked for a...
0
by: Tim::.. | last post by:
Please, please, please help!!! I have a datagrid that displays a list of contacts on our intranet site using the ActiveDirectory as it's main Data Source. I want to be able to show an image of...
0
by: Tim::.. | last post by:
Please, please, please help!!! I have a datagrid that displays a list of contacts on our intranet site using the ActiveDirectory as it's main Data Source. I want to be able to show an image of...
0
by: Tim::.. | last post by:
I have a datagrid that displays a list of contacts on our intranet site using the ActiveDirectory as it's main Data Source. I want to be able to show an image of each employee using a popup layer...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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.