Click here to Skip to main content
15,897,226 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When I select a row in the gridview , I want to store the selected row index in arraylist and at the end update the database with all row indexes whih are present in the arrayist.
How can i achieve this?
Posted

try this :

List<int> L = new List<int>();


on datagridview click event :

C#
private void dataGridView1_MouseClick(object sender, MouseEventArgs e)
{
    int k = Convert.ToInt32(dataGridView1.CurrentRow.Index);
    if (!L.Contains(k))
    {
        L.Add(k);
    }
}


Hope it will help you ...
 
Share this answer
 
You can use Button/ImageButton or any control you want in templated field in grid view.
Suppose you are using Image button as per following , or you can change the code according to control you are using
C#
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
  {

      ImageButton btn = (ImageButton)sender;
      GridViewRow gvr = (GridViewRow)btn.NamingContainer;

      int index = gvr.ItemIndex;//Index of row

  }
 
Share this answer
 
v2

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