Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 为不同用户更改gridview中按钮的可见性_C#_Asp.net_Gridview - Fatal编程技术网

C# 为不同用户更改gridview中按钮的可见性

C# 为不同用户更改gridview中按钮的可见性,c#,asp.net,gridview,C#,Asp.net,Gridview,我有一个gridview的评论,其中显示了一个删除按钮,用于删除登录用户的评论。我的意思是登录用户只能删除自己的评论。 我试过下面的方法,但它没有为任何用户显示删除按钮 <asp:GridView ID="GridView1" runat="server" GridLines="None" AutoGenerateColumns="False" Width="540px" ShowHeader="False" CellPadding="4" ForeColor="Black" OnRow

我有一个gridview的评论,其中显示了一个删除按钮,用于删除登录用户的评论。我的意思是登录用户只能删除自己的评论。 我试过下面的方法,但它没有为任何用户显示删除按钮

 <asp:GridView ID="GridView1" runat="server" GridLines="None" AutoGenerateColumns="False" Width="540px" ShowHeader="False" CellPadding="4" ForeColor="Black" OnRowCommand="GridView1_RowCommand" DataKeyNames="CommentId">
                        <EmptyDataTemplate>
                            ---No comments on this event---
                        </EmptyDataTemplate>
                        <Columns>
                        <asp:TemplateField>
                        <ItemTemplate>
                            <table style="width:540px;background-color:white">
                                <tr>
                                    <td style="width:60px" rowspan="3">
                                        <asp:Image ID="imgUser" Width="50px" Height="50px" ImageUrl='<%# Bind("ProfilePicPath") %>' runat="server" style="border: 2px inset #C0C0C0" />
                                    </td>
                                    <td style="width:480px;border-bottom:solid 1px #999999">
                                        <asp:Label ID="lblCommentator" runat="server" Text='<%# Bind("FirstName") %>' style="color: #336699"></asp:Label>
                                        &nbsp;on
                                        <asp:Label ID="lblCommentTime" runat="server" Text='<%# Bind("CommentTime") %>' style="font-weight: 700"></asp:Label>
                                    </td>
                                </tr>
                                <tr>
                                    <td style="width:480px;vertical-align:top">
                                        <asp:Label ID="lblComment" runat="server" Text='<%# Bind("Comment") %>'></asp:Label>
                                    </td>
                                </tr>
                                <tr>
                                    <td style="width:480px;vertical-align:top;text-align:right">
                                        &nbsp;<asp:HiddenField ID="hfUserId" Value='<%# Bind("UserId") %>' runat="server" />
                                        <asp:LinkButton ID="btnDeleteComment" runat="server" Visible='<%# Session["UserId"] == Eval("UserId") %>' CommandArgument='<%#Eval("CommentId")%>' CommandName="Delete">Delete</asp:LinkButton>
                                    </td>
                                </tr>
                            </table>
                        </ItemTemplate>
                        </asp:TemplateField>
                        </Columns>
                        </asp:GridView>
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:SportsActiveConnectionString %>" SelectCommand="spExtractEventComments" SelectCommandType="StoredProcedure">
                <SelectParameters>
                    <asp:ControlParameter Name="Eventid" Type="Int32" ControlID="lblEventId" />
                </SelectParameters>
            </asp:SqlDataSource>

---对此事件没有任何评论---
在…上
删除
正如您在上面看到的,我正在将当前用户(存储在会话中)与该注释的UserId进行比较

  <asp:LinkButton ID="btnDeleteComment" runat="server" Visible='<%# Session["UserId"] == Eval("UserId") %>'.....
有一个例子:

vb.net :
<asp:LinkButton ID="btnDeleteComment" runat="server" Visible='<%# If(Session("UserId") = Eval("UserId"), "True", "False")%>'></asp:LinkButton>

c# (I think) :
<asp:LinkButton ID="btnDeleteComment" runat="server" Visible='<%# If(Session["UserId"] == Eval("UserId").ToString() ? true : false)%>'></asp:LinkButton>
vb.net:
(我认为):
使用
如果
检查值是否匹配(已测试且正常工作)


If(条件,如果结果为真,做你想做的,如果结果为假,做你想做的)

UserID
可以是任何数字(1,5144,…)@nelek-UserID是nvarchar…类似于PL00124的东西,谢谢。是的,就是这样。我在c#方面很弱,所以我只是使用在线转换器从vb.net转换。@MukeshPanwar如果这个答案对您有帮助,请标记它,这样其他开发人员就不会再浪费时间阅读您的问题了。