Solved

Addiing a drop down list box in a DetailsView cotrol

Posted on 2008-09-30
8
1,082 Views
Last Modified: 2012-06-21
I cannot find any information in any of my books or online tutorials about adding changing a text field in a DetailsView to be a drop down list that is also bould to a code file in the database. What is a good source for information on this?
0
Comment
Question by:bfeddish
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 18

Accepted Solution

by:
David Robitaille earned 500 total points
ID: 22606259
use a template field
http://www.asp.net/learn/data-access/tutorial-13-vb.aspx
and place your drop down list into that template
 
0
 
LVL 18

Expert Comment

by:David Robitaille
ID: 22730343
it<s for a gridview, but it<s the same for a DetailsView
http://msdn.microsoft.com/en-ca/library/ms178294(vs.80).aspx
 
0
 
LVL 18

Expert Comment

by:David Robitaille
ID: 22786270

Could i know, why does it get a "B", if it resolve the issue, I think I should get a "A".
Please read this:
http://www.experts-exchange.com/help.jsp#hi403 
abstract: "an answer is worth an A, unless it doesn't resolve your issue"
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 1

Author Comment

by:bfeddish
ID: 22786375
Correct, it did not complelty answer my question.  The data in the listbox needed to be bound to a table in the database. That tutorial did not mention it. To answer my own question, this is what I was looking for:

 <asp:TemplateField HeaderText="Vendor Type" SortExpression="VendorType">
                    <EditItemTemplate>
                        <asp:DropDownList ID="dd1" runat="server"                        
                        DataSourceID="dsVendorTypes"
                        DataTextField="Description" DataValueField="ID"
                        SelectedValue= '<%# Bind("VendorType") %>' />                        
                    </EditItemTemplate>
                    <InsertItemTemplate>
                        <asp:DropDownList ID="dd1" runat="server"                        
                        DataSourceID="dsVendorTypes"
                        DataTextField="Description"
                        DataValueField="ID"
                        SelectedValue= '<%# Bind("VendorType") %>' />
                    </InsertItemTemplate>
                    <ItemTemplate>
                        <asp:DropDownList ID="dd1" runat="server"                        
                        DataSourceID="dsVendorTypes"
                        DataTextField="Description"
                        DataValueField="ID"
                        SelectedValue= '<%# Bind("VendorType") %>'
                        Enabled = "false"   />
                    </ItemTemplate>
                </asp:TemplateField>
0
 
LVL 18

Expert Comment

by:David Robitaille
ID: 22786459
Thats why I send an second link.
Next time, if it dosen`t fulfill your need, please seen some feedback so experts could provide an more complete answer. Also, if you grade lower than "A", please provide some "Grading comments" that explain why.
It s not because I`m angry, I just want to know so I will be better next time...
 
0
 
LVL 1

Author Comment

by:bfeddish
ID: 22786575

I still had to piece togther the methodology for this. If you look at my code sample above I have the <EditItemTemplate>,  <ItemTemplate> and the <InsertItemTemplate> sections and it took a long time to figure those items out and get my project moving.  Displaying the data in an existing record was one thing but having the drop down box work properly with editing was another.

If this information was in either of the 2 links you sent me then I missed it. If this is the case then if possible I will have them change the grade.
0
 
LVL 18

Expert Comment

by:David Robitaille
ID: 22786743
ok i see...
Has a bonus, when 2 template are the same, you could copy them in the page load event...
this exemple is for a form view, but it should work for a template field

If Not (Page.IsPostBack) Then
'the insert and edit templates are the same
            FormView1.InsertItemTemplate = FormView1.EditItemTemplate
end if
if they are almost the same you could then hide control (or set Enabled = "false" ) part in the DataBount event.
 
0
 
LVL 1

Author Comment

by:bfeddish
ID: 22786804
Thanks for the extra info.

This stuff is frustrationg because there does not seem to be too many good sources on doing everything.  Most books, websites, etc. all just scratch the surface and assume you want to just display a list of data across your screen. None go too deep on data entry forms that most of us developers have been doing for years with standard EXE applications. I can find 100 sources for changing the background color of my grid for every one that shows me how to edit data inside it.
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question