Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1098
  • Last Modified:

Addiing a drop down list box in a DetailsView cotrol

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
bfeddish
Asked:
bfeddish
  • 5
  • 3
1 Solution
 
David RobitailleAnalyst ProgrammerCommented:
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
 
David RobitailleAnalyst ProgrammerCommented:
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
 
David RobitailleAnalyst ProgrammerCommented:

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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
bfeddishAuthor Commented:
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
 
David RobitailleAnalyst ProgrammerCommented:
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
 
bfeddishAuthor Commented:

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
 
David RobitailleAnalyst ProgrammerCommented:
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
 
bfeddishAuthor Commented:
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now