473,383 Members | 1,792 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,383 software developers and data experts.

How to Select Datagrid Row

I currently have a datagrid with several columns. The first column in the
DataGrid is a HyperLinkColumn. When I select a row, I would like for this
HyperlinkColumn to fire. I have the mouseover colors changing, and I have the
routine, but I can't seem to get the HyperLinkColumn to fire....

Private Sub MyDataGrid_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles
MyDataGrid.ItemDataBound
'turn off highlighting...
If bHighlightDataGrid = False Then
Exit Sub
End If

If ((e.Item.ItemType = ListItemType.Pager) Or (e.Item.ItemType =
ListItemType.Header) Or (e.Item.ItemType = ListItemType.Footer)) Then
Exit Sub
End If

If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType =
ListItemType.AlternatingItem Then
e.Item.Attributes.Add("onmouseover",
"this.style.backgroundColor='" & HighlightColor & "'")
If e.Item.ItemType = ListItemType.AlternatingItem Then
e.Item.Attributes.Add("onmouseout",
"this.style.backgroundColor='" & AlternatingColor & "'")
Else
e.Item.Attributes.Add("onmouseout",
"this.style.backgroundColor='" & DefaultColor & "'")
End If
e.Item.Attributes("onclick") =
Page.GetPostBackClientHyperlink(e.Item.Cells(0).Co ntrols(0), "")

'THIS IS THE SECTION THAT I'M ATTEMPTING TO GET THIS TO WORK.
'IF I CHANGE THE HYPERLINK TO HYPERLINKCOLUMN I GET A SYNTAX
'ERROR.
Dim MYLINK As HyperLink = CType(e.Item.Cells(0).Controls(0), HyperLink)
e.Item.Attributes("onclick") =
Page.GetPostBackClientHyperlink(MYLINK, "")
End If

End Sub
Nov 19 '05 #1
4 4378
I got your code to work:
http://www.societopia.net/samples/Da..._DataList.aspx by using the
Page.GetPostBackEventReference on a LinkButton (instead of the
Page.GetPostBackClientHyperlink that you used on HyperLinkColumn)

Hope this helps.
--
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"sakieboy" wrote:
I currently have a datagrid with several columns. The first column in the
DataGrid is a HyperLinkColumn. When I select a row, I would like for this
HyperlinkColumn to fire. I have the mouseover colors changing, and I have the
routine, but I can't seem to get the HyperLinkColumn to fire....

Private Sub MyDataGrid_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles
MyDataGrid.ItemDataBound
'turn off highlighting...
If bHighlightDataGrid = False Then
Exit Sub
End If

If ((e.Item.ItemType = ListItemType.Pager) Or (e.Item.ItemType =
ListItemType.Header) Or (e.Item.ItemType = ListItemType.Footer)) Then
Exit Sub
End If

If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType =
ListItemType.AlternatingItem Then
e.Item.Attributes.Add("onmouseover",
"this.style.backgroundColor='" & HighlightColor & "'")
If e.Item.ItemType = ListItemType.AlternatingItem Then
e.Item.Attributes.Add("onmouseout",
"this.style.backgroundColor='" & AlternatingColor & "'")
Else
e.Item.Attributes.Add("onmouseout",
"this.style.backgroundColor='" & DefaultColor & "'")
End If
e.Item.Attributes("onclick") =
Page.GetPostBackClientHyperlink(e.Item.Cells(0).Co ntrols(0), "")

'THIS IS THE SECTION THAT I'M ATTEMPTING TO GET THIS TO WORK.
'IF I CHANGE THE HYPERLINK TO HYPERLINKCOLUMN I GET A SYNTAX
'ERROR.
Dim MYLINK As HyperLink = CType(e.Item.Cells(0).Controls(0), HyperLink)
e.Item.Attributes("onclick") =
Page.GetPostBackClientHyperlink(MYLINK, "")
End If

End Sub

Nov 19 '05 #2
Thanks for your help.

Maybe I'm not explaining this correct, let's say that this is my code

