473,654 Members | 3,096 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.EventArg s)
Handles Me.Load
...
sConnectionStri ng = "Provider = Microsoft.Jet.O LEDB.4.0; Data Source
= c:\mydb.mdb"
sql = "SELECT [color] FROM [color];"
d = New OleDbDataAdapte r(sql, sConnectionStri ng)
ds = New DataSet()
x = d.Fill(ds)

If Page.IsPostBack Then
dindex = DropDownList1.S electedIndex
dvalue = DropDownList1.S electedValue
DropDownList1.I tems.Clear()
End If

z = New ListItem("choos e a color", "choose")
DropDownList1.I tems.Add(z)

For i = 0 To x - 1
kl = ds.Tables(0).Ro ws(i).Item(0)
z = New ListItem(kl, kl)
DropDownList1.I tems.Add(z)
Next
End Sub

Protected Sub DropDownList1_S electedIndexCha nged(ByVal sender As Object,
ByVal e As System.EventArg s) Handles DropDownList1.S electedIndexCha nged
If dindex 0 Then '0 = "choose"
DropDownList1.S electedValue = dvalue
End If
End Sub
End Class

Here part of the aspx file:
---------------------------
<asp:SqlDataSou rce ID="SqlDataSour ce1" runat="server"
ConflictDetecti on="CompareAllV alues"
ConnectionStrin g="Provider=Mic rosoft.Jet.OLED B.4.0;Data Source=C:\mydb. mdb"
OldValuesParame terFormatString ="original_{ 0}"
ProviderName="S ystem.Data.OleD b"
SelectCommand=" SELECT * FROM [place]"
UpdateCommand=" UPDATE [place] SET [placename] = ?, [color] = @color WHERE
[placenr] = ?">
<UpdateParamete rs>
<asp:Paramete r Name="placename " Type="String" />
<asp:ControlPar ameter ControlID="drop downlist1"
Name="color" PropertyName="S electedValue" Type="String" />

<asp:Paramete r Name="original_ placenr" Type="Int32" />
<asp:Paramete r Name="original_ placename" Type="String" />
<asp:Paramete r Name="original_ color" Type="String" />
</UpdateParameter s>
</asp:SqlDataSour ce>

<asp:GridView ID="GridView1" runat="server" AllowPaging="Tr ue"
AutoGenerateCol umns="False" CellPadding="4"
DataKeyNames="p lacenr" DataSourceID="S qlDataSource1">
<Columns>
<asp:CommandFie ld ShowEditButton= "True"/>
<asp:BoundFie ld DataField="plac enr" ReadOnly="True"/>
<asp:BoundFie ld DataField="plac ename" />
<asp:BoundFie ld DataField="colo r" ReadOnly="True" />
</Columns>
</asp:GridView>
<asp:DropDownLi st ID="DropDownLis t1"
runat="server" AutoPostBack="T rue">
</asp:DropDownLis t>
Aug 15 '06 #1
0 1615

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

Similar topics

4
9790
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" AutoGenerateColumns="False" OnSelectedIndexChanged="gvOrderList_SelectedIndexChanged"> <Columns>
0
1221
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
4599
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 datasource to this GridView in runtime. But I cannot
1
1368
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 displays all fields <asp:GridView ID="gvwOnline" runat="server"> <Columns>
3
2259
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 underneath it for users to collapse detail rows leaving the title row visible. The button can be clicked again to show the details. This used to work great using a DataGrid but when I upgraded it to a GridView I experience the following problem:
4
3846
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 'OldValuesParameterFormatString="original_{0}"'. It works updates data when UpdateCommand has "...WHERE (id = 1)", so I think that problem is with @original_value, it is problably empty...
1
2039
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 to view other records. For that I have given the coding as protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) { GridView1.PageIndex = e.NewPageIndex; GridView1.DataBind(); } ...
5
6079
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
6321
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 address. It's like it's trying to find the address locally. I know it probable has something to do with the url formatting, but not sure what needs to be done. <asp:GridView ID="gvEmployeesBenefits" runat="server" DataSourceID="Benefits"...
5
3936
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 |Jan-09|Qty|Feb-09|Qty|Mar-09 etc ----------------------------------------------------------------- CD|1.00 |$100.00|5.00|$500.00|7.00|$700.00 etc DVD|2.00 |$400.00|7.00|$700.00|8.00|$800.00 etc
0
8290
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8815
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8708
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8489
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8594
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7307
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5622
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
1916
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1596
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.