tags:

views:

740

answers:

1

ihv got allow paging in my gridview...

i need this in button click event

1.) giridvew total row count .

2.) loop through all the rows in foreach

but its jst wrking for the current gridview page...help

protected void Button5_Click(object sender, EventArgs e)
        {
int[] no = new int[GridView2.Rows.Count];
                int i = 0;
            foreach (GridViewRow row in GridView2.Rows)
            {            
                    Label l = (Label)row.FindControl("Label2");
                    if (l.Text == "Unpaid")
                    {
                        int productID = Convert.ToInt32(GridView2.DataKeys[row.RowIndex].Value);
                        no[i] = productID;
                        i++;
                    }
                }                

)
A: 

hi , to achieve you have to disable paging before loop. rebind the grid & perform loop . Then enable paging & bind the grid again.

       protected void Button5_Click(object sender, EventArgs e)       
 { 
GridView2.AllowPaging = false;
 // do your databind here 
GridView2.databind(); 
int[] no = new int[GridView2.Rows.Count];      
          int i = 0;        
    foreach (GridViewRow row in GridView2.Rows)      
      {                             
   Label l = (Label)row.FindControl("Label2");
                    if (l.Text == "Unpaid")        
            {                    
    int productID = Convert.ToInt32(GridView2.DataKeys[row.RowIndex].Value);                        no[i] = productID;                        i++;                    }                }  


              )



GridView2.AllowPaging = true;
        // do your databind here again
        GridView2.databind();
Pragnesh Patel