I am attempting to hide a DetailsView Row conditionally from code behind. I'd like to be able to call SomeMethod based on some condition and have it to hide Row 12. Does anyone know how I can go about accomplishing this?
I have used the debugger to confirm that Row[12] is the correct row and that the method is being executed.
protected void SomeMethod(object sender, EventArgs e)
{
DetailsView1.Rows[12].visible= false;
//Alternative methods I attempted that also did not work.
//DetailsViewRow row = DetailsView1.DataItem as DetailsViewRow;
//row[12].Visible = false;
//DetailsViewRow row = DetailsView1.Rows[12];
//row.visible = false;
}
This is my aspx.
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" DataSourceID="ObjectDataSource2">
...
<asp:TemplateField HeaderText="Item"
SortExpression="Item">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("Item") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("Item") %>'></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("Item") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
...