473,406 Members | 2,549 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,406 software developers and data experts.

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_RowDataBound(object sender, GridViewRowEventArgs e)
'''
'''

ObjDtaSce.SelectParameters["ID"].DefaultValue =Convert.ToString
(integervariable);//
thanks.

--
Paul G
Software engineer.
Jul 2 '08 #1
2 1248
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**@discussions.microsoft.comwrote in message
news:BC**********************************@microsof t.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_RowDataBound(object sender, GridViewRowEventArgs
e)
'''
'''

ObjDtaSce.SelectParameters["ID"].DefaultValue =Convert.ToString
(integervariable);//
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("dropdown2") as DropDownList).DataSource =
ObjDtaSce;
(e.Row.Cells[2].FindControl("dropdown2") as DropDownList).DataBind();
--
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**@discussions.microsoft.comwrote in message
news:BC**********************************@microsof t.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_RowDataBound(object sender, GridViewRowEventArgs
e)
'''
'''

ObjDtaSce.SelectParameters["ID"].DefaultValue =Convert.ToString
(integervariable);//
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
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....
4
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...
3
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...
5
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...
5
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...
0
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...
1
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...
8
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...
3
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
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
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,...
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...
0
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...
0
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...

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.