473,654 Members | 3,114 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Changing controls at runtime

Hi, I am a long time ASP developer learning .NET, so please bear with
me. I am trying to find an article or such that will help me understand
how to change control properties at runtime based on the value in a
field.

For instance, if I want to add some text to a field in a GridView based
on a boolean value in an un-shown field being returned.

Another example would be if I want to bind a Listbox to a table of
people, however I want to concatenate the first and last name fields to
be displayed?

I would think there is some way to configure this in the controls
themselves, which would also be nice to know how to do, but I have run
into this same problem with other controls so I would like to
understand how to reference the data fields at runtime.

Any help/links would be greatly appreciated. Thanks!

- Tom

Oct 5 '06 #1
2 1801
Tom,

Welcome to Asp.Net!

For the GridView task you need to handle RowDataBound event. The event fires
for every row after the row controls get populated from the datasource. The
event can access the row object whose DataItem property points to the
datasource item that served data to the row. You should typecast it to your
datasource item type and then you can access all data fields in the
datasource item. look in the MSDN library for more info and examples.

For the Listbox task you would need to get the table first and then populate
the Listbox programmaticall y. That is because Listbox control doesn't
provide any events on item databinding.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
<tf*****@gmail. comwrote in message
news:11******** *************@i 42g2000cwa.goog legroups.com...
Hi, I am a long time ASP developer learning .NET, so please bear with
me. I am trying to find an article or such that will help me understand
how to change control properties at runtime based on the value in a
field.

For instance, if I want to add some text to a field in a GridView based
on a boolean value in an un-shown field being returned.

Another example would be if I want to bind a Listbox to a table of
people, however I want to concatenate the first and last name fields to
be displayed?

I would think there is some way to configure this in the controls
themselves, which would also be nice to know how to do, but I have run
into this same problem with other controls so I would like to
understand how to reference the data fields at runtime.

Any help/links would be greatly appreciated. Thanks!

- Tom

Oct 5 '06 #2
Thanks for the response, Eliyahu.

I guess I need to get my head around OOP concepts before this will make
sense to me!

- Tom
Eliyahu Goldin wrote:
Tom,

Welcome to Asp.Net!

For the GridView task you need to handle RowDataBound event. The event fires
for every row after the row controls get populated from the datasource. The
event can access the row object whose DataItem property points to the
datasource item that served data to the row. You should typecast it to your
datasource item type and then you can access all data fields in the
datasource item. look in the MSDN library for more info and examples.

For the Listbox task you would need to get the table first and then populate
the Listbox programmaticall y. That is because Listbox control doesn't
provide any events on item databinding.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
<tf*****@gmail. comwrote in message
news:11******** *************@i 42g2000cwa.goog legroups.com...
Hi, I am a long time ASP developer learning .NET, so please bear with
me. I am trying to find an article or such that will help me understand
how to change control properties at runtime based on the value in a
field.

For instance, if I want to add some text to a field in a GridView based
on a boolean value in an un-shown field being returned.

Another example would be if I want to bind a Listbox to a table of
people, however I want to concatenate the first and last name fields to
be displayed?

I would think there is some way to configure this in the controls
themselves, which would also be nice to know how to do, but I have run
into this same problem with other controls so I would like to
understand how to reference the data fields at runtime.

Any help/links would be greatly appreciated. Thanks!

- Tom
Oct 5 '06 #3

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

Similar topics

2
2367
by: Aaron Queenan | last post by:
Is there any way to change the name of a tab at runtime (after the dialogue has been displayed)? Alternately, is there any way to add and remove tab without causing the screen to flicker? Thanks, Aaron Queenan.
2
1544
by: ilPostino | last post by:
ok, so I have my asp.net application. I want a single page which can load asp user controls and at runtime. How can this be done? I don't want to drag the control onto the page because then I can't change it ... or can I ? thanks C
1
3081
by: rp | last post by:
Hi, How would I create runtime tabpages with runtime controls(textBoxes,comboBox, checkedListBox), inserting,deleting, and modifing the tabpages whenever I want to in C#? Thanks in advance. rp
1
1425
by: Tobe | last post by:
We want to change the autopostback properties (serverside) of all of the dropdownlistboxes on the page. I am trying to loop through the Request.Form.Items, but I can't seem to get more the the current text value of the controls. How can I get the controls themselves?
4
6724
by: Chuck Ritzke | last post by:
Hi, I've searched the newsgroup and other sources to understand how to handle runtime controls and see I'm not the only one who's confused, but I'm still not quite sure of the best way to handle from all the various explanations/answers. I'm attempting the typical scenario... I create a variable number of controls at runtime based on parameters from a database.
3
1963
by: phonl | last post by:
I am a vb6 ADO developer looking at vb.net 2005 and ADO2.net. I used the vb.net 2005 data wizard to bind some controls to a database. Now I want to run a select query and have the bound controls reflect the change from the query. How would I do that? The wizard created a TableAdapter, BindingSource, and DataSet. Somehow I need to run feed them a select query to update the data.
7
2206
by: Varangian | last post by:
Hello is creating controls at runtime the same as designtime ? will a page be faster if controls are created at designtime rather than at runtime ? If so why ? thanks :)
17
2382
by: blufox | last post by:
Hi All, Can i change the execution path of methods in my process at runtime? e.g a()->b()->c()->d()->e() Now, i want execution to be altered at runtime as -
8
4357
Megalog
by: Megalog | last post by:
Hey guys.. my turn to ask a question: I'm having a weird issue with a form I've reworked. This form has a combo box, which when used is changing the recordsource of a subform. This subform has no Master/Child relationship set to the main form. Specifically the problem seems to be that everytime the recordsource of the subform is changed, the subform object itself tries to set a default Master/Child value (both fields fill with the "ID"...
0
8294
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8816
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8494
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6162
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5627
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4150
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4297
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2719
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1924
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.