当前位置:编程学习 > C#/ASP.NET >>

我用gridview插件为什么显示不出来表格啊

<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage" %>

<%@ Register assembly="FlexiGrid" namespace="FlexiGrid" tagprefix="cc1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
   <title>UserInfo</title>
    <!--布局js-->
    <script src="../../Content/Scripts/Common/jquery-1.4.1-vsdoc.js" type="text/javascript"></script>
    <!--FlexiGrid插件样式-->
    <link href="../../Content/Scripts/FlexiGrid/css/contextmenu.css" rel="stylesheet"type="text/css" />
    <link href="../../Content/Scripts/FlexiGrid/css/flexigrid.css" rel="stylesheet" type="text/css" />
    <link href="../../Content/Scripts/FlexiGrid/css/main.css" rel="stylesheet" type="text/css" />
    <!--ymPrompt插件样式-->
    <link href="../../Content/Scripts/ymPrompt/skin/dmm-green/ymPrompt.css" rel="stylesheet"type="text/css" />
    <!--ymPrompt插件js-->
    <script src="../../Content/Scripts/ymPrompt/ymPrompt.js" type="text/javascript"></script> 
    <!--MyJs的js-->
    <script src="../../Content/Scripts/MyJs/ChkItem.js" type="text/javascript"></script>

    <script type="text/javascript">
        //数据加载
        function load() {
            tableId = "showData";  //页面上<table>的id(必须设定)
            title = "用户信息";     //标题
            pageSize = 3; //每页显示的数据数量
            showCheckbox = true; //是否显示复选框
            width = "auto"; //宽度(auto表示根据每列的宽度自动计算)
            height = 330;   //高度
            ajaxUrl = '<%=Url.Action("AjaxGetUserInfo") %>';   //异步请求服务器路径(必须设定)

            //按钮
            buttons = new Array(
                new button("Add", "添加用户", "Add"),
                new button("Delete", "删除用户", "Delete")
            )

            //右键菜单
            menus = new Array(
                new rightKeyMenu("修改", "../../Content/Scripts/FlexiGrid/css/images/icons/edit.png", "Update"),
                new rightKeyMenu("重置密码", "../../Content/Scripts/FlexiGrid/css/images/icons/chk.gif", "RestPwd"),
                new rightKeyMenu("删除", "../../Content/Scripts/FlexiGrid/css/images/icons/rowdelete.png", "Delete"),
                new rightKeyMenu("刷新", "../../Content/Scripts/FlexiGrid/css/images/icons/table_refresh.png", "Refurbish")
            )

            //列
            cells = new Array(
                new cell("用户名", "UserName", 100, true, "left", null),
                new cell("真实姓名", "UserTrueName", 100, true, "left", null),
                new cell("角色", "RoleId", 100, true, "left", null),
                new cell("备注", "Remark", 150, true, "left", null)
            )

            //右键菜单的点击事件
            menuItem_click = function (cmd, cell, id) {
                //右键修改用户信息
                if (cmd == "Update") {
                    if (<%=ViewData["roleId"] %> ==1) {
                        ymPrompt.win({ message: '<%=Url.Action("UserInfoHandlerPage/'+id+'")%>', width: 460, height: 310, title: '修改用户信息', handler: null, maxBtn: true, minBtn: true, iframe: true });
                    } else {
                        alert("对不起!你没有权限修改用户!");
                    }
                }
                //右键用户信息
                if (cmd == "Delete") {
                    if (<%=ViewData["roleId"] %> ==1) {
                        if (confirm("你确定要删除用户 [ " + cell[1] + " ] 吗?")) {
                            $.post("/UserManger/AjaxDeleteUser", { id: id }, function (msg) {
                                alert(msg);
                                $("#showData").flexReload();
                            });
                        }
                    } else {
                        alert("对不起!你没有权限删除用户!");
                    }

                }

                //重置密码
                if (cmd == "RestPwd") {
                    if(<%=ViewData["userId"] %> ==id){
                    ymPrompt.win({ message: '<%=Url.Action("RestPwdPage/'+id+'")%>', width: 460, height: 210, title: '重置密码', handler: null, maxBtn: true, minBtn: true, iframe: true });
                    }else{
                        alert("对不起!你没有权限重置"+cell[1]+"的密码!");
                    }

                }

                //右键刷新用户信息
                if (cmd == "Refurbish") {
                    $("#showData").flexReload();
                }
            }

            //头部按钮的点击事件
            button_click = function (cmd, grid) {
                //头部按钮添加用户信息
                if (cmd == "Add") {
                    if (<%=ViewData["roleId"] %> ==1) {
                        ymPrompt.win({ message: '<%=Url.Action("UserInfoHandlerPage")%>', width: 460, height: 310, title: '添加用户', handler: null, maxBtn: true, minBtn: true, iframe: true });
                    } else {
                        alert("对不起!你没有权限添加用户!");
                    }
                }

                //头部按钮删除用户
                if (cmd == "Delete") {
                    if (<%=ViewData["roleId"] %> ==1) {
                        if (confirm("你确定要删除这些用户吗?")) {
                            getChecked();
                            if (falg) {
                                $.post('<%=Url.Action("DeleteUsers")%>', "ids=" + chkValue, function (e) { e == "success" ? alert("删除用户成功!") : alert(e); $("#showData").flexReload(); })
                            }
                        }
                    } else {
                        alert("对不起!你没有权限删除用户!");
                    }
                }
            }
            //加载
            flexiGridLoad();
        }


        $(document).ready(function () {
            load();
            //搜索
            $("#btnSearch").click(function () {
                var key = $("#txtUserName").val();
                query = key;

                $("#div_table").remove();
                var tab = document.createElement("table");
                tab.id = "showData";
                var div = document.createElement("div");
                div.id = "div_table";
                div.appendChild(tab);
                $("#content").append(div);
                load();
            });

            //刷新
            $("#btnrRfresh").click(function () {
                window.navigate(location);
            });
        })
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div style=" height:40px; background-image:url('../../Images/headbg.gif'); font-size:14px; font-weight:bold;">
    <table align="center">
        <tr>
            <td><asp:Image ID="Image1" runat="server" ImageUrl="~/Images/search.gif" /></td>
            <td>姓名:</td>
            <td> 
                <input id="txtUserName" type="text" style=" border:1px solid #B6CEED; width:106px;" />
            </td>
            <td>
                <input id="btnSearch" type="button" value=" 查 询 " class="btnStyle"  />  
            </td>
            <td>
                <input id="btnrRfresh" type="button" value=" 刷 新 " class="btnStyle" />
            </td>
        </tr>
    </table>  
    </div> 
    <div id="content">
        <div id="div_table">
            <table id="showData">
            </table>
        </div>
    </div>
    <cc1:FlexiGrid ID="FlexiGrid1" runat="server" />   
    </form>
