Answered by:
How do I hide a <tr> table row inside a Grid

Question
-
User1279376247 posted
I am able to hide a table row like this:
<tr id="testrow2" runat="server">
and then in my vb code:
testrow2.visible=false.
But how do I do it if my table is inside a grid and I need to do DirectCast
DirectCast(e.Row.FindControl("testrow2",????).visible=false
What kind of object is it?
Wednesday, August 17, 2016 12:07 PM
Answers
-
User283571144 posted
Hi DaveBF,
DaveBF
But how do I do it if my table is inside a grid and I need to do DirectCast
DirectCast(e.Row.FindControl("testrow2",????).visible=false
What kind of object is it?
As far as I know, HTML server controls' class is 'HtmlControl'.
More details, you could refer to follow codes:
Code-behind:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load For Each row As GridViewRow In GridView1.Rows 'Dim Control1 As HtmlControl = row.FindControl("aaa") 'Control1.Visible = False DirectCast(row.FindControl("aaa"), HtmlControl).Visible = False Next End Sub
ASPX:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="Id" DataSourceID="SqlDataSource1"> <Columns> <asp:BoundField DataField="Id" HeaderText="Id" InsertVisible="False" ReadOnly="True" SortExpression="Id" /> <asp:BoundField DataField="name" HeaderText="name" SortExpression="name" /> <asp:BoundField DataField="password" HeaderText="password" SortExpression="password" /> <asp:BoundField DataField="State" HeaderText="State" SortExpression="State" /> <asp:TemplateField HeaderText="City" SortExpression="City"> <EditItemTemplate> <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("City") %>'></asp:TextBox> </EditItemTemplate> <ItemTemplate> <asp:Label ID="Label1" runat="server" Text='<%# Bind("City") %>'></asp:Label> <table > <tr id="aaa" runat="server" clientidmode="Static" > <td> aaaa </td> <td> bbbb </td> </tr> <tr > <td> cccc </td> <td> dddd </td> </tr> </table> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView>
Link:
https://msdn.microsoft.com/en-us/library/system.web.ui.htmlcontrols.htmlcontrol(v=vs.110).aspx
Best Regards,
Brando
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, August 17, 2016 1:05 PM -
User-63706186 posted
Hi
if your "tr" having as runat="server" tag and then you can access them directly in code behind
if you can use this approach of benefits as the "tr" space will be remove at the runtime.
testrow2.Attributes.Add("style","display:none");
this approach of drawback as the "tr" space will be occupied at the runtime
testrow2.visible=false;
I know C# only man i think you can refer solutions tips
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Saturday, August 20, 2016 5:47 AM
All replies
-
User283571144 posted
Hi DaveBF,
DaveBF
But how do I do it if my table is inside a grid and I need to do DirectCast
DirectCast(e.Row.FindControl("testrow2",????).visible=false
What kind of object is it?
As far as I know, HTML server controls' class is 'HtmlControl'.
More details, you could refer to follow codes:
Code-behind:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load For Each row As GridViewRow In GridView1.Rows 'Dim Control1 As HtmlControl = row.FindControl("aaa") 'Control1.Visible = False DirectCast(row.FindControl("aaa"), HtmlControl).Visible = False Next End Sub
ASPX:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="Id" DataSourceID="SqlDataSource1"> <Columns> <asp:BoundField DataField="Id" HeaderText="Id" InsertVisible="False" ReadOnly="True" SortExpression="Id" /> <asp:BoundField DataField="name" HeaderText="name" SortExpression="name" /> <asp:BoundField DataField="password" HeaderText="password" SortExpression="password" /> <asp:BoundField DataField="State" HeaderText="State" SortExpression="State" /> <asp:TemplateField HeaderText="City" SortExpression="City"> <EditItemTemplate> <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("City") %>'></asp:TextBox> </EditItemTemplate> <ItemTemplate> <asp:Label ID="Label1" runat="server" Text='<%# Bind("City") %>'></asp:Label> <table > <tr id="aaa" runat="server" clientidmode="Static" > <td> aaaa </td> <td> bbbb </td> </tr> <tr > <td> cccc </td> <td> dddd </td> </tr> </table> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView>
Link:
https://msdn.microsoft.com/en-us/library/system.web.ui.htmlcontrols.htmlcontrol(v=vs.110).aspx
Best Regards,
Brando
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, August 17, 2016 1:05 PM -
User-63706186 posted
Hi
if your "tr" having as runat="server" tag and then you can access them directly in code behind
if you can use this approach of benefits as the "tr" space will be remove at the runtime.
testrow2.Attributes.Add("style","display:none");
this approach of drawback as the "tr" space will be occupied at the runtime
testrow2.visible=false;
I know C# only man i think you can refer solutions tips
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Saturday, August 20, 2016 5:47 AM