Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > problem about combination gridview-dropdownlist (and selectedvalue)

Thread Tools

problem about combination gridview-dropdownlist (and selectedvalue)

Posts: n/a

It's about a database containing (for simplifying) three fields: 'placenr'
(primary key), 'place' and 'color'. The records are updatable (Edit/Update
button) in a gridview. For updating the field 'color', the selectedvalue of
a dropdownlist must be used, containing all possible colors (red, blue ...),
so the field 'color' is ReadOnly in the gridview.
Everything works, but i still have 2 problems:

1)the new color in the field is always the first element of the dropdownlist
(here the value "choose"), whatever i choose in it.
2)If only the field 'place' must be updated but not the field 'color'(no
click in the dropdownlist), the original color in the field 'color' is
nevertheless always replaced by the first value (again value "choose") in
the dropdownlist.

Any hints or idea for solving that?


Here part of the code-behind file:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load
sConnectionString = "Provider = Microsoft.Jet.OLEDB.4.0; Data Source
= c:\mydb.mdb"
sql = "SELECT [color] FROM [color];"
d = New OleDbDataAdapter(sql, sConnectionString)
ds = New DataSet()
x = d.Fill(ds)

If Page.IsPostBack Then
dindex = DropDownList1.SelectedIndex
dvalue = DropDownList1.SelectedValue
End If

z = New ListItem("choose a color", "choose")

For i = 0 To x - 1
kl = ds.Tables(0).Rows(i).Item(0)
z = New ListItem(kl, kl)
End Sub

Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
If dindex > 0 Then '0 = "choose"
DropDownList1.SelectedValue = dvalue
End If
End Sub
End Class

Here part of the aspx file:
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0 ;Data Source=C:\mydb.mdb"
SelectCommand="SELECT * FROM [place]"
UpdateCommand="UPDATE [place] SET [placename] = ?, [color] = @color WHERE
[placenr] = ?">
<asparameter Name="placename" Type="String" />
<asp:ControlParameter ControlID="dropdownlist1"
Name="color" PropertyName="SelectedValue" Type="String" />

<asparameter Name="original_placenr" Type="Int32" />
<asparameter Name="original_placename" Type="String" />
<asparameter Name="original_color" Type="String" />

<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AutoGenerateColumns="False" CellPadding="4"
DataKeyNames="placenr" DataSourceID="SqlDataSource1">
<asp:CommandField ShowEditButton="True"/>
<asp:BoundField DataField="placenr" ReadOnly="True"/>
<asp:BoundField DataField="placename" />
<asp:BoundField DataField="color" ReadOnly="True" />
<aspropDownList ID="DropDownList1"
runat="server" AutoPostBack="True">

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
problem with keys combination! Alex Python 4 07-11-2009 10:39 AM
problem about combination gridview-dropdownlist (and selectedvalue) Ben ASP .Net 0 08-15-2006 04:22 PM
Combination problem - fast algorithm aka_eu C Programming 6 04-29-2006 11:52 PM
char* combination problem :( x C++ 9 04-14-2004 01:34 PM
problem to fill a combination of containers Helene Pinol C++ 4 06-27-2003 09:43 AM