C# - Dynamic Controls In Databound Control?

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


Similar Messages:

C# - Which Databound Control Should Be Use For Nested Databound Controls?

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

Forms Data Controls :: GridView:Dynamic DataBound Column Creation With Hyperlinks?

May 10, 2010

I have a stored procedure (For Eg: sp_GetAvlData) that accepts a number of parameters, 3 of which are TimeFrom, TimeTo (as varchar) and TimeInterval (as int), formulates a Dynamic query and executes itself. So for instance, if I call the proc as follows:

[code]....

dtAvl is the datatable containing the results of my stored procedure.

The next step for me is to make each of the cells (except the cells in the first column) as a Hyperlink so that when clicked upon a cell, it populates 2 textboxes with the selected Timeslot and Name or ID (ID field is not displayed in Gridview). The textboxes are located on the same page but outside of the Gridview control.

The Challenge that I'm facing out here are:

1) As you can see, the field names being generated are not fixed and I have no control over them.

2) Because the field names are not fixed I'm not sure I can implement this using the Templatefields or BoundFields of Gridview.

Is there any way to achieve the Hyperlinking of these cells within the Gridview?

View 3 Replies

Forms Data Controls :: Several Data Formatting In Dynamic Databound GridView?

Jul 31, 2010

I am facing certain problems with the data formatting in GridView when the data is bound dynamically to it.

I have a DateTime column and want to only show Date from it and not the time.

