开发者

checkBox in gridView

i am using checkbox in gridview..to get the checkbox id i am using the following code..

    for (int i = 0; i < GridView1.Rows.Count; i++)
    {
        CheckBox chkDelete = (CheckBox)GridView1.Rows.Cells[0].FindControl("chkSelect");
        if (chkDelete != null)
        {
            if (chkDelete.Checked)
            {
                strID = GridView1.Rows.Cells[1].Text;
                idCollection.Add(strID);
            }
    开发者_C百科    }
    }

BUT THE KEYWORD "CELLS"..do not support..i am getting an error.."System.Web.UI.WebControls.GridViewRowCollection' does not contain a definition for 'Cells' "


This is the way you have to check

foreach (GridViewRow grRow in grdACH.Rows)
    {
        CheckBox chkItem = (CheckBox)grRow.FindControl("checkRec");
        if (chkItem.Checked)
        {
            strID = ((Label)grRow.FindControl("lblBankType")).Text.ToString();
         }
}


That's correct; the GridViewRowCollection class does not contain either a method or a property with the name Cells. The reason that matters is that the Rows property of the GridView control returns a GridViewRowCollection object, and when you call GridView1.Rows.Cells, it is searching for a Cells property on the GridViewRowCollection object returned by the Row property.


for (int i = 0; i < GridView1.Rows.Count; i++)
{
    CheckBox chkDelete = (CheckBox)GridView1.Rows[i].FindControl("chkSelect");
    if (chkDelete != null)
    {

        if (chkDelete.Checked)
        {
            strID = GridView1.Rows[i].Cells[1].Text;
            idCollection.Add(strID);
        }
    }
}


 foreach (GridViewRow rowitem in GridView1.Rows)
            {
                CheckBox chkDelete = (CheckBox)rowitem.Cells[0].FindControl("chkSelect");
                if (chkDelete != null)
                {
                    if (chkDelete.Checked)
                    {
                        strID = rowitem.Cells[1].Text;
                        idCollection.Add(strID);
                    }
                }


            }
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