|
.net
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Hide TemplateFielda 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
Show quote
Hide quote
On 17 June, 23:05, "David C" <dlch***@lifetimeinc.com> wrote: Hi David> 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 It may be helpful to mention that the 'Visible' property of any control in a template can be DataBound to boolean field values just as the 'Checked' property of a checkbox control can. If the conditions for hiding or showing are a little more complex then you can build expressions in the language of the page (VB.NET in this case) including the option of calling functions coded in script or in the page's code file (give the function a public attribute). HTH
Show quote
Hide quote
"Stan" <googles***@philhall.net> wrote in message Hi Davidnews:911bbef4-675f-49c0-9067-0292527977d5@3g2000yqk.googlegroups.com... On 17 June, 23:05, "David C" <dlch***@lifetimeinc.com> wrote: > 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 It may be helpful to mention that the 'Visible' property of any control in a template can be DataBound to boolean field values just as the 'Checked' property of a checkbox control can. If the conditions for hiding or showing are a little more complex then you can build expressions in the language of the page (VB.NET in this case) including the option of calling functions coded in script or in the page's code file (give the function a public attribute). HTH Yes, that is helpful for the controls, but what about the entire (table row) line of the DetailsView (TemplateField)? If I make the Visible property false for the control, won't the row still show as a blank line? Thanks. David
Other interesting topics
isnull ! gives error
Is there a way to keep the StreamWriter open? Visual Basic is Dead! Web Deployment Project - Include Files Movenext and ASP.net enum or static class Sharing the Cache between ASP.NET applications SQL setup for Session ie8 javascript "new function" behavior Skinning Question for checkboxes |
|||||||||||||||||||||||