If e.Item.ItemType = ListItemType.AlternatingItem Then
e.Item.Attributes.Add("onmouseout",
"this.style.backgroundColor='" & AlternatingColor & "'")
Else
e.Item.Attributes.Add("onmouseout",
"this.style.backgroundColor='" & DefaultColor & "'")
End If

Dim MYLINK As HyperLink = CType(e.Item.Cells(0).Controls(0),
HyperLink)
e.Item.Attributes("onclick") =
Page.GetPostBackEventReference(MYLINK, "")

When I select any row in the grid (excluding the first column, which has the
link in it), I would like it to fire the link in the first column. My
current code, seems like it's firing the ColumHeader "Edit" (which is the
header for the first column) and re-sorting stuff. i.e. if I select an item
in the datagrid which is in the 6th row, 3rd column, it is not firing the
Hyperlink located in the 6th row 1st column. This hyperlink should actually
take me to another page....

"Phillip Williams" wrote:
I got your code to work:
http://www.societopia.net/samples/Da..._DataList.aspx by using the
Page.GetPostBackEventReference on a LinkButton (instead of the
Page.GetPostBackClientHyperlink that you used on HyperLinkColumn)

Hope this helps.
--
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"sakieboy" wrote:
I currently have a datagrid with several columns. The first column in the
DataGrid is a HyperLinkColumn. When I select a row, I would like for this
HyperlinkColumn to fire. I have the mouseover colors changing, and I have the
routine, but I can't seem to get the HyperLinkColumn to fire....

Private Sub MyDataGrid_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles
MyDataGrid.ItemDataBound
'turn off highlighting...
If bHighlightDataGrid = False Then
Exit Sub
End If

If ((e.Item.ItemType = ListItemType.Pager) Or (e.Item.ItemType =
ListItemType.Header) Or (e.Item.ItemType = ListItemType.Footer)) Then
Exit Sub
End If

If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType =
ListItemType.AlternatingItem Then
e.Item.Attributes.Add("onmouseover",
"this.style.backgroundColor='" & HighlightColor & "'")
If e.Item.ItemType = ListItemType.AlternatingItem Then
e.Item.Attributes.Add("onmouseout",
"this.style.backgroundColor='" & AlternatingColor & "'")
Else
e.Item.Attributes.Add("onmouseout",
"this.style.backgroundColor='" & DefaultColor & "'")
End If
e.Item.Attributes("onclick") =
Page.GetPostBackClientHyperlink(e.Item.Cells(0).Co ntrols(0), "")

'THIS IS THE SECTION THAT I'M ATTEMPTING TO GET THIS TO WORK.
'IF I CHANGE THE HYPERLINK TO HYPERLINKCOLUMN I GET A SYNTAX
'ERROR.
Dim MYLINK As HyperLink = CType(e.Item.Cells(0).Controls(0), HyperLink)
e.Item.Attributes("onclick") =
Page.GetPostBackClientHyperlink(MYLINK, "")
End If

End Sub

Nov 19 '05 #3
If you are only interested in jumping to the URL of the Hyperlink then why
are you trying to generate a server postback?

You can instead do this:

e.Item.Attributes("onclick") = _
"javascript:document.URL='" & _
Ctype(e.Item.Cells(0).Controls(0), HyperLink).NavigateUrL & "';"
e.Item.Attributes("title") = "Click anywhere on the row to jump to the link
associated with this row"

I did that and put a new example (with the source code) to demonstrate it
at: http://www.societopia.net/Samples/Da...DataList2.aspx

--
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"sakieboy" wrote:
Thanks for your help.

Maybe I'm not explaining this correct, let's say that this is my code

If e.Item.ItemType = ListItemType.AlternatingItem Then
e.Item.Attributes.Add("onmouseout",
"this.style.backgroundColor='" & AlternatingColor & "'")
Else
e.Item.Attributes.Add("onmouseout",
"this.style.backgroundColor='" & DefaultColor & "'")
End If

Dim MYLINK As HyperLink = CType(e.Item.Cells(0).Controls(0),
HyperLink)
e.Item.Attributes("onclick") =
Page.GetPostBackEventReference(MYLINK, "")

