开发者

Iterating through a GridView to find a row's binded text

I need to iterate through a GridView and find the value of the Eval("name") column of each selected row.

Code:

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


Try it this way (use your control and ID):

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