How to get Gridview cell value on select?

D

Dave Hewes

I am new to 2.0 and converting a page over from 1.1 datagrid.

How do I do the same thing as the following in a Gridview?

Private Sub DataGrid1_ItemCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
DataGrid1.ItemCommand
If e.CommandName = "Select" Then
Server.Transfer("frmProjectView.aspx?ProID=" +
e.Item.Cells(1).Text)
End If
End Sub


Dave
 
D

Dave Hewes

That works great...Thanks

David Longnecker said:
Dave-

Here's one option.

On your ASPX page, your GridView will have:

<asp:GridView ID="testGridView" runat="server" AutoGenerateColumns="False"
OnSelectedIndexChanged="testGridView_SelectedIndexChanged">
<Columns>
<asp:CommandField ButtonType="Button" ShowSelectButton="True" SelectText="View
Report" />
<asp:BoundField DataField="value1" />
<asp:BoundField DataField="value2" />
</Columns>
</asp:GridView>

Your code-behind:

protected void testGridView_SelectedIndexChanged(object sender, EventArgs e)
{
Server.Transfer("frmProjectView.aspx.aspx?ProId=" + testGridView.SelectedRow.Cells[1].Text);
}

Good luck!

-dl

---
David Longnecker
Web Developer
http://blog.tiredstudent.com
I am new to 2.0 and converting a page over from 1.1 datagrid.

How do I do the same thing as the following in a Gridview?

Private Sub DataGrid1_ItemCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
DataGrid1.ItemCommand
If e.CommandName = "Select" Then
Server.Transfer("frmProjectView.aspx?ProID=" +
e.Item.Cells(1).Text)
End If
End Sub
Dave
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,222
Members
46,810
Latest member
Kassie0918

Latest Threads

Top