ASP.NET从数据库中取出数据,有数据的复选框为选中

时间:2021-04-28 15:07:41

在KS系统中在更新菜单的时候,当查出菜单的时候要查出菜单下面已经有了哪些界面了我用了一下的方法弄的。代码如下:

界面代码:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="AdmUpdateMenu.aspx.cs" Inherits="ExamSystemV3.Web.Manager.RoleManager.UpdateMenu" %>

<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="Author" content="kudychen@gmail.com" />
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<title>菜单管理——更新菜单</title>
<link href="../../css/admin.global.css" rel="stylesheet" type="text/css" />
<link href="../../css/admin.content.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../../js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="../../js/jquery.utils.js"></script>
<link href="../../jBox/Skins/Green/jbox.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../../jBox/jquery.jBox-2.3.min.js"></script>
<script type="text/javascript" src="../../js/admin.js"></script>
<script src="../../js/calendar3.js" type="text/javascript"></script>
<script type="text/javascript">
// 设置标题
Index.SetTitle('添加用户'); </script>
</head>
<body>
<form id="form1" runat="server">
<div class="container"> <div class="location">当前位置:菜单管理 -> 更新菜单</div> <div class="blank10"></div> <div class="block">
<div class="h">
<span class="icon-sprite icon-list"></span>
<h3>菜单信息</h3>
<div class="bar">
<a class="btn-lit" href="javascript:Index.Open('list.html');"><span>返回</span></a>
<asp:LinkButton ID="lbtnSaveMenu" class="btn-lit" runat="server" onclick="lbtnSaveMenu_Click"
><span>保存菜单</span></asp:LinkButton>
</div>
</div>
<div class="tl corner"></div><div class="tr corner"></div><div class="bl corner"></div><div class="br corner"></div>
<div class="cnt-wp">
<div class="cnt form"> <table class="data-form" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<th scope="row">菜单名称:</th>
<td><input value="" type="text" name="MenuName" id="MenuName" class="input-normal" runat ="server" /></td>
</tr> <tr>
<th scope="row">菜单描述:</th>
<td><input value="" type="text" name="MenuDescribe" id="MenuDescribe" class="input-normal" runat ="server" /></td>
</tr> </tbody>
</table> </div>
</div>
</div>
</div> <div class="blank10"></div>
<div class="block">
<div class="h">
<span class="icon-sprite icon-list"></span>
<h3>界面列表</h3>
</div>
<div class="tl corner"></div><div class="tr corner"></div><div class="bl corner"></div><div class="br corner"></div> <div class="cnt-wp">
<div class="cnt">
<div class="search-bar"> <div>
<span>界面查询:</span>
<input value="" type="text" name="dateSearch" id="dateSearch" class="input-normal" runat="server" />
<asp:LinkButton ID="lbtnQuery" class="btn-lit" runat="server"
onclick="lbtnQuery_Click"><span>查询</span></asp:LinkButton>
</div> </div>
<table class="data-table history" id="mainTable" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<th scope="col"></th>
<th scope="col">界面描述</th>
</tr> <asp:Repeater ID="rpWindows" runat="server">
<ItemTemplate>
<tr>
<td class="chk">
<asp:CheckBox ID="ckWindowsID" runat="server" />
<asp:HiddenField ID="hfWindows" runat="server" Value='<%#Eval("WindowsID") %>' />
</td>
<td class="txt c"><%#Eval("WindowsDescribe")%></td>
</tr>
</ItemTemplate>
</asp:Repeater>
</tbody>
</table>
</div> <script type="text/javascript">
var pagerUrl = 'list.html?pageIndex={0}';
Pager.Output(pagerUrl, '10', '1', '20', '200'); //(urlFormat, pageSize, pageIndex, pageCount, recordCount)
</script>
</div>
</div>
</div>
</form>
</body>
</html>

后台代码:

  /// <summary>
/// 绑定有权限的界面
/// </summary>
/// <param name="strLike"></param>
public void DataBindPermissionsWindows(string strLike)
{
HiddenField hid;
CheckBox cb;
DataTable dt = new DataTable();
string strWindowsID = "";
BLL.Manager.UserRoleManagerBLL.AdmMenuManager admMenuManager = new BLL.Manager.UserRoleManagerBLL.AdmMenuManager();
dt=admMenuManager.QueryMenuWindows(strLike); //先取出windowsID
for (int i = 0; i < dt.Rows.Count; i++)
{
strWindowsID = dt.Rows[i]["WindowsID"].ToString(); ///将数据库能读出的界面复选框打勾
/////在遍历把符合windowsID的checkbox打勾
foreach (RepeaterItem ri in rpWindows.Items)
{
hid = ri.FindControl("hfWindows") as HiddenField;
cb = ri.FindControl("ckWindowsID") as CheckBox;
if (hid.Value.ToString().Trim() == strWindowsID.ToString().Trim())
{
cb.Checked = true;
}
}
} }