Note that there are some explanatory texts on larger screens.

plurals
  1. POEdit visibility of a cell in GridView based on a value in the row
    primarykey
    data
    text
    <p>I'm trying to set a my delete button visibility to true when the value of the last cell in row is equal to the session value which is the userID</p> <p><strong>Girdview UPDATED:</strong> </p> <pre><code>&lt;Columns&gt; &lt;asp:TemplateField&gt; &lt;ItemTemplate&gt; &lt;%# Container.DataItemIndex + 1 %&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;asp:BoundField DataField="attachID" HeaderText="Attachment ID" SortExpression="atID" HeaderStyle-CssClass="hidcol" ItemStyle-CssClass="hidcol"/&gt; &lt;asp:BoundField DataField="attachmentTitle" HeaderText="Attachment Title" SortExpression="attachmentTitle" /&gt; &lt;asp:BoundField DataField="attachmentType" HeaderText="Attachment Type" SortExpression="attachmentType" /&gt; &lt;asp:BoundField DataField="attachmentDescription" HeaderText="Attachment Description" SortExpression="attachmentDescription" /&gt; &lt;asp:BoundField DataField="attachmentDate" HeaderText="Attachment Date" SortExpression="attachmentDate" /&gt; &lt;asp:TemplateField&gt; &lt;ItemTemplate&gt; &lt;asp:LinkButton ID="LinkButton1" runat="server" CommandName="download" CommandArgument='&lt;%# Eval("attachmentFile") %&gt;'&gt;&lt;img src="CSS/images/download.png" alt="Download File" /&gt;&lt;/asp:LinkButton&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;asp:TemplateField ShowHeader="False"&gt; &lt;ItemTemplate&gt; &lt;asp:ImageButton ID="ImageButton1" runat="server" CausesValidation="False" CommandArgument='&lt;%# Eval("userID") %&gt;' CommandName="Delete" ImageUrl="~/CSS/images/delete_page.png" Text="Delete" /&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;/Columns&gt; </code></pre> <p>I'm trying to set the Delete button property visibile if the <code>userID</code> machates the <code>session["username"]</code></p> <p>I'm not sure this is the right way or not.</p> <p><strong>Code-Behind UPDATED:</strong></p> <pre><code>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; } } } } </code></pre> <p>How can i make it happen ? </p> <p>thanks in advance!</p> <p><strong>The Code has been Updated</strong></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload