Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 756
  • Last Modified:

Datagrid Row Click to another page

I need to make the whole row of a datagrid to redirect to another page while passing a variable in the URL so the page knows what to display. The following is what I have so far.

Private Sub dgTextInventory_ItemCreated(ByVal sender As Object, ByVal e As DataGridItemEventArgs) Handles dgTextInventory.ItemCreated
        If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Or e.Item.ItemType = ListItemType.SelectedItem Then
            e.Item.Attributes.Add("onmouseover", "this.style.cursor='hand'")
            e.Item.Attributes.Add("onclick", "javascript:__doPostBack('" & "dgTextInventory$_" & "ctl" & e.Item.ItemIndex & "$_ctl0','')")
        End If
    End Sub


Private Sub dgTextInventory_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dgTextInventory.SelectedIndexChanged
        dgTextInventory.SelectedItem.Attributes.Item("onmouseover") = "this.style.cursor='hand'"
        Response.Redirect("/SearchResults.aspx?unit=" & WHAT DO I PUT HERE  & ")
End Sub
0
poulsborv
Asked:
poulsborv
  • 5
  • 5
1 Solution
 
tusharashahCommented:
Where are  you getting your Variable that you want to pass from?

If it's from DataGrid's Column then you can retrieve and pass it like this:

Private Sub dgTextInventory_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dgTextInventory.SelectedIndexChanged
        'you dont need this line here dgTextInventory.SelectedItem.Attributes.Item("onmouseover") = "this.style.cursor='hand'"
        Response.Redirect("/SearchResults.aspx?unit=" & e.Item.Cells(n).Text )   '<------ Replace n with Number of Column where you have your Variable
End Sub

-tushar
0
 
poulsborvAuthor Commented:
 Private Sub dgTextInventory_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dgTextInventory.SelectedIndexChanged
        dgTextInventory.SelectedItem.Attributes.Item("onmouseover") = "this.style.cursor='hand'"
        dgTextInventory.SelectedItem.Attributes.Remove("onmouseout")
        Response.Redirect("/SearchResults.aspx?unit=" & e.Item.Cells(0).text)
    End Sub


This does not work it gives me this error

'Item' is not a member of 'System.EventArgs'

0
 
tusharashahCommented:
Following 2 lines have no affect in SelectedIndexChanged Event take it out from there ( or let me know what are you trying to achive):
        dgTextInventory.SelectedItem.Attributes.Item("onmouseover") = "this.style.cursor='hand'"  ' Also this syntax is incorrect
        dgTextInventory.SelectedItem.Attributes.Remove("onmouseout")

Private Sub dgTextInventory_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dgTextInventory.SelectedIndexChanged
        Response.Redirect("/SearchResults.aspx?unit=" & e.Item.Cells(0).text)
    End Sub

-tushar
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
ayha1999Commented:
Hi,

try this

        Response.Redirect("/SearchResults.aspx?unit=" & CType(e.Item.FindControl("YouControlName"), Label).Text )

hope this helps.

ayha
0
 
poulsborvAuthor Commented:
I still get the error that "e is not a member of system.Eventarg" when I try either

Response.Redirect("/SearchResults.aspx?unit=" & CType(e.Item.FindControl("YouControlName"), Label).Text )
or
Response.Redirect("/SearchResults.aspx?unit=" & e.Item.Cells(0).text)

From my understanding of what I am trying to do, in the following sub I need to accomplish 2 things I need to say use the hand cursor when going over it and two I need to tell it that when the user click on the row to do the _SelectedIndexChange, just like as if they click on a select button

Private Sub dgTextInventory_ItemCreated(ByVal sender As Object, ByVal e As DataGridItemEventArgs) Handles dgTextInventory.ItemCreated
'Add hand cursor to row  -  dgTextInventory.SelectedItem.Attributes.Item("onmouseover") = "this.style.cursor='hand'" HOW IS THIS THE WRONG SYNTAX?
'Add something that tell onclick to either run a javascript redirect or to post back and do a response.redirect
End Sub

When row is clicked it needs to do the following, but how do I identify which stockno is in the row that I selected?
Private Sub dgTextInventory_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dgTextInventory.SelectedIndexChanged
' Redirect to the next page        Response.Redirect("/SearchResults.aspx?unit=" & e.Item.Cells(0).text)
End Sub

Thanks for the info

D--
0
 
tusharashahCommented:
Drop Select Button As 1st Column in your DataGrid:

1) Modify your ItemCreated Event Like following:
  Private Sub dgTextInventory_ItemCreated(ByVal sender As Object, ByVal e As DataGridItemEventArgs) Handles dgTextInventory.ItemCreated
      e.Item.Attributes.Add("OnMouseOver","this.style.cursor='hand';")
      Dim strID AS String = ( (LinkButton) e.Item.Cells(0).Controls(0) ).ClientID.Replace("__","$_")
      e.Item.Attributes.Add("OnClick","javascript:__doPostBack('" + strID  + "');" )
  End Sub

