动态给gridview添加一行

        //public void AddRowsToGridView()
        //{
        //    int num = GridView1.Rows.Count;
        //    int RowNum = GridView1.Rows.Count;
        //    //for (int i = 0; i < num; i++)
        //    //{
        //    //    string str = GridView1.Rows[i].Cells[9].Text;
        //    //    if (GridView1.Rows[i].Cells[9].Text == "未处理")
        //    //    {
        //    //        RowNum++;
        //    //    }
        //    //}

        //    int sumRow = DBHelper.GetScalar("select count(Id) from N_UserGetCash where State=0");
        //    int updateRow = sumRow - RowNum;
        //    if (updateRow > 0)
        //    {
        //        DataTable dt = DBHelper.GetDataSet(" select  N_UserGetCash.UserId,N_User.UserName,N_UserGetCash.Money,N_User.PayBank,N_User.PayName,N_User.PayAccount,N_UserGetCash.Msg,N_UserGetCash.STime,N_UserGetCash.State,N_UserGetCash.Id from N_UserGetCash,n_user where N_UserGetCash.State=0 and N_UserGetCash.UserId=n_user.Id order by STime desc");
        //        for (int i = 0; i < dt.Rows.Count; i++)
        //        {
        //            GridViewRow row = new GridViewRow(0, 0, DataControlRowType.Separator, DataControlRowState.Normal);
        //            for (int j = 0; j < dt.Columns.Count; j++)
        //            {
        //                TableCell cell = new TableCell();
        //                if (j == 8)
        //                {
        //                    cell.Text = "未处理";
        //                }
        //                else if (j == 9)
        //                {
        //                    cell.Text = " <a href='User_GetCash_Ok.aspx?Id=" + dt.Rows[i][j].ToString() + "'>确认放款</a> <br /><a href='javascript:User_GetCash_No.aspx?Id=" + dt.Rows[i][j].ToString() + "'>拒绝放款</a>";
        //                }
        //                else
        //                {
        //                    cell.Text = dt.Rows[i][j].ToString();
        //                }
        //                row.Cells.Add(cell);
        //            }
        //            row.Visible = true;
        //            GridView1.Controls[0].Controls.AddAt(-1, row);
        //        }
        //    }
        //}

  js 代码操作

 function AddRowsToGridView() {
            var table = document.getElementById('GridView1');
            var RowCount = table.rows.length;
            $.ajax({
                url: "asyn/AddRowsToGridView.ashx",
                data: { "RowCount": RowCount },
                type: "post",
                success: function (msg) {
                    if (msg != "no") {
                        $("#GridView1 tbody tr").text("").find(":not(:first)").remove();
                        var data = eval("(" + msg + ")");
                        for (var i = 0; i < data.length; i++) {
                            $("<tr> <td style='width: 60px;' align='center'>  "
                            + data[i].UserId +
                            "</td><td style='width: 100px;' align='center'>"
                                                    + data[i].UserName +
                                                    "</td><td style='width: 80px;' align='center'>"
                                                    + data[i].Money
                                                    + "</td><td style='width: 80px;' align='center'>" +
                                                   data[i].PayBank
                                                    + "</td><td style='width: 80px;' align='center'>" +
                                                    data[i].PayName
                                                    + "</td><td style='width: 150px;' align='center'>"
                                                     + data[i].PayAccount + " </td><td>"
                                                      + data[i].Msg + " </td><td style='width: 150px;' align='center'> "
                                                    + getNowFormatDate(data[i].STime)
                                                      + " </td><td style='width: 80px;' align='center'><font color='red'>未处理</font></td><td style='width: 80px;' align='center'> <a href='User_GetCash_Ok.aspx?Id= " + data[i].UserId + "'>确认放款</a> <br><a href='User_GetCash_No.aspx?Id= " + data[i].UserId + "'>拒绝放款</a></td></tr>").insertBefore($("#GridView1 tbody tr:eq(1)"));
                        }
                    }

                }
            });

 

posted @ 2013-12-23 09:48  低调的小磁铁  阅读(1459)  评论(0编辑  收藏  举报