通过GridView迭代查找行的绑定文本

时间:2011-04-04 13:01:33

标签: asp.net gridview

我需要遍历GridView并找到每个选定行的Eval("name")列的值。

代码:

string title = "";
foreach (GridViewRow row in gdv.Rows)
{
    if (row.BackColor.Equals(Color.LightGoldenrodYellow))
    {
        title += row.Cells[0].Text + ", "; // doesn't work, even though the value i want is in the very first column
    }
}

1 个答案:

答案 0 :(得分:0)

以这种方式尝试(使用您的控件和ID):

    foreach (GridViewRow Row in GridView1.Rows)
    {
        Label MyLabel = Row.FindControl("Label1") as Label;

        if (MyLabel != null)
        {
            Response.Write(MyLabel.Text);
        }
    }