当行中最后一个单元格的值等于会话值(即用户 ID)时,我正在尝试将我的删除按钮可见性设置为 true
格维更新:
<Columns>
<asp:TemplateField>
<ItemTemplate>
<%# Container.DataItemIndex + 1 %>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="attachID" HeaderText="Attachment ID" SortExpression="atID" HeaderStyle-CssClass="hidcol" ItemStyle-CssClass="hidcol"/>
<asp:BoundField DataField="attachmentTitle" HeaderText="Attachment Title" SortExpression="attachmentTitle" />
<asp:BoundField DataField="attachmentType" HeaderText="Attachment Type" SortExpression="attachmentType" />
<asp:BoundField DataField="attachmentDescription" HeaderText="Attachment Description" SortExpression="attachmentDescription" />
<asp:BoundField DataField="attachmentDate" HeaderText="Attachment Date" SortExpression="attachmentDate" />
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CommandName="download" CommandArgument='<%# Eval("attachmentFile") %>'><img src="CSS/images/download.png" alt="Download File" /></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:ImageButton ID="ImageButton1" runat="server" CausesValidation="False" CommandArgument='<%# Eval("userID") %>' CommandName="Delete" ImageUrl="~/CSS/images/delete_page.png" Text="Delete" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
我正在尝试设置删除按钮属性可见,如果userID
machatessession["username"]
我不确定这是否正确。
代码隐藏更新:
String searchValue = "" + Session["username"];
foreach (GridViewRow row in GridView1.Rows)
{
// Only look in data rows
if (row.RowType == DataControlRowType.DataRow ||
row.RowType == DataControlRowType.EmptyDataRow)
{
// Find the delete button by ID
ImageButton theDeleteButton = row.FindControl("ImageButton1") as ImageButton;
// Verify the button was found before we try to use it
if (theDeleteButton != null)
{
if (theDeleteButton.CommandArgument != searchValue)
{
// Make the button invisible
theDeleteButton.Visible = false;
}
}
}
}
我怎样才能让它发生?
提前致谢!
代码已更新