GridView selectedrow values

H

HaVoK

Hello,

my problem: i want to get the values of the selected rows of a
GridView.
I have a button in every row and want to get the actual values e.g. of
cell 1 of the actual row.

How can i get this value?
I am using VS 2005 and VB.
Thanks a lot!

Best regards
Benjamin
 
M

Mark Rae

my problem: i want to get the values of the selected rows of a
GridView.

No problem.
I have a button in every row

You don't actually need a button to select a row - just clicking on it
selects it...
and want to get the actual values e.g. of cell 1 of the actual row.

How can i get this value?
I am using VS 2005 and VB.

The following code is in C#, but it should guide you through the process..

<asp:GridView ID="MyGridView" runat="server"
OnRowDataBound="MyGridView_RowDataBound"
OnSelectedIndexChanged="MyGridView_SelectedIndexChanged">

protected void MyGridView_RowDataBound(object sender, GridViewRowEventArgs
e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onclick",
ClientScript.GetPostBackEventReference(MyGridView, "Select$" +
e.Row.RowIndex.ToString()));
e.Row.Style["cursor"] = "pointer";
}
}

protected void MyGridView_SelectedIndexChanged(object sender, EventArgs e)
{
string strFirstCell = MyGridView.SelectedRow.Cells[0].Text;
}
 
H

HaVoK

thanks a lot :) now it's working fine.
--> for me it was a problem;-) I am unfortunately a beginner...

Best regards
Benjamin


Mark said:
my problem: i want to get the values of the selected rows of a
GridView.

No problem.
I have a button in every row

You don't actually need a button to select a row - just clicking on it
selects it...
and want to get the actual values e.g. of cell 1 of the actual row.

How can i get this value?
I am using VS 2005 and VB.

The following code is in C#, but it should guide you through the process..

<asp:GridView ID="MyGridView" runat="server"
OnRowDataBound="MyGridView_RowDataBound"
OnSelectedIndexChanged="MyGridView_SelectedIndexChanged">

protected void MyGridView_RowDataBound(object sender, GridViewRowEventArgs
e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onclick",
ClientScript.GetPostBackEventReference(MyGridView, "Select$" +
e.Row.RowIndex.ToString()));
e.Row.Style["cursor"] = "pointer";
}
}

protected void MyGridView_SelectedIndexChanged(object sender, EventArgs e)
{
string strFirstCell = MyGridView.SelectedRow.Cells[0].Text;
}
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top