Solved

Addiing a drop down list box in a DetailsView cotrol

Posted on 2008-09-30
8
1,078 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
  • 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

828 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