开发者

How to calculate the Yes or No In status column when updating in GridView

I have a GridView status with a DropDownList that is Yes or No.

开发者_C百科

After updating that status column. I have to count Total number Yes in that grid and popup the message that 90% records updated and saved successfully.

I've saved the records successfully, but how do I count the number of Yes choices in the status column?


Hi Madhu You will have to loop through all the rows and its all Cells to check if is null or not, and if you have template column and if it has control inside it like Label or TextBox than you will have to use FindControl method to get its value but if they are just bound column you can easily get it by following

foreach (GridViewRow dr in grd.Rows)
{
       foreach (TableCell td in dr.Cells)
       {
           if (td.Text=="Yes")
           count++;
       }
}

now if you have template column just remove second loop of cells and just use dr.FindControl to find the control and check if its null or not

let me know

Thanks


You can try like this

foreach (GridViewRow GVRow in GridView1.Rows)
    {

      Dropdown d = (Dropdown)GVRow.FindControl("DropdownID");

      if(d.SelectedItem.Text=="Yes")
      {
         Count++;
      }

    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