Another Decimal type column which accepts decimal upto 4 places, I want to show decimal upto the places defined in the particular value (don't know how to put it in the correct way, but here is an example of what I want).

i.e.

1.0000 should be displayed as 1 after the databound in the gridview.

Similarly,

2.3400 --> 2.34
1.0050 --> 1.005
1.1000 --> 1.1

View 6 Replies

C# - Adding Dynamic Image Overlay To Databound Gridview?

Feb 25, 2011

I am trying to add an image overlay of a cell within a data bound gridview cell in ASP.Net (C#). The effect is designed to have a string within the image that is going to sit on top of the image that is pulled from the server.

IE: Database contains path to images. Data grid is pulling these images in based on the ID of the items in question. I need to pull the price from the database and lay it onto an image that is placed over the data bound image cell.

SQL Statement gets results.

Results contains path to image for items.

Items are sometimes on sale, so a special overlay is needed.

Overlay will have a varying price overlaying it.

I tried to break it down into easy portions. I am not sure if I am over thinking things or not but I can't find a feasible way to do this. The data is converted to a table due to the data grid control in ASP.Net, and there isn't any way to determine the IDs after the table is created.

View 1 Replies

How To Get Values From Controls In Databound Formview Control

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

Forms Data Controls :: Databound Treeview Control Using .net?

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

Forms Data Controls :: Refresh Databound Control On AJAX Tab?

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

Forms Data Controls :: Use Eval Or Bind In A Databound Control?

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

Data Controls :: How To Use EVAL Function Outside GridView DataBound Control

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

Forms Data Controls :: Adding Calculated Fields To A Databound Control?

Oct 14, 2010

I need a form that displays three columns drawn directly from a database (no problems here) as well as two fields that require some complex calculations. Not only am I lost as to how to incorporate the calculations into the control, I don't know exactly how to write the calculations. I am working in Visual Web Developer 2008 with Vb.NET.

The first of the two fields should take the sum of all payments made by a given customer and divide it by a DailyMembershipRate, returning a DaysPaid variable. It should take this variable and a CustomerSince field for that particular customer and calculate a PaidThrough field.

The second of the two columns similarly requires the DaysPaid variable described above. It should subtract the CustomerSince field from the current date and return the value in days, giving a MembershipDays variable. Finally, it should subtract MembershipDays from the DaysPaid variable, again returning a value in days, and then multiply this by the DailyRate value for a Credit/Deficit field.

I realize this is a lot, but I haven't been able to find any documentation either online or in VWD or ASP.NET texts on this topic. I could really use some fellow user input.

View 4 Replies

Forms Data Controls :: How To Set DataList's EditItemTemplate To User Control And Databound It

Feb 24, 2011

I have DataList control and I want to assign to it's edititemtemplate some User Control. The problem is I can't find when I should databound UserControl to data, as my UserControl doesn't have static look (it renders different depending on some property values and datasource).

I was try to simply set my user control in edititemtemplate

<EditItemTemplate>
<uc:MyUserControl id="myUserControl1" runat="server" />
</EditItemTemplate>

and then bind it to data in ItemDataBound event handler, but it remains empty

if(e.Item.ItemType == ListItemType.EditItem)
{
var p = (Pair)DataBinder.GetPropertyValue(e.Item.DataItem, "Key");
((AnnouncementUserControl) e.Item.FindControl("userControl1")).RepeaterDataSource =
_templateWorker.ReturnTemplateByAnnouncementId(Convert.ToInt32(p.First), true);
}

how can I databound my control, or another approach which will make me avoid this problem?

View 2 Replies

Forms Data Controls :: Make A Databound Control With A Custom Scrollbar?

Mar 22, 2010

I'm working on a website to showcase some of my bird photography, using ASP.NET 2.0 and C# with a SQLServerExpress backend.What I have right now is a ListBox bound to my database that displays a list of common names of birds and when the user clicks on an item in the listbox the main image on the page is changed to the image for that bird. For style reasons I want the listbox to always be a fixed size and because I specify the size (using CSS) a vertical scrollbar appears. My problem is that I want to provide my own images of arrows that go above and below the box such that when the user hovers over an arrow the box scrolls slowly and when the user clicks an arow the box scrolls quickly. Finally, my main problem is that I want to get rid of the ugly default vertical scrollbar that comes with ListBox.

Can you guys help me figure out how to do this? I don't mind using a different control other than ListBox as long as it is available in ASP.NET 2.0 and as long as it can be bound to my db. I also don't mind using JavaScript (which I'm sure I'll end up doing for the hover effects). Right now I'm fooling around with subclassing the ListBox control but I've never subclassed a control before so I'm somewhat clueless.

View 3 Replies

Forms Data Controls :: Adding A Calculated Field To A Databound Control?

Oct 19, 2010

I'm using a gridview to extract a set of records. I need to add another field to the gridview, which can calculate the difference between a date associated with each record and the current date.

View 6 Replies

Forms Data Controls :: Eval(), XPath(), And Bind() Can Only Be Used In The Context Of A Databound Control?

Mar 9, 2010

I have a big problem...I have made a page has a Data FormView controland the insert template of this Formview control has DropDownList to allow the user to choose section (SectionsDDList)..and there's also another DropDownList allow the user to choose a teacher (TeachersDDList)...more infothe SectionsDDList get the section list from SqlDataSource control which the "Select Command" of is:"SELECT section_id,section_id FROM sections"the TeachersDDList get the teachers list from another SqlDataSource control which the "Select Command" of is:"SELECT teacher_id,teacher_name FROM teachers WHERE (section_id = @section_id)"finallyI want the TeachersDDList to be filled with teachers according to the selected section from the SectionsDDList...So,I enable the Auto postBack function of the SectionsDDListand add the next code for the SectionsDDList_SelectedIndexChanged event:TeachersDataSource.SelectParameters["section_id"].DefaultValue = ((DropDownList)sender).SelectedValue;be aware that both of the SectionsDDList & TeachersDDList have been Bounding to a column...and the problem I have faced is that:Exception Details: System.InvalidOperationException: Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.maybe you want to know the Stack Trace:[InvalidOperationException: Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.]

System.Web.UI.Page.GetDataItem() +93
System.Web.UI.TemplateControl.Eval(String expression) +33
ASP.cpanel_managecourses_aspx.__DataBinding__control82(Object sender, EventArgs e) in

[code]...

View 8 Replies

Web Forms :: Add A DataList Databound Value Inside A FormViews DataBound Value

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

Forms Data Controls :: Passing The Underlying Data Of The Databound Control?

Mar 30, 2010

In my asp.net web page i have a dropdown box. Say like i have to bind EmployeeName to this dropdown box to show up as items.

I am using a dataTable to bind to this grid by having two columns in DataTable (EmployeeId and EmployeeName). But i am only binding the EmployeeName to the dropdown list box.

In the UI, after the user selects an Employee, I need to pass that employee's id to a function. Is there any way, i can directly pass the underlying data (EmployeeID in the DataTable attached to this dropdown), when the user selects the EmployeeName from the dropdown. Or i will have to make a roundtrip to the database and get the selected Employee's Id and then pass it to the function.

View 2 Replies

Forms Data Controls :: Dynamic Size For Chart Control / Using The Control In Web Application

Feb 22, 2010

using the control in web application.

View 1 Replies

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

C# - LoginView Not Display Databound Control?

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

DataBound Event Is Not Available For DataList Control?

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

Get Item Index From Databound Control?

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

Databound Control From An ObjectDataSource Event?

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

Web Forms :: How To Control Custom Templated Databound

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

.net - Calendar Control To Show Databound Date?

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







Copyrights 2005-15 www.BigResource.com, All rights reserved