Solved

Addiing a drop down list box in a DetailsView cotrol

Posted on 2008-09-30
8
1,073 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
Comment Utility
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
Comment Utility
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
Comment Utility

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
 
LVL 1

Author Comment

by:bfeddish
Comment Utility
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 18

Expert Comment

by:David Robitaille
Comment Utility
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
Comment Utility

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
Comment Utility
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
Comment Utility
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Javascript - getdate 5 50
Swiper slider stops between pages 11 30
Paging GridView 7 32
How can I use this extension method? 8 35
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

771 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now