GridView selectedrow values

  • Thread starter Thread starter HaVoK
  • Start date Start date
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
 
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;
}
 
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;
}
 
Back
Top