Hide A Databound Control?
Aug 31, 2010
Depending on the case, I'd like to hide a databound control in a page. But no matter what I try, it seems like the control will try biding no matter what. I've tried setting Visible="false", but it would still try to bind. I've tried putting the control into a placeholder and then hide the placeholder, it will try to bind anyway. I've also tried putting it into a MultiView, same thing. You would think that in a wizard interface using a MultiView you would not want the controls in the next steps of the wizard to bind, but no. It binds anyway...
The only way I've found is to unset and set the DataSourceID property which seems to prevent binding.
Is this really the only option?
View 2 Replies
Similar Messages:
Dec 7, 2010
I want to render something like this (with ASP.Net Controls in the codebehind):
<ul>
<li class="first"><h1>This is a caption</h1></li>
<li><a href="#" title="" target="_self">Foo</a></li>
<li><a href="#" title="" target="_self">Foo1</a></li>
<li><a href="#" title="" target="_self">Foo2</a></li>
<li><a href="#" title="" target="_self">Foo3</a></li>
<li><a href="#" title="" target="_self">Foo4</a></li>
</ul>
<ul>
<li class="first"><h1>This is a another caption</h1></li>
<li><a href="#" title="" target="_self">Foo5</a></li>
<li><a href="#" title="" target="_self">Foo6</a></li>
<li><a href="#" title="" target="_self">Foo7</a></li>
<li><a href="#" title="" target="_self">Foo8</a></li>
<li><a href="#" title="" target="_self">Foo9</a></li>
<li><a href="#" title="" target="_self">Foo10</a></li>
<li><a href="#" title="" target="_self">Foo11</a></li>
</ul>
The amount of li elements that will be rendered into each ul is determined at runtime. Each link in a li belongs to into a specific ul (the one containing a specific caption. Imagine this as a kind of a treeview with nodes and subnodes) During the bind Event I need access to an ASP:HyperLink that will be rendered into the a-element. Which databound ASP.Net control should I pick for this? Looks like a repeater in a repeater, which should make the databinding process ugly. I'm thinking about creating this HTML-Output with StringWriters myself.
View 1 Replies
May 10, 2010
i have a FormView, and i already have a Label control that gets the value of theselected propery inside the FormView, so each time the FormView displays data, i have a Label control that displays individual values, according to the value of the FormView, here is the code:
[code]....
What i would like to do is to know how i could add a DataList instead of a Label, and then each time the FormView databinds an item, to show the value of the DataList How would i go about doing that?
View 10 Replies
Feb 25, 2010
I have a control that inherits CompositeDataBoundControl. Based on the values of the bound data, I create som dynamic controls. In order to preserve state, I need to recreate the control tree on every request(from CreateChildControls):
[code]....
The problem is that on postback the PaymentMethod object is null, so I have no method of knowing what kind of control to recreate. That means that the control state is ruined. If I hardcode the type of payment control to make, it works as expected:
UserControl userCtrl = (UserControl)Page.LoadControl("~/WAF/View/VisitControls/Shop/CreditCardForm.ascx");
dataContainer.Controls.Add(userCtrl);
userCtrl.ID = "CreditCardForm";
how I can find out what payment method is used, so that I can create the correct control on postback?
View 1 Replies
Sep 20, 2010
I've come to a scenario where I need to databind something only if the user is logged in. To do this I am using the LoginView control to display a Login control when they are not logged in and a GridView control when they are logged in. However, when I databind to the GridView object in the LoginView, nothing ever gets displayed. I have been debugging it and I am databinding it to a DataTable that definitely has data in it, however nothing shows up.
Here is some of the code:
if (User.Identity.IsAuthenticated)
{
((GridView)LoginView1.FindControl("GridView1")).DataSource = dt;
((GridView)LoginView1.FindControl("GridView1")).DataBind();
}
Is there a particular reason that this should not work? Is it bad practice?
View 1 Replies
Mar 16, 2011
I am working on a project in ASP.Net, in which I am using DataList control to list the candidate data. As we know, DataBoud event is available for gridview control, which is raises after databound. In DataList control no such event is available. Yes, ItemDataBound event is there which is arises on every Item bound. Let us assume, that I want the number of items are listed in datalist, after completing the data bound of datalist.
View 2 Replies
Oct 5, 2010
I want a javascript on a databound row to act on another control in the same row - show/hide for example. The classic ASP approach was to number the controls (usually by rowIndex so that they're easier to reference. I am wondering is there a way to do this in ASP.Net without writing any item command code?
So for html to render as follows
<div onClick='actOnX0'> <span id=x0>i am x0</span></div>
<div onClick='actOnX1'> <span id=x1>i am x1</span></div>
<div onClick='actOnX2'> <span id=x1>i am x2</span></div>
Can I insert the numbers using a databound property that returns say the rowIndex / item index of the current row?
View 2 Replies
Dec 20, 2010
Take for example a DetailsView control with an ObjectDataSource as its datasource.Normally in the DetailsView.ItemUpdated event I would grab a reference to the details view by casting the sender:
DetailsView dv = (DetailsView)sender;
In certain situations it becomes necessary to handle the event inside the ObjectDataSource.ItemUpdated event. In this case sender is now of type ObjectDataSource. What I want to be able to do is write clean code that isnt hardcoded like
Label label1 = DetailsView1.FindControl("Label1");
I looked over the documentation and also did some searches but couldnt find how I would write some code like the following:
protected void ObjectDataSource1_Inserted(object sender, ObjectDataSourceStatusEventArgs e)
{
ObjectDataSource ods = (ObjectDataSource)sender;
DetailsView dv = (DetailsView)ods.SOMETHING_HERE;
}
what I should be putting in the SOMETHING_HERE in the snippet above?
View 2 Replies
May 5, 2010
I'm working in a web application and my page is using a databound formview control. When i first enter the page via my code, I am unable to retreive a value from any of my controls -e.g. when i debug, i see that tbDate.text has no value (see code below). How can I retreive the values from the controls on my page e.g text boxes?
Code:
if (!this.IsPostBack)
{
TextBox tbDate = (TextBox)FormView1.Row.Cells[0].FindControl("txtDate");
}
View 6 Replies
Nov 11, 2010
I am fairly new to asp.net programming. I found this custom control that uses ajax to update the contents of the control and it is working perfectly. However, I need to access some of the asp.net labels and images in the databound event so I can set their values/properties appropriately, and am not sure how to go about adding additional code or accessing these in my custom control (I have been googling endlessly with no results). My code for the custom control is below.
Imports System
Imports System.Text
Imports System.IO
Imports System.Collections
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports Microsoft.VisualBasic
Namespace myControls
Public Class AjaxDivView
Inherits CompositeDataBoundControl
Implements ICallbackEventHandler
Private _itemTemplate As ITemplate
''' <summary>
''' The ItemTemplate is used to format each item from the data source.
''' </summary>
<TemplateContainer(GetType(DivViewItem))> _
<PersistenceMode(PersistenceMode.InnerProperty)> _
Public Property ItemTemplate() As ITemplate
Get
Return _itemTemplate
End Get
Set(ByVal value As ITemplate)
_itemTemplate = value
End Set
End Property
''' <summary>
''' Register Javascript
''' </summary>
Protected Overrides Sub OnPreRender(ByVal e As System.EventArgs)
'Register Refresh Function
Dim eRef As String = Page.ClientScript.GetCallbackEventReference(Me, Nothing, "AjaxDivView_Result", "'" & Me.ClientID & "'", "AjaxDivView_Error", False)
Dim refreshFunc As String = "function AjaxDivView_Refresh() {" & eRef & "}"
Page.ClientScript.RegisterClientScriptBlock(Me.GetType(), Me.UniqueID, refreshFunc, True)
MyBase.OnPreRender(e)
End Sub
''' <summary>
''' Iterate through the data items and instantiate each data item in a template.
''' </summary>
Protected Overloads Overrides Function CreateChildControls(ByVal dataSource As System.Collections.IEnumerable, ByVal dataBinding As Boolean) As Integer
Dim counter As Integer = 0
For Each dataItem As Object In dataSource
Dim contentItem As New DivViewItem(dataItem, counter)
_itemTemplate.InstantiateIn(contentItem)
Controls.Add(contentItem)
counter = counter + 1
Next
DataBind(False)
Return counter
End Function
''' <summary>
''' Render this control's contents in a Ul tag
''' </summary>
Protected Overrides ReadOnly Property TagKey() As System.Web.UI.HtmlTextWriterTag
Get
Return HtmlTextWriterTag.Div
End Get
End Property
''' <summary>
''' Render my contents to a string and send the result back to the client
''' </summary>
Public Function GetCallbackResult() As String Implements System.Web.UI.ICallbackEventHandler.GetCallbackResult
Dim builder As New StringBuilder()
Dim sWriter As New StringWriter(builder)
Dim hWriter As New HtmlTextWriter(sWriter)
Me.RenderContents(hWriter)
Return builder.ToString()
End Function
''' <summary>
''' Whenever I get called through AJAX, rebind my data.
''' </summary>
Public Sub RaiseCallbackEvent(ByVal eventArgument As String) Implements System.Web.UI.ICallbackEventHandler.RaiseCallbackEvent
Me.DataBind()
End Sub
Public Class DivViewItem
Inherits WebControl
Implements IDataItemContainer
Private _dataItem As Object
Private _index As Integer
Public ReadOnly Property DataItem() As Object Implements System.Web.UI.IDataItemContainer.DataItem
Get
Return _dataItem
End Get
End Property
Public ReadOnly Property DataItemIndex() As Integer Implements System.Web.UI.IDataItemContainer.DataItemIndex
Get
Return _index
End Get
End Property
Public ReadOnly Property DisplayIndex() As Integer Implements System.Web.UI.IDataItemContainer.DisplayIndex
Get
Return _index
End Get
End Property
Protected Overrides ReadOnly Property TagKey() As System.Web.UI.HtmlTextWriterTag
Get
Return HtmlTextWriterTag.Div
End Get
End Property
Public Sub New(ByVal dataItem As Object, ByVal index As Integer)
_dataItem = dataItem
_index = index
End Sub
End Class
End Class
End Namespace
View 5 Replies
Jan 6, 2011
I have a databound calendar control that loads the date from the database.The problem I have is that it defaults to todays date when the form is loaded, although when you scroll to the loaded date you see that the correct date is in fact selected. How can I force it to show the loaded date from the database from the start?
View 2 Replies
Dec 30, 2010
I have a databound checkbox control that displays items with different widths. In order to get a better outlook, I would like to set a fix width for each items in the checkboxlist control which has horizontal repeatdirection.
Here is the control:
[Code]....
View 3 Replies
Sep 29, 2010
Context
I'm putting together a templated, databound control. Presently it works with the following syntax...
<cc:ItemChooserControl ID="ItemChooser" runat="server">
<TitleTemplate>
<h4><%# DataBinder.Eval(Container.DataItem, "DisplayName") %></h4>
</TitleTemplate>
</cc:ItemChooserControl>
Problem
What I would like though is that the shorter, simpler Eval would work instead.
<h4><%# Eval("DisplayName") %></h4>
What I get however when using straight Eval is an error:
Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.
Code
I'm databinding to a custom HtmlTableCell...
public class TitleTemplateTableCell: HtmlTableCell, INamingContainer
{
private object m_DataItem;
public virtual object DataItem
{
get { return m_DataItem; }
set { m_DataItem = value; }
}
}
With the following custom DataBind (non-related code removed)...
foreach (object dataItem in dataSource) {
TitleTemplateTableCell title = new TitleTemplateTableCell();
TitleTemplate.InstantiateIn(title); // TitleTemplate is the template property
title.DataItem = dataItem;
title.DataBind();
}
View 1 Replies
Nov 2, 2010
I was trying to make an ASP.NET AJAX programatically Databound Accordion control expand onmouseover event but it didnt fired. When i use static text i.e without databinding the Accordion control the onmouseover event works fine.
Default.aspx
<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="SocisSchools.aspx.cs" Inherits="SocisSchools" Title="Schools Detail" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<div>
<span style="font-size: 12pt"><strong>Schools</strong></span>
<br />
</div>
<div>
<cc1:Accordion ID="Accordion1" runat="server" SelectedIndex="0"
HeaderCssClass="accordionHeader" HeaderSelectedCssClass="accordionHeaderSelected"
ContentCssClass="accordionContent" FadeTransitions="true" FramesPerSecond="40"
TransitionDuration="250" AutoSize="None" RequireOpenedPane="false"
SuppressHeaderPostbacks="true">
<HeaderTemplate>
<a href=""><%# Eval("SchoolName") %></a>
</HeaderTemplate>
<ContentTemplate>
<p style="text-align: justify">
<asp:Label ID="lblSchoolIntro" runat="server" Text='<%# Eval("SchoolIntro") %>'>
</asp:Label></p><br />
</ContentTemplate>
</cc1:Accordion>
<div>
<asp:Button ID="cmdPrev" runat="server" Text=" << " OnClick="cmdPrev_Click" CausesValidation="false"></asp:Button>
<asp:Button ID="cmdNext" runat="server" Text=" >> " OnClick="cmdNext_Click" CausesValidation="false"></asp:Button>
<asp:Label ID="lblCurrentPage" runat="server"></asp:Label>
</div>
</div>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder2" Runat="Server">
</asp:Content>
Default.aspx.cs
public partial class SocisSchools : System.Web.UI.Page
{
public int CurrentPage
{
get
{
// look for current page in ViewState
object o = this.ViewState["_CurrentPage"];
if (o == null)
return 0; // default to showing the first page
else
return (int)o;
}
set
{
this.ViewState["_CurrentPage"] = value;
}
}
protected void Page_Load(object sender, EventArgs e)
{
GetItems();
}
private void GetItems()
{
BusinessLogicLayer.SocisSchools fac = new BusinessLogicLayer.SocisSchools();
DataSet ds = fac.GetSchools();
PagedDataSource objPds = new PagedDataSource();
objPds.DataSource = ds.Tables[0].DefaultView;
objPds.AllowPaging = true;
objPds.PageSize = 7;
objPds.CurrentPageIndex = CurrentPage;
lblCurrentPage.Text = "Page: " + (CurrentPage + 1).ToString() + " of " + objPds.PageCount.ToString();
Accordion1.DataSource = objPds;
Accordion1.DataBind();
// Disable Prev or Next buttons if necessary
cmdPrev.Enabled = !objPds.IsFirstPage;
cmdNext.Enabled = !objPds.IsLastPage;
}
protected void cmdPrev_Click(object sender, EventArgs e)
{
CurrentPage -= 1;
GetItems();
}
protected void cmdNext_Click(object sender, EventArgs e)
{
CurrentPage += 1;
GetItems();
}
}
View 1 Replies
Feb 1, 2010
How do you avoid duplicate bound items in this scenario: There's a databound control on a page (a DropDownList in this case, though I don't think it matters). It has AppendDataBoundItems set to "true". Somewhere in the code, a DataSource is set and DataBind is called. So this control is bound explicitly. You have a bunch of other things to bind on the page, so you call Page.DataBind.
Your databound control now has duplicate items in it. It was (1) bound explicitly, then (2) Page.DataBind bound it again. Since AppendDataBoundItems was true, the second bind appends to the first, and you end up with double the items. A couple limitations: The explicit call to DataBind on the control is done through some centralized code, and would be painful to change. i really need to bind the rest of the page in aggregate (via Page.Databind()) because there's too many other databound elements to do it individually without writing a ton of individual calls.
I need a method like... Page.DataBindExceptIfTheyHaveAlreadyBeenBoundDuh()
View 2 Replies
May 21, 2010
i am developing a tree view component which should be data driven and amendable instead default layout provided by .net can we change that proper hierarchial structure like organization chart is there any chance to provide with an hyperlink to redirect other page or content view control below to display the content related to it.
i am trying to use silverlight with c#.
View 2 Replies
Aug 17, 2010
I am using .Net 3.5 in VS 2010. I would like to use a couple of radio buttons, that are bound to data, to control the Expand/Collapse of a CollapsiblePanelExtender.
I have found several threads on the web that suggest using JavaScript to control the CollapsiblePanelExtender with a RadioButtonList, but I cannot $find the control in the JavaScript.
I have also found several threads that suggest using custom radio buttons, but I don't see how to do the databinding for these.
View 2 Replies
Sep 8, 2012
SqlCommand _cmd1 = new SqlCommand("Viewstate2", _cn);
_cmd1.CommandType = CommandType.StoredProcedure;
_cmd1.Parameters.AddWithValue("@behcode", data);
string data1 = Request.QueryString["id"].ToString();
_cmd1.Parameters.AddWithValue("@id", data1);
_cn.Open();
SqlDataReader _dr1 = _cmd1.ExecuteReader();
while (_dr1.Read())
{
lblprice.Text = _dr1["price"].ToString();
Lbldate.Text = System.Convert.ToDateTime(miladitoshamsi(Eval("Date"))).ToString(" yyyy/MM/dd");
In the above code I get the following error
Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control. Description: An unhandled exception occurred during the execution of the current web request. review the stack trace for more information about the error and where it originated in the code. Exception Details: System.InvalidOperationException: Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.Source Error:
Line 97: lblprice1.Text = _dr1["price1"].ToString();
Line 98: lblprice.Text = _dr1["price"].ToString();
Line 99: Lbldate.Text = System.Convert.ToDateTime(miladitoshamsi(Eval("Date"))).ToString(" yyyy/MM/dd");
View 1 Replies
Aug 31, 2010
Basically, I have a custom templated control with a custom data container class. When a developer adds an instance of my control to a page, they can define the controls in the LayoutTemplate however they like, as follows:
<ml:MyControl id="MyControl1" runat="server">
<LayoutTemplate>
<span><%#Container.ErrorMessage%></span>[code]...
I would like my control to automatically move the "ml_errormessage" (databound content from Container.ErrorMessage - hard coded token in the property) to be a class of its containing element to make it easier for jQuery to use a selector to find the element and dynamically insert the error message client side. More importantly, I would like it moved out of the way so the class name doesn't get replaced by the content and jQuery can find it as many times as it needs to during the page lifecycle. In other words, I would like the output to look like this without the developer changing the input template or resort to using custom controls in the template:
<span id="MyControl1"><span>
<span class="ml_errormessage"></span>
</span></span>
I would like to move the value using the controls collection rather than resorting to string parsing of the output, if possible. However, when I interrogate the collection in an override of OnPreRender, the control in the template looks like this in the debugger:
{System.Web.UI.DataBoundLiteralControl}
System.Web.UI.DataBoundLiteralControl: {System.Web.UI.DataBoundLiteralControl} [code]...
As you can see the "ml_errormessage" value is nowhere to be found. Upon analysis of the DataBind event of the Control class using Reflector, I see that it delegates the binding behavior to each control. In other words, each control handles its own databinding. However, since I have no way of knowing in advance what control types will be in the template, how can this change be done?
Note: an acceptable alternative would be to add a new HtmlGenericControl (span) in the exact spot where the "ml_errormessage" is and add it as a class to this new control.On a side note, is there an easy way to get the control's output to indent for easy reading during debugging?
View 1 Replies
Apr 5, 2010
I dont want to use asp.net's TreeView control. I want to create a custom template databound control with multi template support like -
<asp:MtNavigationControl>
<ItemTemplate>
...
...
</ItemTemplate>
<SelectedItemTemplate>
...
...
</SelectedItemTemplate>
<ParentItemTemplate>
...
...
</ParentSelectedItemTemplate>
<SelectedParentItemTemplate>
...
...
</SelectedParentSelectedItemTemplate>
</asp:MtNavigationControl>
My data is like -
class Employee
{
string EmployeeName
List<Employee> Employees
}
Does anyone know how to accomplish it?
View 1 Replies
Apr 13, 2010
I am trying to develop a very simple templated custom server control that resembles GridView. Basically, I want the control to be added in the .aspx page like this:
[Code]....
I know that what I want to achieve is pointless and that I can use DataGrid to achieve it, but I am giving this very simple example because if I know how to do this I would be able to develop the control that I need.
View 1 Replies
Jan 6, 2010
I have an AJAX tab container with 2 panels within aspx page. Each panel hosts an ascx control. Each control contains GridView and FormView that are databound - 1st control to the parent table and 2nd - to the child. The 2nd control/tab contains standard DropDownList that is bound to the parent values so the user can select a parent to create "child" for. everything works fine except when the parent (on the 1st tab control) is created/updates the ObjectDataSource on the 2nd tab does not getting refreshed. Only after refreshing the hole page I can see the new "parent" value in the ddl on "child" page. I use strongly typed dataset. How I can programmatically refresh the DataSource? Simple rebinding didn't make a dent. Do I need to refresh page, the tab container, tab panel?
<asp:Content
ID="Content1"
ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server">
[Code]....
View 1 Replies
Sep 8, 2010
I have a repeater I've databound with a generic arraylist from a LINQ query (.ToList() ) in the code behind.
I was using
<%# Bind("FirstName")%> but noticed
<%# Eval("FirstName")%> works just as well.
Is it better to use Eval or Bind? or does it depend on the situation?
View 3 Replies
Dec 29, 2012
this is my hyperlink code that is in gridview
<ItemTemplate>
<asp:HyperLink ID="lnkRemove2" runat="server" CssClass="LBP3E" Text = "more..." NavigateUrl='<%# "state/view.aspx?BehCode=" + Request.QueryString["BehCode"] + "&Id=" + Eval("Id") %>'></asp:HyperLink>
</ItemTemplate>
I want do some thing like that for my button control that is not in gridview it is out of grid view...HOw I can do it?
View 1 Replies
Apr 3, 2010
I am getting the following error
Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.
but all I am trying to do is inside a ASP.NET REPEATER Control
<% if ( Eval("Message").ToString() == HttpContext.Current.Profile.UserName) %>
<% { %>
<asp:ImageButton runat="server" etc.... />
<% } %>
View 2 Replies