Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old August 22nd, 2007, 09:11 PM
Authorized User
Join Date: Aug 2007
Posts: 70
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to yukijocelyn
Default DropDownList value insert to MS DB(DetailsView)


I'm experiencing one problem here. I have a DropDownList in my Details View. However, I am unable to get its value(AAA or BBB or CCC) to be inserted into the MS Access database that I want to. The codes are as such:

<asp:AccessDataSource ID="AccessDataSource1" runat="server" ConflictDetection="CompareAllValues" DataFile="~/App_Data/DB.mdb"
DeleteCommand="DELETE FROM [table] WHERE [ID] = ?
InsertCommand="INSERT INTO [table] ([o] VALUES (?)"
OldValuesParameterFormatString="original_{0}" SelectCommand="SELECT [ID], [o] FROM [table]"
UpdateCommand="UPDATE [table] SET [o]] = ? WHERE [ID] = ? ">

<asp:Parameter Name="o" Type="String" />

<asp:DetailsView ID="DetailsView1" runat="server" AllowPaging="True" AutoGenerateRows="False" CellPadding="4" DataKeyNames="ID" DataSourceID="AccessDataSource1" DefaultMode="Insert" ForeColor="#333333" GridLines="None" Height="263px" Style="z-index: 106; left: 8px; position: absolute; top: 93px" Width="694px">
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<CommandRowStyle BackColor="#D1DDF1" Font-Bold="True" />
<EditRowStyle BackColor="#2461BF" />
<RowStyle BackColor="#EFF3FB" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<asp:CommandField ShowInsertButton="True" />
<asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True" SortExpression="allocatedID" />

<asp:BoundField DataField="o" HeaderText="o" SortExpression="o"/>
<asp:TemplateField HeaderText="Company"><EditItemTemplate>
     <asp:DropDownList ID="DropDownList1" runat="server" DataTextField="o" DataValueField="o">
<FieldHeaderStyle BackColor="#DEE8F5" Font-Bold="True" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />

Please advise me on how to go about solving this problem.
Thank you!
Old August 22nd, 2007, 11:31 PM
Registered User
Join Date: Apr 2007
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts

 Hope this helps u
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
DropDownList ddl = (DropDownList)sender;
string selectedStatus = ddl.SelectedValue.ToString();
or can get the value as below in any event, say for example in btnSave_Click
foreach (DetailsViewRow row in DetailsView1)
  DropDownList ddl=(DropDownList)row.FindControl("DropDownList1") ;
  string ddlItem = ddl.SelectedItem.Text;
Store the value of ddlItem in database.


Old August 23rd, 2007, 01:32 AM
Authorized User
Join Date: Aug 2007
Posts: 70
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to yukijocelyn

Hi Sripa!

Thank you so much for your help! I got it already! Thank you!

Similar Threads
Thread Thread Starter Forum Replies Last Post
Cannot bind from DropDownList to DetailsView kiekar ASP.NET 2.0 Basics 0 February 19th, 2008 09:26 PM
Insert DropDownList(DetailsView) value toMS Access yukijocelyn ASP.NET 2.0 Professional 0 August 22nd, 2007 09:49 PM
Re-Binding A Dropdownlist In A DetailsView cyber0ne BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 0 March 26th, 2007 07:10 PM
ASP Insert , MS Access Db tigere Classic ASP Databases 0 November 11th, 2006 08:43 AM
dropdownlist value into detailsview: how? hertendreef ASP.NET 2.0 Professional 0 June 26th, 2006 01:54 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.