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

gridview根据权限做出edit是否能进行,可以根据情况显示edit模式或者提供edit事件

我现在根据条件查询出一组数据,但这里面根据权限,可能有些行是可编辑的,有些行是不可编辑的,是否有方法控制那些不可编辑的行前面那个edit链接隐藏或者失效(不是那一列,因为我那里面还有new链接)。谢谢
--------------------编程问答-------------------- up --------------------编程问答-------------------- 可以控制.对于不可以编辑的行之后在代码里用普通文字替换一下那个链接就可以了. --------------------编程问答-------------------- 在RowDataBound写方法,做判断

<asp:GridView ID="gvRole" runat="server" AutoGenerateColumns="False" Width="100%" DataKeyNames="RoleID" OnRowCancelingEdit="gvRole_RowCancelingEdit" OnRowDeleting="gvRole_RowDeleting" OnRowEditing="gvRole_RowEditing" OnRowUpdating="gvRole_RowUpdating" OnRowDataBound="gvRole_RowDataBound">
                            <Columns>
                                <asp:BoundField DataField="RoleName" HeaderText="角色名称" />
                                <asp:BoundField DataField="Remark" HeaderText="描述" />
                                <asp:TemplateField ShowHeader="False" HeaderText="编辑">
                                    <EditItemTemplate>
                                        <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" CommandName="Update"
                                            Text="更新"></asp:LinkButton>
                                        <asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Cancel"
                                            Text="取消"></asp:LinkButton>
                                    </EditItemTemplate>
                                    <ItemTemplate>
                                        <asp:LinkButton ID="lbtEdit" runat="server" CausesValidation="False" CommandName="Edit"
                                            Text="编辑"></asp:LinkButton>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="删除">
                                    <ItemTemplate>
                                        <asp:LinkButton ID="lbtDelete" runat="server" CausesValidation="False" CommandName="Delete" OnClientClick = "return confirm('确定要删除这行数据吗?');"
                                            Text="删除"></asp:LinkButton>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="权限">
                                    <ItemTemplate>
                                        <asp:HyperLink ID="Right" runat="server" NavigateUrl='<%# Eval("RoleID", "MenuRight.aspx?RoleID={0}") %>' 
                                            Text="权限"></asp:HyperLink>
                                    </ItemTemplate>
                                </asp:TemplateField>
                            </Columns>
                        </asp:GridView>



protected void gvRole_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            try
            {
                LinkButton button = (LinkButton)e.Row.FindControl("lbtDelete");
                button.Visible = base.CheckAuth("RoleIndex.aspx", "lbtDelete");//CheckAuth是我写的一个方法 你可以把自己的方法加到这里 会达到你想要的效果
                HyperLink link = (HyperLink)e.Row.FindControl("Right");
                link.Visible = base.CheckAuth("RoleIndex.aspx", "Right");
                button = (LinkButton)e.Row.FindControl("lbtEdit");
                button.Visible = base.CheckAuth("RoleIndex.aspx", "lbtEdit");
            }
            catch
            {
            }
        }
        else
        {
            DataControlRowType rowType = e.Row.RowType;
        }
    }
补充:.NET技术 ,  ASP.NET
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,