datagridview绑定权限表.选中后再进行判断使其选中
你自己已经把实现逻辑给说了.现在是什么问题.
不会是要具体代码吧!
你自己已经把实现逻辑给说了.现在是什么问题.
不会是要具体代码吧!
解决方案 »
- C#2008中不能远程连接SQL2000
- C#编译的程序、程序集如何避免反编译???
- 文本框变灰色,不可输入
- 【求助专家】请问OpenFileDialog 是否可以设置读取默认文件夹路径
- 利用sendRequest传递url时关键字(中文)出现乱码
- 关于Audio播放器的问题?
- 请问谁用asp.net做过Web聊天室或在Web页中聊天的程序
- 求一个测试题答案和解释 重要的是解释
- 请问有没有根据Sql Server2000的数据库,自动生成数据访问层代码的工具呀,在那里可以下载呀,谢谢!!!
- 谁有c#在线邮件收发系统?推荐也有分!!!!!!!!
- globel.asax在线统计的问题——急
- c# 调用delphi dll 传结构体参数
楼主是不是要这样,在 OnRowUpdating事件中处理,传递当前GridView,对比角色中的权限,并显示SetBitValue(gv, "chkView",pb,Permission.View); public void SetBitValue(GridView gv, string id, PermissionBase pb, Permission p)
{
if(gv.EditIndex==-1)return; CheckBox cb = gv.Rows[gv.EditIndex].FindControl(id) as CheckBox;
if (cb == null)
return;
if (cb.Checked)
{
pb.SetBit(p);
}
else
{
pb.Deny(p);
}
}
遍历dgv你应该没有问题吧.
遍历过程中进行比较,相等就选中以下是选中的代码[code=C#]DataGridViewCheckBoxCell cbh = (DataGridViewCheckBoxCell)this.DataGridView1.Rows[count].Cells["你的选中列(DataGridViewCheckBoxCell)"];
this.DataGridView1.Rows[count].Cells["你的选中列(DataGridViewCheckBoxCell)"].Value = true;
code]
。。遍历dgv这是什么啊?怎么你的代码没有sql查询语句啊?。。这样子能行吗。。
不知道如何回答你了.。。我的那个代码就只是绑定了一下dropdownlist,还有gridview,往下就不知道怎么写了。。你得一步步来.
你先理清实现的思路,写出来.帮你实现吧!
我这么清楚说dropdownlist。。
select power_id from UserRole where userId=dropdownlist1.selectedselect power_id from RoleName这样子对吗?。。然后用dr读取上面的值进行对比?
1.dropdownlist的SelectedIndexChanged事件下获得当前选中用户的id,
并查询数据库得到该用户所拥有的权限的id,假设是个List<string> lStr,里面存放的是该用户的权限(字符串什么的都可以),把这个数字设置为属性 私有的,
2.gridview 有一个datarowbound方法 在这个方法里面判断 如果当前行的权限存在于数组中 就设置checkbox的属性为选中状态 代码大概如下
List<string> lStr=new List<string>();
SelectedIndexChanged(){
//查询该用户ID对应的权限
lStr=GetPurviewByUserID(userid);
BindGV();
}
BindGV(){
//查询所有权限绑定gridview} protected void gv_RowDataBound(object sender, GridViewRowEventArgs e){
if (e.Row.RowType == DataControlRowType.DataRow){
//这个地方保证该行是数据绑定行 不是表头或者表尾等
DataRowView drv = (DataRowView)e.Row.DataItem;
if(lStr.Contains(drv["PurviewID"].tostring())){//PurviewID是个列名
Checked chchkPurviewk = e.Row.FindControl("chkPurview") as Checked;
//chkPurview 是该行checkedbox控件的id
chchkPurviewk.checked=true;
}
}}希望能对你有帮助 注意绑定gridview数据源的时候 数据集中要有PurviewID列名
最好下拉框和页面都用
<asp:UpdatePanel ID="up" runat="server" ><ContentTemplate> </ContentTemplate></asp:UpdatePanel>
包裹起来 还有什么疑问可以 加我qq 67780558