</body>
</html>

*********************************

我用的是mvc2 --------------------编程问答-------------------- 后台:
#region 用户管理

        /// <summary>
        /// 用户信息主页面
        /// </summary>
        /// <returns></returns>
        public ActionResult UserInfo()
        {
            ////UserInfo user = (UserInfo)Session["user"];
            ////if (user != null)
            ////{
            ////    ViewData["roleId"] = user.RoleId;
            ////    ViewData["userId"] = user.UserId;
            ////}
            return View();
        }

        /// <summary>
        /// 右键根据用户编号显示用户详细信息
        /// </summary>
        /// <returns></returns>
        public ActionResult UserInfoViewPage(string id)
        {
            return View();
        }

        /// <summary>
        /// 用户信息操作页面
        /// </summary>
        /// <returns></returns>
        public ActionResult UserInfoHandlerPage(string id)
        {
            var roleList = new List<object> { new { text = "--请选择--", value = "0" } };
            var role = rs.GetAllRoleInfo();
            foreach (var r in role)
            {
                var item = new { text = r.RoleName, value = r.RoleId.ToString() };
                roleList.Add(item);
            }
            ViewData["RoleId"] = new SelectList(roleList, "value", "text");
            if (!string.IsNullOrEmpty(id))
            {
                var user = us.GetUserInfoById(int.Parse(id));
                ViewData["UserName"] = user.UserName;
                ViewData["UserPassword"] = user.UserPassword;
                ViewData["UserTrueName"] = user.UserTrueName;
                ViewData["RoleId"] = new SelectList(roleList, "value", "text", user.RoleId.ToString());
                ViewData["Remark"] = user.Remark;
                ViewData["hid"] = id;
            }
            return View();
        }

        /// <summary>
        /// 密码重置页面
        /// </summary>
        /// <returns></returns>
        public ActionResult RestPwdPage(string id)
        {
            if (!string.IsNullOrEmpty(id))
            {
                var user = us.GetUserInfoById(int.Parse(id));
                ViewData["UserName"] = user.UserName;
                ViewData["UserPassword"] = user.UserPassword;
                ViewData["UserTrueName"] = user.UserTrueName;
                ViewData["RoleId"] = user.RoleId;
                ViewData["Remark"] = user.Remark;
                ViewData["hid"] = id;
            }
            return View();
        }


        /// <summary>
        /// 按条件查询用户
        /// </summary>
        /// <param name="from"></param>
        /// <returns></returns>
        public JsonResult AjaxGetUserInfo(FormCollection from)
        {
            var view = new PageView(from);
            List<UserInfo> list = null;
            string userName = view.Query;
            if (string.IsNullOrEmpty(userName))
            {
                list = us.GetUserInfo();
            }
            else
            {
                list = us.GetUserInfoByTureName(userName);
            }

            //分页数据
            var result = list.Skip(view.PageSize * (view.PageIndex - 1)).Take(view.PageSize);
            //构建表格
            DataTable dt = new DataTable();
            DataColumn dc1 = new DataColumn("UserId", typeof(int));
            DataColumn dc2 = new DataColumn("UserName", typeof(string));
            DataColumn dc3 = new DataColumn("UserTrueName", typeof(string));
            DataColumn dc4 = new DataColumn("RoleId", typeof(string));
            DataColumn dc5 = new DataColumn("Remark", typeof(string));

            dt.Columns.AddRange(new DataColumn[] { dc1, dc2, dc3, dc4, dc5 });
            //添加数据
            foreach (var item in result)
            {
                IsAtOnceLoad.IsLazyLoad = true;
                DataRow dr = dt.NewRow();
                RoleInfo role = rs.GetRoleInfoById(int.Parse(item.RoleId.ToString()));
                dr["UserId"] = item.UserId;
                dr["UserName"] = item.UserName;
                dr["UserTrueName"] = item.UserTrueName;
                dr["RoleId"] = role.RoleName;
                dr["Remark"] = item.Remark;

                dt.Rows.Add(dr);
            }
            GetDataHelper gdh = new GetDataHelper();
            return Json(gdh.GetFlexiGridData(view, dt, list.Count));
        }

        /// <summary>
        /// 右键修改用户
        /// </summary>
        /// <param name="dept"></param>
        /// <returns></returns>
        [HttpPost]
        public string AjaxEditUser(FormCollection collection)
        {
            try
            {
                string user = collection["userInfo"];
                JavaScriptSerializer js = new JavaScriptSerializer();
                UserInfo u = js.Deserialize<UserInfo>(user);
                us.UpdateUserInfo(u);
                return "success";
            }
            catch (Exception)
            {
                return "error";
            }
        }

        /// <summary>
        /// 右键删除部门信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public string AjaxDeleteUser(string id)
        {
            try
            {
                us.DeleteUserInf0(int.Parse(id));
                return "success";
            }
            catch (Exception)
            {
                return "error";
            }
        }

        /// <summary>
        /// 右键重置密码
        /// </summary>
        /// <param name="collection"></param>
        /// <returns></returns>
        public string AjaxResetPwd(FormCollection collection)
        {
            try
            {
                UserInfo user1 = (UserInfo)Session["user"];
                string user = collection["userInfo"];
                JavaScriptSerializer js = new JavaScriptSerializer();
                UserInfo u = js.Deserialize<UserInfo>(user);
                us.UpdateUserInfo(u);
                return "success";
            }
            catch (Exception)
            {

                return "error";
            }
        }

        /// <summary>
        /// 按钮添加部门
        /// </summary>
        /// <param name="dept"></param>
        /// <returns></returns>
        [HttpPost]
        public string AjaxAddUser(FormCollection collection)
        {
            try
            {
                string user = collection["userInfo"];
                JavaScriptSerializer js = new JavaScriptSerializer();
                UserInfo u = js.Deserialize<UserInfo>(user);
                us.AddUserInfo(u);
                return "success";
            }
            catch (Exception)
            {
                return "error";
            }
        }

        /// <summary>
        /// 按钮删除部门
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        [HttpPost]
        public string DeleteUsers(string ids)
        {
            try
            {
                var id = ids.Split(',');
                for (int i = 0; i < id.Length - 1; i++)
                {
                    if (!string.IsNullOrEmpty(id[i]))
                    {
                        us.DeleteUserInf0(int.Parse(id[i]));
                    }
                }
                return "success";
            }
            catch (Exception)
            {
                return "error";
            }
        }

        #endregion

--------------------编程问答-------------------- 请高手帮帮忙啊 --------------------编程问答-------------------- 错了我用的是MVC+Flexigrid+Linq to sql 
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,