When I select any row in the grid (excluding the first column, which has the
link in it), I would like it to fire the link in the first column. My
current code, seems like it's firing the ColumHeader "Edit" (which is the
header for the first column) and re-sorting stuff. i.e. if I select an item
in the datagrid which is in the 6th row, 3rd column, it is not firing the
Hyperlink located in the 6th row 1st column. This hyperlink should actually
take me to another page....

"Phillip Williams" wrote:
I got your code to work:
http://www.societopia.net/samples/Da..._DataList.aspx by using the
Page.GetPostBackEventReference on a LinkButton (instead of the
Page.GetPostBackClientHyperlink that you used on HyperLinkColumn)

Hope this helps.
--
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"sakieboy" wrote:
I currently have a datagrid with several columns. The first column in the
DataGrid is a HyperLinkColumn. When I select a row, I would like for this
HyperlinkColumn to fire. I have the mouseover colors changing, and I have the
routine, but I can't seem to get the HyperLinkColumn to fire....

Private Sub MyDataGrid_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles
MyDataGrid.ItemDataBound
'turn off highlighting...
If bHighlightDataGrid = False Then
Exit Sub
End If

If ((e.Item.ItemType = ListItemType.Pager) Or (e.Item.ItemType =
ListItemType.Header) Or (e.Item.ItemType = ListItemType.Footer)) Then
Exit Sub
End If

If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType =
ListItemType.AlternatingItem Then
e.Item.Attributes.Add("onmouseover",
"this.style.backgroundColor='" & HighlightColor & "'")
If e.Item.ItemType = ListItemType.AlternatingItem Then
e.Item.Attributes.Add("onmouseout",
"this.style.backgroundColor='" & AlternatingColor & "'")
Else
e.Item.Attributes.Add("onmouseout",
"this.style.backgroundColor='" & DefaultColor & "'")
End If
e.Item.Attributes("onclick") =
Page.GetPostBackClientHyperlink(e.Item.Cells(0).Co ntrols(0), "")

'THIS IS THE SECTION THAT I'M ATTEMPTING TO GET THIS TO WORK.
'IF I CHANGE THE HYPERLINK TO HYPERLINKCOLUMN I GET A SYNTAX
'ERROR.
Dim MYLINK As HyperLink = CType(e.Item.Cells(0).Controls(0), HyperLink)
e.Item.Attributes("onclick") =
Page.GetPostBackClientHyperlink(MYLINK, "")
End If

End Sub

Nov 19 '05 #4
That's exactly what I want, I knew it was in the NavigateURL, but wasn't sure
how to access it......Thanks alot!!!

"Phillip Williams" wrote:
If you are only interested in jumping to the URL of the Hyperlink then why
are you trying to generate a server postback?

You can instead do this:

e.Item.Attributes("onclick") = _
"javascript:document.URL='" & _
Ctype(e.Item.Cells(0).Controls(0), HyperLink).NavigateUrL & "';"
e.Item.Attributes("title") = "Click anywhere on the row to jump to the link
associated with this row"

I did that and put a new example (with the source code) to demonstrate it
at: http://www.societopia.net/Samples/Da...DataList2.aspx

--
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"sakieboy" wrote:
Thanks for your help.

Maybe I'm not explaining this correct, let's say that this is my code

If e.Item.ItemType = ListItemType.AlternatingItem Then
e.Item.Attributes.Add("onmouseout",
"this.style.backgroundColor='" & AlternatingColor & "'")
Else
e.Item.Attributes.Add("onmouseout",
"this.style.backgroundColor='" & DefaultColor & "'")
End If

Dim MYLINK As HyperLink = CType(e.Item.Cells(0).Controls(0),
HyperLink)
e.Item.Attributes("onclick") =
Page.GetPostBackEventReference(MYLINK, "")

When I select any row in the grid (excluding the first column, which has the
link in it), I would like it to fire the link in the first column. My
current code, seems like it's firing the ColumHeader "Edit" (which is the
header for the first column) and re-sorting stuff. i.e. if I select an item
in the datagrid which is in the 6th row, 3rd column, it is not firing the
Hyperlink located in the 6th row 1st column. This hyperlink should actually
take me to another page....

