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

Gridview with two dropdownlists causing error.

19
I have a dropdownlist2 in a gridview whose datasource and select control parameter is based on the selected value of dropdownlist1 in the same gridview. Everything works great for insert, but when I edit the row in the gridview and change the selected value in dropdownlist1, I get an error of "'dropdownlist2' has a SelectedValue which is invalid because it does not exist in the list of items. Parameter name: value" This kinda makes sense to me. At what stage (maybe drowdownlist1 selectedindexchanged?) do I tell dropdownlist2 that it needs to requery so I don't get the error. I can just tell it to select the 0 index by default here for dropdownlist2. An example would be lovely.

Tried the following on Dropdownlist1.selected item changed with the same error:
Expand|Select|Wrap|Line Numbers
  1.          'Grabbing a reference to the ddl1 that raised the event 
  2.         Dim ddl1 As DropDownList = CType(sender, DropDownList)
  3.  
  4.         'Grabbing a reference to the GridViewRow that the ddl1 belongs to  
  5.         'so that I can grab a reference to the ddl2 that belongs to that row 
  6.         Dim gridViewRowDdlBelongsTo As GridViewRow = CType(CType(sender, Control).NamingContainer, GridViewRow)
  7.  
  8.         'Grabbing a reference to ddl2 that is in the same row as ddl1 
  9.         Dim ddl2 As DropDownList = Nothing
  10.         If gridViewRowDdlBelongsTo IsNot Nothing Then
  11.             ddl2 = CType(gridViewRowDdlBelongsTo.FindControl("roomDDLE"), DropDownList)
  12.         End If
  13.  
  14.         'Generating the data source for ddl2 depending on what was selected in ddl1 
  15.         Dim mySql As String = "select ID, Name from dbo.myDatabase where ID=" & ddl1.SelectedItem.Value.ToString
  16.         Dim ds As New Data.DataSet
  17.         Dim strConn As String = ConfigurationManager.ConnectionStrings("strConn").ConnectionString
  18.         Dim cn As New Data.SqlClient.SqlConnection(strConn)
  19.         Dim da As New Data.SqlClient.SqlDataAdapter
  20.         da = New Data.SqlClient.SqlDataAdapter(mySql, cn)
  21.         da.Fill(ds, "newTable")
  22.  
  23.  
  24.         'Setting the datasource for ddl2 in the row, and binding to it. 
  25.         If ddl2 IsNot Nothing Then
  26.             ddl2.DataSource = ds.Tables("newTable")
  27.             ddl2.DataBind()
  28.             ddl2.SelectedIndex = 0
  29.         End If
  30.  
May 24 '10 #1
0 1143

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: TJ | last post by:
I am running PHP version 4.3.4 I am running an Apache server I am running on Windows 2000 My PHP server has run perfectly since it was installed last November. However, I just uncommented the...
2
by: RK | last post by:
Hi I am using the following code in the button_click event in xxxxx.htm page which is URL for the showModalDialog window. function btnAddComment_Onclick() { var user_info = new...
1
by: Bryan | last post by:
I have the following in my asp.net html page <script language="JavaScript" type=text/javascript Function loader() <% If Not Page.IsPostBack Then % document.form1.submit() <% End If % ...
4
by: Slasher186 | last post by:
Hi all, First of all, I'm sorry if I posted at the wrong section here, but I can't seem to find the VB 6.0 newsgroup ? I'm developing my apps with VB 6.0 sp5 installed on win xp. I have create...
2
by: tacmec | last post by:
ASP.NET 2.0 (C#) application. I have a web form with a GridView, which is populated dynamically. See the code below. First time to the page, IsPostBack is false. Therefore, DisplayItems() is...
2
by: DCC700 | last post by:
VS 2005 Converted Header causing error when publishing After converting from Visual Studio 2003 to 2005, I have had several issues with a header that is used throughout the project. The...
0
by: David | last post by:
Using ASP.Net 2.0 and I have identical code for exporting a GridView to Excel in 2 web sites. One works fine and the 2nd one gives me the error "RegisterForEventValidation can only be called...
3
by: =?Utf-8?B?bWFuaWthMDI=?= | last post by:
Hi, I have a GridView control in page called eventslisting which is inheriting from a MasterPage. The normal code to export to GridView does not work and gives me an error - "Control of type...
0
by: Joe Kovac | last post by:
Hi! When using a GridView errors as follow might occur (in the DataLayer): - duplicate key - can`t delete due to references - SQL does nothing (e.g. update with wrong WHERE clause) - etc. ...
0
by: Paul | last post by:
In GridView if I make the CommandArgument of a link button a string created from something like myGuid.ToString() the RowCommand handler dies with an error I can't track down. The only thing I know...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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:
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...
0
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...

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.