Different DetailsView templates for items in a GridView. Is it possible?

B

bogdan

Hi,

Can a single GridView be 'connected' to DetailsView that renders itself
differently based on the currently selected row?
I have a GridView with rows that could be displayed in the same way in the
view (like a report) but when a user wants to edit/insert items I'd like to
show a different layout and [possibly] different controls based on the
selected item type. For example, for some items I'd like to provide text
boxes and for others I'd like to provide dropdownlists, extra buttons, etc.

I'd like to have the DetailsView displayed on the same page as the GridView.

Can this be done? If not, any recommendations for alternative solutions?

Thanks,
Bogdan
 
P

Paul Shapiro

You can use Templates for the DetailsView to specify different controls for
display and editing.
 
B

bogdan

But how do I do it dynamically? I could define a single template per field
in DetailsView. What I'd like to do is to (I think) have different
templates for the same fields based on some criteria.
For example, I get an 'item' from db. The 'item' has a column called
'content'. The content (which is a text) can represent a filename, a
paragraph of text, or a line of text. It all depends on a value in another
column of the item.
So, if I a filename is selected in the 'parent' GridView I'd like the
DetailsView display a short text box and have a corresponding validator
attached to it. On the other hand, if a paragraph is selected in the
GridView I'd like DetailsView to display a multiline text box and no
validator.

The item's remaining fields and their templates would identical in all
cases.

Thanks,
Bogdan



Paul Shapiro said:
You can use Templates for the DetailsView to specify different controls
for display and editing.

bogdan said:
Hi,

Can a single GridView be 'connected' to DetailsView that renders itself
differently based on the currently selected row?
I have a GridView with rows that could be displayed in the same way in
the view (like a report) but when a user wants to edit/insert items I'd
like to show a different layout and [possibly] different controls based
on the selected item type. For example, for some items I'd like to
provide text boxes and for others I'd like to provide dropdownlists,
extra buttons, etc.

I'd like to have the DetailsView displayed on the same page as the
GridView.

Can this be done? If not, any recommendations for alternative solutions?
 
P

Paul Shapiro

You might want to rethink the db design a bit. One field should really have
one meaning, not dependent on the values of other fields, like the meaning
of content depends on content type in this example.

I'm pretty new at asp.net development, so you might get better suggestions
from people with more experience. One possibility for alternate templates
would be to include the same field as many times as you have desired control
types. Then hide all but the appropriate control depending on the content
type.

bogdan said:
But how do I do it dynamically? I could define a single template per
field in DetailsView. What I'd like to do is to (I think) have different
templates for the same fields based on some criteria.
For example, I get an 'item' from db. The 'item' has a column called
'content'. The content (which is a text) can represent a filename, a
paragraph of text, or a line of text. It all depends on a value in
another column of the item.
So, if I a filename is selected in the 'parent' GridView I'd like the
DetailsView display a short text box and have a corresponding validator
attached to it. On the other hand, if a paragraph is selected in the
GridView I'd like DetailsView to display a multiline text box and no
validator.

The item's remaining fields and their templates would identical in all
cases.

Thanks,
Bogdan



Paul Shapiro said:
You can use Templates for the DetailsView to specify different controls
for display and editing.

bogdan said:
Hi,

Can a single GridView be 'connected' to DetailsView that renders itself
differently based on the currently selected row?
I have a GridView with rows that could be displayed in the same way in
the view (like a report) but when a user wants to edit/insert items I'd
like to show a different layout and [possibly] different controls based
on the selected item type. For example, for some items I'd like to
provide text boxes and for others I'd like to provide dropdownlists,
extra buttons, etc.

I'd like to have the DetailsView displayed on the same page as the
GridView.

Can this be done? If not, any recommendations for alternative
solutions?
 

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

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,710
Latest member
bernietqt

Latest Threads

Top