开发者

checkBox in gridView

开发者 https://www.devze.com 2023-02-26 05:22 出处:网络
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++)

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

精彩评论

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