佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

12
返回列表 发新帖
楼主: 可可妹

ASP.NET - 做一个control user access right的module

[复制链接]
发表于 25-5-2009 10:08 PM | 显示全部楼层
原帖由 可可妹 于 25-5-2009 08:49 PM 发表


我的access right是放在 SQL database的.

请问page load not is post back是什么意思呢?
其实Bind 是什么意思呢?我的girdview,加了item template - checkbox,然后可以binding的,可是我不明白这是做什么的 ...

原帖由 可可妹 于 25-5-2009 08:49 PM 发表

我的access right是放在 SQL database的.

请问page load not is post back是什么意思呢?
其实Bind 是什么意思呢?我的girdview,加了item template-checkbox,然后可以binding的,可是我不明白这是做什么的,曾经在form 的check box,放checked=<%#bind(ID)%>但是做不到什么。。  


我尝试把我知道的让你明白。
     If not Me.IsPostBack Then

     End If

Meanif you fire a control like dropdownlist textchange event orbuttonclicked event it will cause the postback to render at server page(codebehind)

if not me.ispostback -- > mean when page_loadis not caused bypostback what the statement will execute. mostly wewill specified notis postback when we would like to initial setting forthe page. It willexecute only a time if the page redirected.SoIsPostback tells uswhether this is the first time the page hasbeenrequested, or whether the page is being run as the result of ausersubmitting the page.
(简单的用中文解释就 not ispostback 不是因为user execute submit action, ispostback 就是当user firing submit event.

如果要知道是什么control caused the postback

If Request.Params.Item("Your firing control ID" <> Nothing Then
' bla bla bla
Else
' bla bla bla
End If

或者

Dim PostbackControlA As String = Request.Form("__EVENTTARGET"
‘get postback control name
Dim PostbackControlB As String = Request.Form("__EVENTARGUMENT"
‘get postback control arguments.

bind 就是你把gridview 和 datatable bind 起来。
好像你datatable consist 4 data columns and 4 data rows.当你bind your gridwith datatable。 grid 的 layout will as same as your datatable.
<%# DataBinder.Eval(Container.DataItem, "Id" %> 你可以用这个statement bind with databound
或者 control text like label,textbox and hiddenfield. for controls remember to add the single quote.
我给你一个很多example的网站。

http://mattberseth.com/blog/index.html
回复

使用道具 举报


ADVERTISEMENT

 楼主| 发表于 26-5-2009 10:28 AM | 显示全部楼层
我的gridview + check box是这样的:

aspx file:

    <asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" DataSourceID="UserAccessRight"
        OnSelectedIndexChanged="GridView2_SelectedIndexChanged" DataKeyNames="ID" CellPadding="4" ForeColor="#333333" GridLines="None" Visible="False" Font-Names="Arial" Font-Size="10pt" CaptionAlign="Left" HorizontalAlign="Center" Width="534px">
        <Columns>
            <asp:TemplateField HeaderText="Select">
                <ItemTemplate>
                    <aspheckBox ID="AccessSelection" runat="server" />
                </ItemTemplate>
                <FooterTemplate>
                    &nbsp;
                </FooterTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="ID" HeaderText="ID" SortExpression="ID" />
            <asp:BoundField DataField="function1" HeaderText="Function" SortExpression="function1" />
            <asp:BoundField DataField="priveleges" HeaderText="riveleges" SortExpression="priveleges" />
            <asp:BoundField DataField="description" HeaderText="Description" SortExpression="description" />
            <aspheckBoxField />
        </Columns>
        <EmptyDataTemplate>
            &nbsp;
        </EmptyDataTemplate>
        <RowStyle BackColor="#EFF3FB" HorizontalAlign="Left" VerticalAlign="Middle" />
        <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" HorizontalAlign="Left" VerticalAlign="Top" />
        <agerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Left" />
        <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" HorizontalAlign="Center" VerticalAlign="Middle" />
        <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" HorizontalAlign="Left" />
        <EditRowStyle BackColor="#2461BF" HorizontalAlign="Left" VerticalAlign="Middle" />
        <AlternatingRowStyle BackColor="White" HorizontalAlign="Left" VerticalAlign="Middle" />
        <EmptyDataRowStyle HorizontalAlign="Left" VerticalAlign="Middle" />
    </asp:GridView>

    <asp:SqlDataSource ID="UserAccessRight" runat="server" ConnectionString="<%$ ConnectionStringsocalInventoryConnectionString %>"
        SelectCommand="SELECT FunctionPrivileges.ID, FunctionPrivileges.function1, FunctionPrivileges.description, FunctionPrivileges.priveleges FROM FunctionPrivileges ORDER BY FunctionPrivileges.ID">
    </asp:SqlDataSource>

是不是要在 .aspx.cs的file 直接写RowDataBound?

Protected Sub GridView2_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
        If e.Row.RowType = DataControlRowType.DataRow Then
            Dim chkAuthority As CheckBox = DirectCast(e.Row.Cells(0).FindControl("CheckboxID", CheckBox)
            Dim AccessRight As HiddenField = DirectCast(e.Row.Cells(0).FindControl("hdAccessRight", HiddenField)

            If AccessRight.Value = "Authorized" Then
                chkAuthority.Checked = True
            Else
                chkAuthority.Checked = False
            End If


        End If
    End Sub
回复

使用道具 举报

 楼主| 发表于 26-5-2009 11:50 AM | 显示全部楼层
我做到了:
   protected void GridView2_RowDataBound(object sender, EventArgs e)
    {
        CheckBox chk2;
        string currentID;
        string selectedName = GridView1.SelectedRow.Cells[2].Text;

        {
            foreach (GridViewRow rowItem in GridView2.Rows)
            {
                chk2 = (CheckBox)(rowItem.Cells[0].FindControl("AccessSelection");
                currentID = GridView2.DataKeys[rowItem.RowIndex]["ID"].ToString();

                //    DirectCast(rowItem.Cells(0).FindControl("ID");
                String strAccess = "Select * From UserAccessRight where username = '" + selectedName + "' AND accessRight = '" + currentID + "'";
                DataTable dtAccess = DBObj.QueryDB(strAccess).Tables[0];
                if (dtAccess.Rows.Count == 0)
                {
                    chk2.Checked = false;

                } else {
               
                    chk2.Checked = true;
                }


            }
        
        }



谢谢你 ~!
回复

使用道具 举报

 楼主| 发表于 26-5-2009 11:51 AM | 显示全部楼层
我做到了:
   protected void GridView2_RowDataBound(object sender, EventArgs e)
    {
        CheckBox chk2;
        string currentID;
        string selectedName = GridView1.SelectedRow.Cells[2].Text;

        {
            foreach (GridViewRow rowItem in GridView2.Rows)
            {
                chk2 = (CheckBox)(rowItem.Cells[0].FindControl("AccessSelection");
                currentID = GridView2.DataKeys[rowItem.RowIndex]["ID"].ToString();

                //    DirectCast(rowItem.Cells(0).FindControl("ID");
                String strAccess = "Select * From UserAccessRight where username = '" + selectedName + "' AND accessRight = '" + currentID + "'";
                DataTable dtAccess = DBObj.QueryDB(strAccess).Tables[0];
                if (dtAccess.Rows.Count == 0)
                {
                    chk2.Checked = false;

                } else {
               
                    chk2.Checked = true;
                }


            }
        
        }



谢谢你 ~!
回复

使用道具 举报

 楼主| 发表于 26-5-2009 12:27 PM | 显示全部楼层
可是我遇到一个bug..
当选第一个user, 如果UserAccessRight有他的access right,checkbox 会被 check。
String strAccess = "Select * From UserAccessRight where username = '" + selectedName + "' AND accessRight = '" + currentID + "'";

当选另外一个user, check box 没有被refresh,还是display之前user access right的checking box..
回复

使用道具 举报

 楼主| 发表于 26-5-2009 12:35 PM | 显示全部楼层
可是有一个bug,
就是当选另外一个user时,gridview2 不会被refresh,还是保留第一个 user的access right....
是不是要做Page load is not post back呢?
回复

使用道具 举报

Follow Us
 楼主| 发表于 26-5-2009 12:46 PM | 显示全部楼层
可是有一个bug,
就是当选另外一个user时,gridview2 不会被refresh,还是保留第一个 user的access right....
是不是要做Page load is not post back呢?
回复

使用道具 举报

 楼主| 发表于 26-5-2009 02:29 PM | 显示全部楼层
可是有一个bug,
就是当选另外一个user时,gridview2 不会被refresh,还是保留第一个 user的access right....
是不是要做Page load is not post back呢?
回复

使用道具 举报


ADVERTISEMENT

发表于 26-5-2009 05:52 PM | 显示全部楼层
原帖由 可可妹 于 26-5-2009 11:51 AM 发表
我做到了:
   protected void GridView2_RowDataBound(object sender, EventArgs e)
    {
        CheckBox chk2;
        string currentID;
        string selectedName = GridView1.SelectedRow.Cells[2] ...


Try up  this see weather workable o not. Never tested

{
  • if (e.Row.RowType == DataControlRowType.DataRow) {
  •         CheckBox chk2 = (CheckBox)e.Row.Cells(0).FindControl("AccessSelection");
  •         string currentID = null;
  •         string selectedName = GridView1.SelectedRow.Cells(2).Text;
  •         currentID = GridView2.DataKeys(e.Row.RowIndex)("ID").ToString();
  •         string strAccess = ("Select * From UserAccessRight " + " where username = '" + selectedName + "'" + " AND accessRight = '") + currentID + "'";
  •         DataTable dtAccess = DBObj.QueryDB(strAccess).Tables(0);
  •         if (dtAccess.Rows.Count == 0) {
  •             chk2.Checked = false;
  •         }
  •         else {
  •             chk2.Checked = true;
  •         }
  •     }
  • }
回复

使用道具 举报

发表于 26-5-2009 08:15 PM | 显示全部楼层
我写的回复就这样不见了。。。。。。
回复

使用道具 举报

 楼主| 发表于 29-5-2009 11:56 PM | 显示全部楼层
谢谢zhi xuen,我也是卡贴。。
回复

使用道具 举报

发表于 1-6-2009 12:16 AM | 显示全部楼层
不知道可可妹我的code 能用吗?
你成功了吗?
回复

使用道具 举报

 楼主| 发表于 4-6-2009 10:12 PM | 显示全部楼层
原帖由 zhixuen 于 1-6-2009 12:16 AM 发表
不知道可可妹我的code 能用吗?
你成功了吗?


抱歉迟回复了,
我用了别的方式,就是在 backend code,check 有没有access right, 如有,就check = true,
用你一样的逻辑
谢谢你哦。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 11-12-2025 08:01 PM , Processed in 0.132206 second(s), 21 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表