Click here to Skip to main content
16,004,574 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Good Guys

I need your help, please help me.

I am using ASP.NET 2008 to develop Web application. On the WebForm1, I have created GridView1 and the SELECT button are on the GridView First column of all the rows.

How do I set it up and handle it when the user click on one of them, how do I retrieve the data from the specific row where the Select Button is clicked?

How the coding within column ?

Cheers,
Lennie
Posted
Updated 28-Jul-10 19:23pm
v2

for a select button there will be select command set to Select. Now in selectedindexchanged event of gridview you can get the reference to selected GridView row as Gridview1.SelectedRow which returns a row of type GridviewRow.
 
Share this answer
 
Comments
TeeLeong 29-Jul-10 5:14am    
Hi Shining Legend;
Regarding your statement:
for a select button there will be select command set to Select. Now in selectedindexchanged event of gridview you can get the reference to selected GridView row as Gridview1.SelectedRow which returns a row of type GridviewRow.Permalink | Report

Can you please share the sample codes regarding it ?
Shining Legend 29-Jul-10 5:18am    
Please refer any of the below links:

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.selectedindexchanged.aspx

or

http://www.codeproject.com/Answers/96112/how-to-get-row-values-for-select-row-using-command.aspx#answer4
Hope these links would help you learning Gridview operations:
Try the following links:
Table of Contents: GridView Examples for ASP.NET 2.0[^]
Gridview Samples[^]
 
Share this answer
 
v2
C#
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
   {
       int selectedRow = GridView1.SelectedIndex;
       //teaking the value of first column in selected row
       string firstColumn = GridView1.Rows[selectedRow].Cells[0].Text;
       //taking the value of second column in selected row
       string secondColumn = GridView1.Rows[selectedRow].Cells[1].Text;
   }
 
Share this answer
 
Hi Makhaai,

I am not using C# software. I am using VBNET2008 with ASPNET2008 within

Regarding your suggestion listed below:
C#
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
 {
    int selectedRow = GridView1.SelectedIndex;

    //teaking the value of first column in selected row
      string firstColumn = GridView1.Rows[selectedRow].Cells[0].Text;

    //taking the value of second column in selected row
    string secondColumn = GridView1.Rows[selectedRow].Cells[1].Text;
   }



-----------------------------------------------------------
I convert it to VB Scripting and tried to run it but it generate this error message:
'cells' is not a member of 'Integer'. :laugh:

This is the ASP Vb version
VB
Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal E As System.EventArgs)

       Dim intSelectRow As Integer = GridView1.SelectedIndex
       Dim GVRow As GridViewRow
       Dim strCustID As String = GridView1.Rows(intSelectRow.cells(1).text)

   End Sub
 
Share this answer
 
Comments
raju melveetilpurayil 30-Jul-10 14:51pm    
use good converters to converts codes C# to VB.net. otherwise its raise errors ;)
check this link http://www.developerfusion.com/tools/convert/csharp-to-vb/
you can try simply with one line of code

protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
     lbl_message.Text = GridView1.SelectedRow.Cells[0].Text;
}
 
Share this answer
 
Comments
koool.kabeer 31-Jul-10 14:22pm    
in VB..........
lbl_message.Text= GridView1.SelectedRow.Cells(0).Text

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900