编辑,删除这些按扭不自带的,如果不是管理员就不应该显示编辑,删除这些按扭。这应该怎么做?

解决方案 »

  1.   

    GridView页面代码:我用的删除按钮是ImageButton<asp:GridView ID="gvw" runat="server" AutoGenerateColumns="False"
                                    Width="100%" CssClass="Grid_Item" DataKeyNames="FeelingsID" OnRowDataBound="gvw_RowDataBound" AllowPaging="True" AllowSorting="True" >
                                    <Columns>   
                                        <asp:BoundField HeaderText="报道标题" DataField="FeelingsTitle" >
                                            <itemstyle horizontalalign="Left" Width="250px" />
                                            <headerstyle horizontalalign="Center" width="250px" />
                                        </asp:BoundField>
                                        <asp:BoundField HeaderText="报道媒体" DataField="Media" >
                                            <itemstyle horizontalalign="Center" />
                                            <headerstyle horizontalalign="Center" width="10%" />
                                        </asp:BoundField>
                                        <asp:BoundField HeaderText="发表日期" DataField="FeelingsPublishDate" >
                                            <itemstyle horizontalalign="Center" />
                                            <headerstyle horizontalalign="Center" width="10%" />
                                        </asp:BoundField>
                                        <asp:BoundField HeaderText="关键词" DataField="KeyWords" >
                                            <itemstyle horizontalalign="Center" Width="80px" />
                                            <headerstyle horizontalalign="Center" width="80px" />
                                        </asp:BoundField>     
                                        <asp:BoundField HeaderText="工作属性" DataField="WrokAttribute" >
                                            <itemstyle horizontalalign="Center" Width="50px" />
                                            <headerstyle horizontalalign="Center" width="50px" />
                                        </asp:BoundField>    
                                        <asp:BoundField HeaderText="事件地点" DataField="Country" >
                                            <itemstyle horizontalalign="Center" Width="130px" />
                                            <headerstyle horizontalalign="Center" width="130px" />
                                        </asp:BoundField>
                                        <asp:TemplateField HeaderText="操作">
                                            <ItemTemplate>
                                                <asp:ImageButton ImageUrl = "../App_Themes/Images/edit.gif" ID="iBtnEdit" runat="server" OnClick="iBtnEdit_Click"/>
                                                <asp:ImageButton ImageUrl = "../App_Themes/Images/bt_icon_del.gif" ID="iBtnDelete" runat ="server" OnClick="iBtnDelete_Click" />
                                                <asp:ImageButton ImageUrl = "../App_Themes/Images/bt_icon_search.gif" ID="iBtnView" runat ="server" OnClick="iBtnView_Click" />
                                            </ItemTemplate>
                                            <ItemStyle HorizontalAlign="Center" Width="100px" />
                                            <HeaderStyle HorizontalAlign="Center" Width="100px" />
                                        </asp:TemplateField>
                                    </Columns>
                                    <AlternatingRowStyle CssClass="altertr" />
                                    <RowStyle CssClass="Grid_Item" />
                                    <PagerSettings Visible="False" />
                                </asp:GridView>你在GridView的gvw_RowDataBound事件中,这样写ImageButton imageBtnDelete = e.Row.Cells[6].FindControl("iBtnDelete") as ImageButton;
    imageBtnDelete.Visible = false;
    就行了。
      

  2.   

    在TemplateField里放一个Button或LinkButton,把它的CommandName属性设置为“Delete”就变成了删除按钮,然后根据你的业务逻辑规则编写代码适当的代码来让它显示或不显示。
    示例如下:<asp:GridView ...>
    <Columns>
      ....
      <asp:TemplateField>
        <ItemTemplate>
           <asp:Button runat="server" CommandName="Delete" CommandArgument='<%# Eval("ArticleID") %>' Visible='<%# ArticleRule.CanDelete(Container.DataItem) %>' Text="删除" />
        </ItemTemplate>
      </asp:TemplateField>
    </Columns>
    </asp:GridView
      

  3.   


    <Columns>
    <asp:CommandField ShowEditButton="True" ShowDeleteButton="True" />
    </Columns>如果在程序里能得到ShowDeleteButton属性,那么就可以将他设为false这样就不显示了,我想知道如何得到这个属性???
      

  4.   

    GridView的RowDataBound事件中
    先找到button,用findcontrol
    然后用声明得button得id 比如 bn 直接做判断,登陆类型就好了如果是管理员 bn.visiable=true
    否则  bn.visiable=false