473,800 Members | 2,648 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Re: DropDownList in Gridview when item does not exist in ddl

I answered my own question. Here's what I did to solve this:

1. Deleted the "selected value="<%# bind("driver") %>" from the
dropdownlist. (i did not have this code in my above posting)
2. Placed "Imports System.Data" at the top of my code page to
accomodate for the "DataRowVie w"
3. Entered the following code in my dropdownlist_da tabound. I got
this code from teh following website:

http://www.webswapp.com/codesamples/...s/default.aspx
(he has codebehind in C# or VB)

Protected Sub ddlTruckDrivers 1_DataBound(ByV al sender As Object,
ByVal e As System.EventArg s)
Dim ddl As DropDownList = DirectCast(send er, DropDownList)
'=== add an empty item on top of the list

Dim gvRow As GridViewRow = DirectCast(ddl. NamingContainer ,
GridViewRow)
'check to see if the item exists in the gridview, if it doesn't then
it will default to the first item in the dropdownlist
If Not gvRow.DataItem Is Nothing Then
Dim strDriver As String = DirectCast(gvRo w.DataItem,
DataRowView)("d river").ToStrin g
'be careful of the possibility that the value saved on
the database does not exist
'in the valid selections that are displayed on the list
ddl.ClearSelect ion()
Dim li As ListItem = ddl.Items.FindB yValue(strDrive r)
If Not li Is Nothing Then li.Selected = True

End If
End Sub

4. This small piece of data to set the value of the update parameter:

Protected Sub glTrucks_RowUpd ating(ByVal sender As Object, ByVal e
As System.Web.UI.W ebControls.Grid ViewUpdateEvent Args) Handles
glTrucks.RowUpd ating
e.NewValues("dr iver") =
CType(glTrucks. Rows(e.RowIndex ).FindControl(" ddlTruckDrivers 1"),
DropDownList).S electedValue
End Sub
Nov 6 '08 #1
0 1462

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

Similar topics

6
8274
by: Dabbler | last post by:
I have a dropdownlist in a GridView ItemTemplate. I need to bind the ddl to an SqlDataSource, then have a value from a boundfield in the row be passed as the keyfield for select where clause. Im trying to load the ddl with a list of dates from another table keyed on GridView row field that only apply to this row. Any suggestions would be appreciated.
2
7788
by: keithb | last post by:
I have dropdown list in a gridview column edit template. It works OK, except when I edit a row, the dropdown list does not initialize to the existing value that shows in the textbox that displays in the item template. I tried to initialize the selected value of the dropdown list with some lines of code in the grid_RowEditing event but I get an error that I do not understand. The error occurs at this line of code: String DelID =...
0
1622
by: Ben | last post by:
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...
6
1482
by: needin4mation | last post by:
I have a gridview and a dropdownlist. If I change the ddl, the gridview populates. That is what I want. But what I don't want is for it to happen the first time they get to the page. I know I can add a "Select Item," but is that the correct way to do it? I don't want it to hit the database at all the first time the page loads. I have done everything through visual studio and was trying to see if I could do this with no code behind. ...
1
7767
by: mitchman10 | last post by:
My Time table has TimeID,Employee,PayPeriod,ChargeCodeID,Hours My Chargecode table has ChargecodeID,c_Text I need an Editable datagrid that will show the TimeID,Employee,PayPeriod,C_Text in a label and hours, along with an edit linkbutton. When they click on edit, the edit button turns to Update Cancel TimeID stays read Only
1
2707
by: mark4asp | last post by:
I moved a page to another web-site and now it's broke! I had 5 pages in their own web-site. These pages have now been moved to another web-site. Everything is fine except that one of the pages, which I had trouble with in the past (i.e. same problem), is now partly broke. The paging no longer fully works in the gridview. The gvAwarded_RowDataBound code works to load the ddlPager with the correct number of pages.
0
1812
by: Moneypenny | last post by:
Hi there, I have a Gridview control which has a dropdownlist in every row. The dropdowns are populated dynamically from a database (so the content is different in each row. There is also a select button for each row so that the the user can choose a row and the values will be added to a shopping cart. My problem is that the page loads fine and everything is showing as it should be. However, when I select a row the dropdownlist for that row...
2
2022
by: steven | last post by:
i've got a dropDownList that I'm trying to populate from my code behind as follows: uxVehicleColourEdit.DataSource = oDsLookups.Tables; if the dropDown is placed inside a datagrid, i get compile time errors stating the control doesn't exist in the current content: <asp:DataGrid ID="tmp" runat="server"> <Columns>
1
4943
by: Brett | last post by:
I have a DropDownList in an ASP.NET web form that is populated with items from a lookup table by binding that DropDownList to a SqlDataSource. However, the items in the lookup table can change over time. The problem is that when an item has been removed from the lookup table, and a user wants to retrieve a record that used the deleted item, the following error occurs: 'ddlAssignedTo' has a SelectedValue which is invalid because it...
0
9550
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
10273
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
10250
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
9085
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
7574
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
6811
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
5469
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5603
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4149
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.