473,804 Members | 3,043 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

dropdown list in gridview does not seem to display correct data

I have a gridview and in the RowDataBound I have the line of code below. I
have the ObjDtaSce= to the datasource of a dropdown box. I have 3 rows that
are populated and for some reason the dropdown box for all rows is populated
by values expected in the last row only. I checked the ID value and it is
correct for each row. Is there something I would need to reset?

protected void gridview_RowDat aBound(object sender, GridViewRowEven tArgs e)
'''
'''

ObjDtaSce.Selec tParameters["ID"].DefaultValue =Convert.ToStri ng
(integervariabl e);//
thanks.

--
Paul G
Software engineer.
Jul 2 '08 #1
2 1264
You seem to be databinding declaratively with DataSourceID property. In this
case actual select operation takes place in the PreRender event which fires
well after all your RowDataBound events. You need to databind in the
RowDataBound event itself. Simply databind with the DataSource property
instead of DataSourceID and call myDdl.DataBind( ) method.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Paul" <Pa**@discussio ns.microsoft.co mwrote in message
news:BC******** *************** ***********@mic rosoft.com...
>I have a gridview and in the RowDataBound I have the line of code below. I
have the ObjDtaSce= to the datasource of a dropdown box. I have 3 rows
that
are populated and for some reason the dropdown box for all rows is
populated
by values expected in the last row only. I checked the ID value and it is
correct for each row. Is there something I would need to reset?

protected void gridview_RowDat aBound(object sender, GridViewRowEven tArgs
e)
'''
'''

ObjDtaSce.Selec tParameters["ID"].DefaultValue =Convert.ToStri ng
(integervariabl e);//
thanks.

--
Paul G
Software engineer.

Jul 3 '08 #2
Thanks that worked! I removed the datasourceID that was set in the
properties box and then just set the datasource and executed a databind as
shown below.

(e.Row.Cells[2].FindControl("d ropdown2") as DropDownList).D ataSource =
ObjDtaSce;
(e.Row.Cells[2].FindControl("d ropdown2") as DropDownList).D ataBind();
--
Paul G
Software engineer.
"Eliyahu Goldin" wrote:
You seem to be databinding declaratively with DataSourceID property. In this
case actual select operation takes place in the PreRender event which fires
well after all your RowDataBound events. You need to databind in the
RowDataBound event itself. Simply databind with the DataSource property
instead of DataSourceID and call myDdl.DataBind( ) method.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Paul" <Pa**@discussio ns.microsoft.co mwrote in message
news:BC******** *************** ***********@mic rosoft.com...
I have a gridview and in the RowDataBound I have the line of code below. I
have the ObjDtaSce= to the datasource of a dropdown box. I have 3 rows
that
are populated and for some reason the dropdown box for all rows is
populated
by values expected in the last row only. I checked the ID value and it is
correct for each row. Is there something I would need to reset?

protected void gridview_RowDat aBound(object sender, GridViewRowEven tArgs
e)
'''
'''

ObjDtaSce.Selec tParameters["ID"].DefaultValue =Convert.ToStri ng
(integervariabl e);//
thanks.

--
Paul G
Software engineer.


Jul 3 '08 #3

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

Similar topics

5
10842
by: Kris Rockwell | last post by:
Hello (again), I have gotten the dropdown list functionality to work through a few tricks (probably not the most efficient, but it works) but I am not sure how to set the default selected value. I have tried setting various values to represent the default value with little success. Essentially I am looking to have the first item in the list be the default selected item. I noticed in the properties for a dtat grid you could set a default...
4
29541
by: Dabbler | last post by:
I have two tables I'm editing in a Gridview. The VANS table contains a key to the other LESSOR table. I would like to use a dropdown list to select the LessorId value while displaying the Lessor table's "Company" field as text. When I commit the edit I get error:Must declare the scalar variable "@LessorId". Also as a bonus question ;) I don't know how to set the selectedindex value in the dropdown list based on the LessorId value in the...
3
2114
by: Advertis | last post by:
Is there a way to populate a dropdown in a GridView with the next x years? I am using a GridView to display data from a SQL table One of the fields is a Year. I want to have the dropdown list not only the year in the db field, but also the current year to the next x years. Any ideas?
5
6458
by: sutphinwb | last post by:
Hi - This could be a simple question. When I relate two tables in a datasetet, how do I get that relation to show up in a GridView? The only way I've done it, is to create a separate table in the dataset with a join query for the GetData() select method. I use ObjectDataStore to couple the GridView with the table adapter on the dataset. If I point the ODS at the child table, the GridView will bind to the "normal" select and I end up...
5
11907
by: jung_h_park | last post by:
From: jung_h_park@yahoo.com Newsgroups: microsoft.public.dotnet.framework.aspnet Subject: Dropdown List not retaining its SelectedValue Date: Mon, 26 Jun 2006 21:02:57 -0700 Hello, My dropdown list control does not retain its SelectedValue. Unless I read the SelectedValue right after the control has been loaded, populated, and assigned with its original value (and of course that is
0
2918
by: cindy | last post by:
I have a dynamic datagrid. I have custom classes for the controls public class CreateEditItemTemplateDDL : ITemplate { DataTable dtBind; string strddlName; string strSelectedID; string strDataValueField; string strDataTextField; public CreateEditItemTemplateDDL(string DDLName,string DataValueField,string
1
9689
by: William Youngman | last post by:
I have a gridview displaying data and would like to use the AJAX dropdown extender so that when the user clicks on a record a dropdown menu will display providing the user with a menu of selections to choose from (yes much like the SharePoint 2007 dropdown menu). I'm having problems dynamically binding the 'TargetControlID' property of the extender control to the record label in the gridview. What I'm doing is - The label's text is the...
8
2935
by: Wingot | last post by:
Hey, I have a program I am trying to write using Visual C#, SQL Server 2005/2008, and Visual Studio 2008, and one part of it includes a Schema called Client. Inside this schema, three tables exist named Country, MedicalCondition, and Customer.
3
1721
by: =?Utf-8?B?UGF1bA==?= | last post by:
Hi I have a generic list of data list <typelistcategory; listcategory = new list <type>; I also have a dropdown box that I have put into a template column of a gridview. I was able to populate the dropdown box ok when it was outside of the gridview for (int i = 0; i <= listcategory.Count - 1; i++) { ddl.Items.Add(listcategory.Description);
0
9706
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
10326
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
10317
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
10075
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
9143
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
7615
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
6851
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
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4295
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.