counter
counter

GridView点击一行 取数据

1.后台添加点击事件
protected
 void gvadm_RowDataBound(object sender, GridViewRowEventArgs e)         {             this.lblCurrentPage.Text = string.Format("当前第{0}页/总共{1}页"this.gvm.PageIndex + 1, this.gvm.PageCount);             //遍历所有行设置边框样式               foreach (TableCell tc in e.Row.Cells)             {                 tc.Attributes["style"] = "border-color:#D9ECFB";             }             if (e.Row.RowIndex != -1)             {                 int id = e.Row.RowIndex + 1;                 e.Row.Cells[0].Text = id.ToString();             }             //执行循环,保证每条数据都可以更新             for (int i = 0; i < gvm.Rows.Count + 1; i++)             {                 //首先判断是否是数据行                 if (e.Row.RowType == DataControlRowType.DataRow)                 {                     //当鼠标停留时更改背景色                     e.Row.Attributes.Add("onmouseover""c=this.style.backgroundColor;this.style.color='red';this.style.backgroundColor='#D9ECFB'");                     //当鼠标移开时还原背景色                     e.Row.Attributes.Add("onmouseout""this.style.backgroundColor=c;this.style.color='black';this.style.backgroundColor=c");                     e.Row.Attributes.Add("id""row_" + i.ToString());                     e.Row.Attributes.Add("onclick""Item_Click(this)");                     e.Row.Attributes["style"] = "Cursor:pointer";                 }             }         }
2.前台赋值
<script type="text/javascript">
        function Item_Click(item) {
            $("#txtCapability").attr("value", item.cells[2].innerText);
            $("#txtAH").attr("value", item.cells[5].innerText);
            $("#txtFOH").attr("value", item.cells[8].innerText);
            $("#txtGAAG").attr("value", item.cells[3].innerText);
            $("#txtSH").attr("value", item.cells[6].innerText);
            $("#txtEUNDH").attr("value", item.cells[9].innerText);
            $("#txtPH").attr("value", item.cells[4].innerText);
            $("#txtUOH").attr("value", item.cells[7].innerText);
        }
    </script>
posted @ 2013-06-28 14:24  bfy  阅读(681)  评论(0编辑  收藏  举报