2) Let's say Variable that you want to pass as QueryString is on 2nd Column now, so write down following code in SelectedIndexChange Event:

Private Sub dgTextInventory_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dgTextInventory.SelectedIndexChanged
  Response.Redirect("ViewContact.aspx?CompanyNo=" + dgTextInventory.SelectedItem.Cells(1).Text )
End Sub

-tushar
0
 
poulsborvAuthor Commented:
Ok hopefully this will be the last question, I feel we are very close

 Dim strID AS String = ( (LinkButton) e.Item.Cells(0).Controls(0) ).ClientID.Replace("__","$_")

This gives me an error  it says ") is expected right here( (LinkButton)  <--

would you mind explaining what is going on with this line of code. I moved the select column to the first row ( or cell 0) What is the text LinkButton for?

Thanks

D--
0
 
tusharashahCommented:
It should be like following:

Dim strID AS String = CType(e.Item.Cells(0).Controls(0), LinkButton).ClientID.Replace("__", "$_")

Select Button is normaly a LinkButton.. ( change LinkButton to Button, if you have button). This line will grab ClientID of your LinkButton and will place it in strID which you'll pass in doPostBack function..

-tushar
0
 
poulsborvAuthor Commented:
So close, I could'nt get the exact code working that you gave me, but I have jury rigged it so far with this


        Dim strID As String = "dgTextInventory$_ctl" &  NEED AUTO INCREMENT HERE & "$_ctl0','"

        e.Item.Attributes.Add("OnClick", "javascript:__doPostBack('" + strID + "');")

So now I just need to figure out how to autoincrement or something, I will continue to look and play. If you know how to do this that would be great the point are your anyways.

D--
0
 
tusharashahCommented:
The code I gave you should give correct ClientID for Select Button in every case.. but still if you want to do the other way then use e.Item.ItemIndex ..

        Dim strID As String = "dgTextInventory$_ctl" &  e.Item.ItemIndex & "$_ctl0','"

        e.Item.Attributes.Add("OnClick", "javascript:__doPostBack('" + strID + "');")

-tushar
0
 
poulsborvAuthor Commented:
Got it! - For the record here is what the code looks like

Private Sub dgTextInventory_ItemCreated(ByVal sender As Object, ByVal e As DataGridItemEventArgs) Handles dgTextInventory.ItemCreated
        e.Item.Attributes.Add("OnMouseOver", "this.style.cursor='hand';")
        Dim strID As String = "dgTextInventory$_ctl" & e.Item.ItemIndex + 2 & "$_ctl0','"
        e.Item.Attributes.Add("OnClick", "javascript:__doPostBack('" + strID + "');")
End Sub

Private Sub dgTextInventory_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dgTextInventory.SelectedIndexChanged
       Response.Redirect("SearchResults.aspx?Unit=" + dgTextInventory.SelectedItem.Cells(1).Text)
End Sub

Don't know if this is the best solution, but it seems to work

D--
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

  • 5
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now