vb.net中遍历checkbox 权限列表

For Each dgi As DataGridItem In Datagrid1.Items
If (CType(dgi.FindControl("cbcb"), CheckBox).Checked) Then
Dim i As Integer = IIf(CType(dgi.FindControl("cbsel"), CheckBox).Checked.ToString().ToLower() = "true", 1, 0)
Dim j As Integer = IIf(CType(dgi.FindControl("cbadd"), CheckBox).Checked.ToString().ToLower() = "true", 1, 0)
Dim k As Integer = IIf(CType(dgi.FindControl("cbupd"), CheckBox).Checked.ToString().ToLower() = "true", 1, 0)
Dim l As Integer = IIf(CType(dgi.FindControl("cbdel"), CheckBox).Checked.ToString().ToLower() = "true", 1, 0)
Response.Write(Convert.ToString(Datagrid1.DataKeys(dgi.ItemIndex)) & "<br>")
Dim sql As String = String.Format("update powers set sels={0},adds={1},upds={2},dels={3} where id='{4}'", i.ToString(), j.ToString(), k.ToString(), l.ToString(), Convert.ToString(Datagrid1.DataKeys(dgi.ItemIndex)))
db.GetState(sql)
End If
Imports System.Text
Public Class PowersCheck
Inherits System.Web.UI.Page
Public Enum opertor
adds
upds
dels
sels
EndEnum
Public Shared Sub Checks( ByVal userid As String , ByVal parts As String , ByVal oprator As Integer )
Dim db As DbAccess = New DbAccess
Dim sql As StringBuilder = New StringBuilder
sql.Append(
" select " )
Dim edit As String = String .Empty


If oprator = 0 Then
edit
= " adds "
ElseIf oprator = 1 Then
edit
= " upds "
ElseIf oprator = 2 Then
edit
= " dels "
ElseIf oprator = 3 Then
edit
= " sels "
Else
edit
= " sels "
End If

sql.Append(edit)
sql.AppendFormat(
" frompowerswhereuserid='{0}'andpartid='{1}' " ,userid,parts)
Dim sqltemp As String = sql.ToString()
Dim succ As String = db.GetOne(sqltemp)
If succ.ToLower() = " true " Then

Else
HttpContext.Current.Response.Write(
" <scriptlanguage=javascript>alert('没有权限')</script> " )
HttpContext.Current.Server.Transfer(HttpContext.Current.Request.Url.ToString()
& " /login.aspx " )

End If




EndSub

EndClass
< asp:datagrid id ="Datagrid1" runat ="server" Height ="0px" Width ="100%" AllowSorting ="True" Font-Size ="X-Small"
CellPadding
="2" BorderWidth ="1px" BorderStyle ="None" BorderColor ="#93BEE2" BackColor ="White"
AllowPaging
="True" AutoGenerateColumns ="False" DataKeyField ="id" >
< SelectedItemStyle Font-Bold ="True" ForeColor ="#CCFF99" BackColor ="#009999" ></ SelectedItemStyle >
< AlternatingItemStyle Font-Size ="X-Small" HorizontalAlign ="Center" BackColor ="#E8F4FF" ></ AlternatingItemStyle >
< ItemStyle Font-Size ="X-Small" HorizontalAlign ="Center" ForeColor ="#003399" BackColor ="White" ></ ItemStyle >
< HeaderStyle HorizontalAlign ="Center" ForeColor ="White" VerticalAlign ="Middle" BackColor ="#337FB2" ></ HeaderStyle >
< FooterStyle ForeColor ="#003399" BackColor ="#99CCCC" ></ FooterStyle >
< Columns >
< asp:TemplateColumn >
< HeaderStyle Wrap ="False" Width ="5%" ></ HeaderStyle >
< ItemStyle Wrap ="False" HorizontalAlign ="Center" ></ ItemStyle >
< ItemTemplate >
&nbsp;
< asp:CheckBox id ="cbcb" runat ="server" ></ asp:CheckBox >
</ ItemTemplate >
</ asp:TemplateColumn >
< asp:BoundColumn DataField ="username" HeaderText ="姓名" ></ asp:BoundColumn >
< asp:BoundColumn DataField ="partname" HeaderText ="模块" ></ asp:BoundColumn >
< asp:TemplateColumn HeaderText ="查询" >
< ItemTemplate >
< FONT face ="宋体" >
< asp:CheckBox id ="cbsel" runat ="server" Checked ='<%#DataBinder.Eval(Container.DataItem,"sels")% > '>
</ asp:CheckBox ></ FONT >
</ ItemTemplate >
< EditItemTemplate >
< asp:TextBox id ="TextBox1" runat ="server" ></ asp:TextBox >
</ EditItemTemplate >
</ asp:TemplateColumn >
< asp:TemplateColumn HeaderText ="增加" >
< ItemTemplate >
< asp:CheckBox id ="cbadd" runat ="server" Checked ='<%#DataBinder.Eval(Container.DataItem,"adds")% > '>
</ asp:CheckBox >
</ ItemTemplate >
< EditItemTemplate >
< asp:TextBox id ="TextBox2" runat ="server" ></ asp:TextBox >
</ EditItemTemplate >
</ asp:TemplateColumn >
< asp:TemplateColumn HeaderText ="修改" >
< ItemTemplate >
< asp:CheckBox id ="cbupd" runat ="server" Checked ='<%#DataBinder.Eval(Container.DataItem,"upds")% > '>
</ asp:CheckBox >
</ ItemTemplate >
< EditItemTemplate >
< asp:TextBox id ="TextBox3" runat ="server" ></ asp:TextBox >
</ EditItemTemplate >
</ asp:TemplateColumn >
< asp:TemplateColumn HeaderText ="删除" >
< ItemTemplate >
< asp:CheckBox id ="cbdel" runat ="server" Checked ='<%#DataBinder.Eval(Container.DataItem,"dels")% > '>
</ asp:CheckBox >
</ ItemTemplate >
< EditItemTemplate >
< asp:TextBox id ="TextBox4" runat ="server" ></ asp:TextBox >
</ EditItemTemplate >
</ asp:TemplateColumn >
</ Columns >
< PagerStyle NextPageText ="" Font-Size ="X-Small" HorizontalAlign ="Center" ForeColor ="#003399"
BackColor
="#E8F4FF" Mode ="NumericPages" ></ PagerStyle >
</ asp:datagrid >< asp:button id ="Button1" style ="Z-INDEX:101;LEFT:216px;POSITION:absolute;TOP:344px" runat ="server"
Text
="保存" ></ asp:button >
< asp:Button id ="Button2" style ="Z-INDEX:102;LEFT:160px;POSITION:absolute;TOP:344px" runat ="server"
Text
="全选" ></ asp:Button >

你可能感兴趣的:(.net,asp.net,asp,vb,VB.NET)