473,839 Members | 1,439 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 1624

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

Similar topics

4
9815
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
1230
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
4612
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
1377
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
2265
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
3855
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
2048
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
6084
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
6329
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
3948
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
9856
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10597
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...
0
10299
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
9434
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...
1
7834
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7022
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();...
0
5872
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4071
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3136
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.