473,323 Members | 1,551 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,323 software developers and data experts.

problem about combination gridview-dropdownlist (and selectedvalue)

Ben
Hi,

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?

Thanks
Ben

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
DropDownList1.Items.Clear()
End If

z = New ListItem("choose a color", "choose")
DropDownList1.Items.Add(z)

For i = 0 To x - 1
kl = ds.Tables(0).Rows(i).Item(0)
z = New ListItem(kl, kl)
DropDownList1.Items.Add(z)
Next
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"
ConflictDetection="CompareAllValues"
ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0 ;Data Source=C:\mydb.mdb"
OldValuesParameterFormatString="original_{0}"
ProviderName="System.Data.OleDb"
SelectCommand="SELECT * FROM [place]"
UpdateCommand="UPDATE [place] SET [placename] = ?, [color] = @color WHERE
[placenr] = ?">
<UpdateParameters>
<asp:Parameter Name="placename" Type="String" />
<asp:ControlParameter ControlID="dropdownlist1"
Name="color" PropertyName="SelectedValue" Type="String" />

<asp:Parameter Name="original_placenr" Type="Int32" />
<asp:Parameter Name="original_placename" Type="String" />
<asp:Parameter Name="original_color" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>

<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AutoGenerateColumns="False" CellPadding="4"
DataKeyNames="placenr" DataSourceID="SqlDataSource1">
<Columns>
<asp:CommandField ShowEditButton="True"/>
<asp:BoundField DataField="placenr" ReadOnly="True"/>
<asp:BoundField DataField="placename" />
<asp:BoundField DataField="color" ReadOnly="True" />
</Columns>
</asp:GridView>
<asp:DropDownList ID="DropDownList1"
runat="server" AutoPostBack="True">
</asp:DropDownList>
Aug 15 '06 #1
0 1606

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

Similar topics

4
by: ber.janssens | last post by:
Hi, In ASP.NET 2.0, I have a GridView with 2 CommandFields, how can I determine in the SelectedIndexChanged event which CommandField is clicked? <asp:GridView ID="gvOrderList" runat="server"...
0
by: Mudassar | last post by:
I am facing a problem while accessing the gridview in nested gridview structure. Some time i found child gridview control but when i bind data to child gridview it doesnt
3
by: Jeff | last post by:
Hey asp.net 2.0 In the source I posted below, there is a GridView (look at the bottom of the script): <asp:GridView ID="gvwOnline" runat="server"> </asp:GridView> I'm trying to assign a...
1
by: Jeff | last post by:
Hey asp.net 2.0 I have this GridView in my web page. My problem is that it get populated with all the fields of the MembershipUser class. I thought only UserName would be displayed, but it...
3
by: =?Utf-8?B?c2hhcnJpczEyMzQ1?= | last post by:
Hi, I have a GridView that has one column that I fill with an alternating "Title Row" then "Details Row". The Title row has a button that I use to hide it's corresponding details row that is...
4
by: etam | last post by:
Hi, I am trying to build updateable GridView. I can't see the problem with this code but it simply doesnt update the DataSet. It doesnt work with or without...
1
by: suganya | last post by:
I have displayed the data from the DB to the GridView made a column in the GridView as HyperLink allowed paging by setting the Allow Paging Property to "True". By clicking on the page no link I have...
5
by: Eric | last post by:
Hi, there are several gridviews all with a linkbutton which all trigger the same procedure. I need to know from which gridview the linkbutton has been clicked. Thanks Eric Here the code:
9
by: kimbred | last post by:
I have a gridview that has a hyperlink column. It gets the web address from a data source. This is all working as it should. The problem is when I click the web address, it doesn't go to the...
5
by: DeMuy | last post by:
I have a gridview with AutoGenerateColumns=true that is presenting a challenge to me. Challenge #1 The data structure from the database server follows: Product |Qty...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.