2016-09-20 83 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 
相关问题