"Phillip Williams" wrote:
I got your code to work:
http://www.societopia.net/samples/Da..._DataList.aspx by using the
Page.GetPostBackEventReference on a LinkButton (instead of the
Page.GetPostBackClientHyperlink that you used on HyperLinkColumn)

Hope this helps.
--
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"sakieboy" wrote:

> I currently have a datagrid with several columns. The first column in the
> DataGrid is a HyperLinkColumn. When I select a row, I would like for this
> HyperlinkColumn to fire. I have the mouseover colors changing, and I have the
> routine, but I can't seem to get the HyperLinkColumn to fire....
>
> Private Sub MyDataGrid_ItemDataBound(ByVal sender As Object, ByVal e As
> System.Web.UI.WebControls.DataGridItemEventArgs) Handles
> MyDataGrid.ItemDataBound
> 'turn off highlighting...
> If bHighlightDataGrid = False Then
> Exit Sub
> End If
>
> If ((e.Item.ItemType = ListItemType.Pager) Or (e.Item.ItemType =
> ListItemType.Header) Or (e.Item.ItemType = ListItemType.Footer)) Then
> Exit Sub
> End If
>
> If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType =
> ListItemType.AlternatingItem Then
> e.Item.Attributes.Add("onmouseover",
> "this.style.backgroundColor='" & HighlightColor & "'")
> If e.Item.ItemType = ListItemType.AlternatingItem Then
> e.Item.Attributes.Add("onmouseout",
> "this.style.backgroundColor='" & AlternatingColor & "'")
> Else
> e.Item.Attributes.Add("onmouseout",
> "this.style.backgroundColor='" & DefaultColor & "'")
> End If
> e.Item.Attributes("onclick") =
> Page.GetPostBackClientHyperlink(e.Item.Cells(0).Co ntrols(0), "")
>
> 'THIS IS THE SECTION THAT I'M ATTEMPTING TO GET THIS TO WORK.
> 'IF I CHANGE THE HYPERLINK TO HYPERLINKCOLUMN I GET A SYNTAX
> 'ERROR.
> Dim MYLINK As HyperLink = CType(e.Item.Cells(0).Controls(0), HyperLink)
> e.Item.Attributes("onclick") =
> Page.GetPostBackClientHyperlink(MYLINK, "")
> End If
>
> End Sub

Nov 19 '05 #5

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

Similar topics

4
by: Terry | last post by:
Hey, Having somewhat of an issue, I have a datagrid which is giving me issues. The Datagrid is setup for the user to double click the row, the row is selected and data within that row populates a...
4
by: Bruce Pullum | last post by:
I have a datagrid that I am using a DataView with. All works great for the sorting of the columns. However, after I sort the column, and then try and select a data row to edit, the row selected...
2
by: Chris Plowman | last post by:
Hi all, I was wondering if anyone can help me with a really annoying problem I have been having. I made a derived datagrid class that will select the row when a user clicks anywhere on a cell...
1
by: developer | last post by:
I have a Windows form that contains a datagrid populated with a table in my database. When i load my form i want a particular row in my datagrid to be selected. How can i do that Thanks
2
by: Juan | last post by:
Do i have to loop trough a datagrid in order to find and select a row just being inserted? is there any event i can capture in the datagrid to obtain the inserted row? I need to obtain its position...
3
by: Zachary Hilbun | last post by:
I'm using a DataGrid control in a web form. I can display it using binding but when I click on any of the items there is no feedback that that row has been selected. I changed SelectedItemStyle...
2
by: Bob Hollness | last post by:
Hi group. I am a newbie to ASP.NET as you will see from some of the questions I may ask! I have a datagrid which I have populated from a database. It works great! I have added a column, via...
5
by: Vik | last post by:
If there are a few Select buttons in a datagrid, is there a way to distinguish in code which button was clicked? Thanks.
3
by: CharlesA | last post by:
Hi folks, I really need help with the following scenario, I'm going to describe as well as a I can what the setup is and what I can't understand I'm using the framework 1.1 using ASP.net with...
1
by: Wan | last post by:
Hi, I have a test project which contains two simple forms - 1st form contains datagrid and couple of buttons. First button to populate the grid with Northwind.Customers records and show 3...
1
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...
0
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
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...
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
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?
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...

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.