Click here to Skip to main content
15,917,456 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a gridview with 5 coulumns out of which one column is an image button field. When I click the image button I need the value of first column current row index.
Posted
Updated 5-Nov-10 21:40pm

Check this it will help you
//Image Button is inside in the grid
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        ImageButton imgBtn = (ImageButton)sender;
        GridViewRow gridRow = (GridViewRow)imgBtn.NamingContainer;
        int selectedIndex = gridRow.DataItemIndex;  
        //get the cell text from current index
        string item = GridView1.Rows[selectedIndex].Cells["your desired cell index"].Text;
    }
 
Share this answer
 
You can set the CommandName of that ImageButton To "Select". after this, when you click the ImageButton,the Gridview's SelectedIndexChanged Event will fire.

in SelectedIndexChanged event, you can get the value of the first column of the selected row as shown below:

//Considering Id of that gridview is GridView1
string desiredValue= GridView1.SelectedRow.Cells[0].Text;

please mark this answer correct if it helped you, so that others like you can get their solutions easily.
 
Share this answer
 

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