473,401 Members | 2,125 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

databinding at runtime.

I kind of understand how the below works, however I am trying to do it at runtime vrs design time.

<asp:TextBox id="TextBox1" runat="server" Text='<%# StateList.SelectedItem.Text %>'></asp:TextBox>

So what I really want to do is something like I show below.

In Page_Load I have:

TextBox txt;
txt= new TextBox();
Color clr = new Color() ;
clr = Color.DeepSkyBlue;
txt.BackColor = clr;
txt.Style["Left"] = 10 + "px";
txt.Style["Top"] = 200 + "px";
txt.Style["Width"] = 200 + "px";
txt.Style["Height"] = 80 + "px";
txt.Text = "<%# StateList.SelectedItem.Text %>"; // <--- Should I be able to do this at runtime?
PlaceHolder1.Controls.Add(txt);

And in aspx I have:
<asp:placeholder id="PlaceHolder1" runat="server"></asp:placeholder>

StateList is a list control but when setup using the PlaceHolder I do not get any binding to take place.

Thanks for your pointers!

Al
Nov 19 '05 #1
2 1659
> txt.Text = "<%# StateList.SelectedItem.Text %>"; // <--- Should I be

The <%# %> syntax simply created this line of code:

txt.Text = StateList.SelectedItem.Text;

The main thing is when the line of code executes. <%# %> happens during databinding,
whereas <%= %> and <% %> happen during Rendering. DataBinding in v1.1 is
explicit, so it happens when you call it.

-Brock
DevelopMentor
http://staff.develop.com/ballen


Nov 19 '05 #2
I think I understand what you said but my question is can I set the tags at runtime using a placeholder. My tests do confirm that is does not work as in my original post. So I am not sure if I am doing something wrong or that's the way it is..

<%# %> happens during databinding.... OK, it happens during databinding, but can I build it up at runtime as in...

TextBox txt;
txt= new TextBox();
Color clr = new Color() ;
clr = Color.DeepSkyBlue;
txt.BackColor = clr;
txt.Style["Left"] = 10 + "px";
txt.Style["Top"] = 200 + "px";
txt.Style["Width"] = 200 + "px";
txt.Style["Height"] = 80 + "px";
txt.Text = "<%# StateList.SelectedItem.Text %>"; // <--- Should I be able to do this at runtime for it does not seem to work?
PlaceHolder1.Controls.Add(txt);
Thanks
Al
"Brock Allen" <ba****@NOSPAMdevelop.com> wrote in message news:47**********************@msnews.microsoft.com ...
txt.Text = "<%# StateList.SelectedItem.Text %>"; // <--- Should I be


The <%# %> syntax simply created this line of code:

txt.Text = StateList.SelectedItem.Text;

The main thing is when the line of code executes. <%# %> happens during databinding,
whereas <%= %> and <% %> happen during Rendering. DataBinding in v1.1 is
explicit, so it happens when you call it.

-Brock
DevelopMentor
http://staff.develop.com/ballen



Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: CGuy | last post by:
Hi, I have an ASPX page which has a datagrid and this datagrid is bound to a Custom Collection. sample code this.DataGrid1.DataSource = UserManager.Users; this.DataGrid1.DataBind();
1
by: Ben R. | last post by:
This question refers to: http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q313482 First question: >> The following code binds a TextBox control and a DataGrid control to the same...
0
by: Thomas | last post by:
I have a dropdownlist whose items are bind to it during runtime. I do it in the databinding event, but the event handler was never get called. Finally I have to do the databinding in the prerender...
2
by: Steven | last post by:
Hi, I'm having an odd problem with late databinding (using DataBinder.Eval). I have my Business Logic and Facade assemblies in the GAC, and just about everything works fine, however, when using...
0
by: Simon Gregory | last post by:
I am currently attempting to figure out how the new databinding stucture works in ASP.NET 2.0 after working with v1.0 & v1.1 for several years. It seems that if you wish to do set up databinding...
8
by: GaryDean | last post by:
We have been noticing that questions on vs.2005/2.0 don't appear to get much in answers so I'm reposting some questions posted by some of the programmers here in our organization that never got...
9
by: J055 | last post by:
Hi I have a very simple configuration of the GridView with paging and sorting. When I do a postback the DataBinding event fires twice - in both the ProcessPostData and PreRender stages of the...
1
by: Mark Stafford | last post by:
I am attempting to use a DetailsView control to view some data where the fields returned by the database are determined at runtime. I create the TemplateFields on the fly using a class that...
7
by: JTC^..^ | last post by:
When i attempt to bind to the "Text" and "Value" property of a combobox on a windows form the value is reset when I leave the combobox. The comboboxes contain the correct Text and Values. I know...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.