Wednesday, February 13, 2008

AJAX Modal Popup Gridview Data Transfer

In a previous post I simply mentioned an article that helped me solve a problem I was having with the grid view control in an AJAX modal popup. The solution mentioned placing some javascript in your aspx file. I couldn't get that to quite work, so this is what I did:
  1. I created some hidden text fields in the modal popup.
  2. When a row in the grid view was selected by a user certain fields in the selected row were transferred to the hidden text fields.
    • Protected Sub GridView1_SelectedIndexChanging(ByVal sender As Object, ByVal e As GridViewSelectEventArgs)

      Dim index As Integer = GridView1.SelectedIndex
      Dim row As GridViewRow = GridView1.Rows(e.NewSelectedIndex)

      hTicket.Text = row.Cells(1).Text ...(etc.)
  3. When the OK button was clicked I was able to add some code into that sub procedure that transferred the data in the hidden fields to the controls in my form.
    • Me.txtTicketNbr.Text = hTicket.Text
This does seem like there should be an easier solution, but I could not get the data to be transferred from the grid view directly to the form when a certain row was selected. No one in the asp.net forums seemed to know or care. So if anyone comes across a solution after reading this, please be so kind as to share the knowledge.

3 comments:

Ivan said...

I'm running in to the same issue.
Let me know when you have a solution... if I find one, I will post back here.

Mansoor-Bari said...

Protected Sub GridView1_SelectedIndexChanging(ByVal sender As Object, ByVal e As GridViewSelectEventArgs)

//get our new selected index
int Index = e.NewSelectedIndex;

//display the value of column 1 to the TextBox Directly
Me.txtTicketNbr.Text = GridView1.Rows[Index].Cells[1].Text;

End Sub

NenCh said...

Me too... I'm having the same problem...

//get our new selected index
int Index = e.NewSelectedIndex;

//display the value of column 1 to the TextBox Directly
Me.txtTicketNbr.Text = GridView1.Rows[Index].Cells[1].Text;

how do i do this in vb?

Compilation Error
'NewSelectedIndex' is not a member of 'System.EventArgs'.