473,378 Members | 1,564 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

problem with updating from dropdownlist in detailsview

Dan
Hi,

I have a detailsview with two fields: in editmode, one is a textbox and the
other is a dropdownlist.
i want to update both fields using the detailsview.
My problem: when clicking on the edit button, the modified text in the
textbox is effectively updated in the table, but instead of updating the
chosen value of the dropdownlist, the field in the table becomes empty (old
value is updated by nothing).
The items of the dropdownlist comes from table ("fotos"), but the
selectedvalue comes from table("inhoud").
In editmode, i can see all the items of the dropdownlist and the
selectedvalue is also right.

Protected Sub DetailsView1_DataBound(ByVal sender As Object, ByVal e As
System.EventArgs) Handles DetailsView1.DataBound
Dim sql, foto, fotosel As String
Dim comd As SqlCommand
Dim dtreader As SqlDataReader
Dim dd1 As DropDownList
Dim z1 As ListItem

' i read here the value which must be the selectedvalue of the
dropdownlist
Using mConnection As New SqlConnection(param.ConnectionString)
sql = "select foto_n1 from inhoud"
comd = New SqlCommand(sql, mConnection)
mConnection.Open()
dtreader = comd.ExecuteReader
dtreader.Read()
If Not dtreader.IsDBNull(0) Then fotosel = dtreader.GetString(0)
dtreader.Close()

'i read here all the possible items of the dropdownlist and put
them in the DD
sql = "select foto_na from fotos"
comd = New SqlCommand(sql, mConnection)
dtreader = comd.ExecuteReader
If dtreader.HasRows Then
While dtreader.Read()
foto = dtreader.GetString(0)
If DetailsView1.CurrentMode = DetailsViewMode.Edit Then
dd1 = DetailsView1.Rows(1).FindControl("dd1")
z1 = New ListItem(foto, foto)
dd1.Items.Add(z1)
dd1.SelectedValue = fotosel
End If
End While
End If
dtreader.Close()
End Using
End Sub
aspx:
----
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:myconn %>"
SelectCommand="SELECT * FROM [inhoud]"
UpdateCommand="UPDATE [inhoud] SET [foto_n1] = @foto_n1, [n1] =
@n1 WHERE [id] = @id">
<UpdateParameters>
<asp:Parameter Name="foto_n1" Type="String" />
<asp:Parameter Name="n1" Type="String" />
<asp:Parameter Name="id" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>

<asp:DetailsView ID="DetailsView1" runat="server" AllowPaging="True"
AutoGenerateEditButton="True" AutoGenerateRows="False" DataKeyNames="id"
DataSourceID="SqlDataSource1" >
<Fields>
<asp:BoundField DataField="id" HeaderText="id"
InsertVisible="False"
ReadOnly="True" Visible="false" SortExpression="id" />

<asp:TemplateField HeaderText="foto niveau 1">
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%#
Bind("foto_n1") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="dd1" runat="server"
Width="155px">
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>

<asp:TemplateField HeaderText="niveau 1">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("n1")
%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TextBox1" TextMode="MultiLine"
height="340px" runat="server" Text='<%# Bind("n1") %>'
Width="600px"></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
</Fields>
</asp:DetailsView>
Oct 12 '08 #1
0 1454

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Murugan V via DotNetMonster.com | last post by:
Hi, i want to add the DropDownList,TextBox and Label in detailsview dynamically at runtime.At the page load, the detailsview displayed the records.when i click the edit button,these controls should...
2
by: Ram | last post by:
I'm using detailsview control with a template field which contains a dropdownlist I databind the dropdownlist during page load, now the problem is dropdownlist loses state during postbacks, i...
2
by: clickon | last post by:
I am using ASP.net 2.0 and trying to take advantage of the updated data editing facilities provided through the SQLDataSource control and the DetailsView control. The data is a record from a...
1
by: Michael Gross | last post by:
Hello I have a GridView, and a DetailsView to edit the data. In the DetailsView I have two TemplateFields with a DropDownList in each TemplateField. Now I want that when the user selects an item...
2
by: André | last post by:
Hi, I made a detailsview containing several fields for inserting only. I also made a dropdownlist which is invisible at start. Now, when clicking in a particular textbox, the dropdownlist must...
0
by: inf42 | last post by:
The issue is this. Have one table with two others related to it. Now I use the others to display the proper names in the field, which there indexes are stored in the table I want to update the data...
0
by: 47computers | last post by:
Hello. I'm having a bit of difficulty with some DropDownList controls within templates in a DetailsView on my web form. Basically, I have a form where a user is building a "location profile" with...
1
by: JJ | last post by:
Hi. I am having trouble getting a dropdownlist to work properly in a detailsview: The code is something like: <asp:DetailsView ID="dvwSubscriber" runat="server" AutoGenerateRows="False" ...
3
by: EdisonCPP | last post by:
Hi, I have a DetailsView with a template field with a dropdownlist added to it. If the data coming into that field were put into a textbox, it would look like: Small|Medium|Large|X-Large. I...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.