GridView,DataList,Repeater,DetailsView的遍历行代码

foreach (DataListItem dli in DataList1.Items)
        {

            string id = DataList1.DataKeys[dli.ItemIndex].ToString();
            Response.Write("<script>alert('" + id + "')</script>");

        }
        foreach (DetailsViewRow dvr in DetailsView1.Rows)
        {

            string id = DetailsView1.DataKeys[dvr.RowIndex].Value.ToString();
            // string s = dvr.Cells[0].Text;
            Response.Write("<script>alert('" + id + "')</script>");

        }
        foreach (RepeaterItem ri in Repeater1.Items)
        {

            string id = Repeater1.DataKeys[ri.ItemIndex.ToString();
            Response.Write("<script>alert('" + id + "')</script>");

        }
        foreach (GridViewRow drv in GridView1.Rows)
        {
            string id = GridView1.DataKeys[drv.RowIndex].Value.ToString();
            // string s = drv.Cells[0].Text;
            Response.Write("<script>alert('" + id + "')</script>");
        }

posted @ 2009-07-21 17:15  大牛博客  阅读(585)  评论(0编辑  收藏  举报