Changing controls at runtime

T

tfsimes

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
 
E

Eliyahu Goldin

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 programmatically. That is because Listbox control doesn't
provide any events on item databinding.
 
T

tfsimes

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 said:
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 programmatically. That is because Listbox control doesn't
provide any events on item databinding.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,742
Latest member
AshliMayer

Latest Threads

Top