2016-09-20 96 views
0

我試圖隱藏「刪除」鏈接,如果在CUST_ORDER_ID =「X」的價值,但我不知道如何設置visibility屬性爲「False」從代碼更改visibility屬性後面

我ASP。

<Columns> 
<asp:CommandField ShowDeleteButton="True" /> 
<asp:BoundField DataField="ROWID" SortExpression="ROWID" Visible="False">   </asp:BoundField> 
<asp:BoundField DataField="CUST_ORDER_ID" HeaderText="ORDER ID"  SortExpression="CUST_ORDER_ID"> 
<ItemStyle Width="50px"></ItemStyle> 

背後

Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound 
    If e.Row.RowType = DataControlRowType.DataRow Then 
     'check is row non order type and allow user to delete 
     Dim oid As TableCell = e.Row.Cells(2) 
     If oid.Text = "X" Then 
      Dim tb As Button = e.Row.Cells(1).Controls(1) 
      'Dim tb = e.Row.FindControl("DeleteButton") 
      tb.Visible = "False" 
     End If 
    End If 
End Sub 
+0

的代碼,你可能要添加一個* ASP/asp.net *標記,即可* ASP *問題吸引* ASP *注意 – Plutonix

+1

@Plutonix只是做了他。 – Codexer

+0

爲什麼不能在HTML上添加Visible屬性? – techspider

回答

-1

也許代碼,你可以改變模板列

<asp:TemplateField HeaderText="Col1"> 
    <ItemTemplate> 
    <asp:label ID="lbl1" runat="server" text='<%#left(DataBinder.Eval(Container.DataItem, "field1"),20)%>'> 
    </asp:label> 
    </ItemTemplate> 

有了這個代碼:

Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound 
Dim lbl1 As Label 
    If e.Row.RowType = DataControlRowType.DataRow Then 
    lbl1 = CType(e.Row.FindControl("lbl1"), Label) 
    If oid.Text = "X" Then 
     lbl1 .Visible = "False" 
    End If 
    End If 
End Sub 

您幾乎可以在模板中使用任何控件。

0

感謝所有的想法。這是我在這個網站上找到的最乾淨的解決方案,但它在c#中被轉換爲vb。

<asp:TemplateField> 
    <ItemTemplate> 
     <asp:LinkButton runat="server" ID="DeleteButton" CommandName="Delete" Text="Delete" /> 
    </ItemTemplate> 
</asp:TemplateField>    

背後

Dim oid As TableCell = e.Row.Cells(2) 
Dim tb = e.Row.FindControl("DeleteButton") 
If oid.Text = "X" Then 
    tb.Visible = True 
Else 
    tb.Visible = False 
End If 
相關問題