D
David C
I have a DetailsView using TemplateFields and would like to know if there is
a way to hide them in code. I have a Databound event where I am doing other
things and would like to hide some TemplateFields based on whether a
checkbox is checked. Below is a sample of 2 TemplateFields in my page and
below that is my Databound code where I am hiding controls. Any help is
appreciated.
David
<asp:TemplateField HeaderText="Retail business, shopping center"
SortExpression="">
<EditItemTemplate>
<asp:CheckBox ID="ckRetailBusShopping" runat="server"
Checked='<%# Bind("RetailBusShopping") %>' />
</EditItemTemplate>
<ItemTemplate>
<asp:CheckBox ID="ckRetailBusShopping" runat="server"
Checked='<%# Bind("RetailBusShopping") %>' Enabled="false" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Distance from Retail (meters)"
SortExpression="">
<EditItemTemplate>
<asp:TextBox ID="txtMetersFromRetail" runat="server"
Text='<%# Bind("MetersFromRetail") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="LblMetersFromRetail" runat="server"
Text='<%# Bind("MetersFromRetail") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
In the code page I have sub below.
Protected Sub dvPropertyAndBusiness_DataBound(ByVal sender As Object,
ByVal e As System.EventArgs) Handles dvPropertyAndBusiness.DataBound
Dim ck As CheckBox =
dvPropertyAndBusiness.FindControl("ckRetailBusShopping")
Dim tx As TextBox
Dim lbl As Label
Select Case dvPropertyAndBusiness.CurrentMode
Case DetailsViewMode.ReadOnly
tx =
dvPropertyAndBusiness.FindControl("txtMetersFromRetail")
lbl =
dvPropertyAndBusiness.FindControl("LblMetersFromRetail")
If ck.Checked Then
tx.Visible = True
lbl.Visible = True
Else
tx.Visible = False
lbl.Visible = False
End If
Case DetailsViewMode.Edit
tx =
dvPropertyAndBusiness.FindControl("txtMetersFromRetail")
lbl =
dvPropertyAndBusiness.FindControl("LblMetersFromRetail")
If ck.Checked Then
tx.Visible = True
lbl.Visible = True
Else
tx.Visible = False
lbl.Visible = False
End If
Case Else
End Select
End Sub
a way to hide them in code. I have a Databound event where I am doing other
things and would like to hide some TemplateFields based on whether a
checkbox is checked. Below is a sample of 2 TemplateFields in my page and
below that is my Databound code where I am hiding controls. Any help is
appreciated.
David
<asp:TemplateField HeaderText="Retail business, shopping center"
SortExpression="">
<EditItemTemplate>
<asp:CheckBox ID="ckRetailBusShopping" runat="server"
Checked='<%# Bind("RetailBusShopping") %>' />
</EditItemTemplate>
<ItemTemplate>
<asp:CheckBox ID="ckRetailBusShopping" runat="server"
Checked='<%# Bind("RetailBusShopping") %>' Enabled="false" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Distance from Retail (meters)"
SortExpression="">
<EditItemTemplate>
<asp:TextBox ID="txtMetersFromRetail" runat="server"
Text='<%# Bind("MetersFromRetail") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="LblMetersFromRetail" runat="server"
Text='<%# Bind("MetersFromRetail") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
In the code page I have sub below.
Protected Sub dvPropertyAndBusiness_DataBound(ByVal sender As Object,
ByVal e As System.EventArgs) Handles dvPropertyAndBusiness.DataBound
Dim ck As CheckBox =
dvPropertyAndBusiness.FindControl("ckRetailBusShopping")
Dim tx As TextBox
Dim lbl As Label
Select Case dvPropertyAndBusiness.CurrentMode
Case DetailsViewMode.ReadOnly
tx =
dvPropertyAndBusiness.FindControl("txtMetersFromRetail")
lbl =
dvPropertyAndBusiness.FindControl("LblMetersFromRetail")
If ck.Checked Then
tx.Visible = True
lbl.Visible = True
Else
tx.Visible = False
lbl.Visible = False
End If
Case DetailsViewMode.Edit
tx =
dvPropertyAndBusiness.FindControl("txtMetersFromRetail")
lbl =
dvPropertyAndBusiness.FindControl("LblMetersFromRetail")
If ck.Checked Then
tx.Visible = True
lbl.Visible = True
Else
tx.Visible = False
lbl.Visible = False
End If
Case Else
End Select
End Sub