473,563 Members | 2,732 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Dynamic Listbox in Gridview

Hello All,

I know this has to be something simple but I have having a hard time finding
examples. I need to add a dynamic listbox to a gridview.

For example, my grid view displays categories and then in each row/ category
I have a list box that displays items in the category.

Can anyone give any pointers or examples?
Mar 24 '07 #1
6 8924
"MikeB" <m@nospam.comwr ote in message
news:%2******** ********@TK2MSF TNGP04.phx.gbl. ..
Can anyone give any pointers or examples?
Google is your friend:
http://www.google.co.uk/search?sourc...idView+ListBox
Mar 24 '07 #2
Thank you, I have been searching on the wrong terms.

"Mark Rae" <ma**@markNOSPA Mrae.comwrote in message
news:O9******** ******@TK2MSFTN GP04.phx.gbl...
"MikeB" <m@nospam.comwr ote in message
news:%2******** ********@TK2MSF TNGP04.phx.gbl. ..
>Can anyone give any pointers or examples?

Google is your friend:
http://www.google.co.uk/search?sourc...idView+ListBox

Mar 24 '07 #3
New question, my dropdown list will not load with the data. I am setting
the object datasouce with the below code howver, it isn't working (I debuged
though it and it is being called correctly).

protected void GridView1_RowDa taBound(object sender, GridViewRowEven tArgs e)

{

if (e.Row.RowType == DataControlRowT ype.DataRow)

{

ObjectDataSourc e ds =
(ObjectDataSour ce)e.Row.FindCo ntrol("ObjectDa taSource2");

ds.SelectParame ters["categoryID "].DefaultValue =
GridView1.DataK eys[e.Row.DataItemI ndex].Value.ToString ();

}

}

"MikeB" <m@nospam.comwr ote in message
news:%2******** ********@TK2MSF TNGP04.phx.gbl. ..
Hello All,

I know this has to be something simple but I have having a hard time
finding examples. I need to add a dynamic listbox to a gridview.

For example, my grid view displays categories and then in each row/
category I have a list box that displays items in the category.

Can anyone give any pointers or examples?

Mar 24 '07 #4
"MikeB" <m@nospam.comwr ote in message
news:eh******** ******@TK2MSFTN GP05.phx.gbl...
New question, my dropdown list will not load with the data. I am setting
the object datasouce with the below code howver, it isn't working (I
debuged though it and it is being called correctly).

protected void GridView1_RowDa taBound(object sender, GridViewRowEven tArgs
e)

{

if (e.Row.RowType == DataControlRowT ype.DataRow)

{

ObjectDataSourc e ds =
(ObjectDataSour ce)e.Row.FindCo ntrol("ObjectDa taSource2");

ds.SelectParame ters["categoryID "].DefaultValue =
GridView1.DataK eys[e.Row.DataItemI ndex].Value.ToString ();
It doesn't appear as if you're actually binding the datasource to the
DropDownList...

Something like:

DropDownList ddl = e.Row.Cells[...].FindControl(". ..");
ddl.DataSource = ds;
ddl.DataBind();

You'll also need to specify which field in your datasource is the value and
which the text of each of the ListItems in your DropDownList...
Mar 24 '07 #5
I am having one of those days. Thank you again.

"Mark Rae" <ma**@markNOSPA Mrae.comwrote in message
news:u7******** ******@TK2MSFTN GP06.phx.gbl...
"MikeB" <m@nospam.comwr ote in message
news:eh******** ******@TK2MSFTN GP05.phx.gbl...
>New question, my dropdown list will not load with the data. I am
setting the object datasouce with the below code howver, it isn't working
(I debuged though it and it is being called correctly).

protected void GridView1_RowDa taBound(object sender, GridViewRowEven tArgs
e)

{

if (e.Row.RowType == DataControlRowT ype.DataRow)

{

ObjectDataSour ce ds =
(ObjectDataSou rce)e.Row.FindC ontrol("ObjectD ataSource2");

ds.SelectParam eters["categoryID "].DefaultValue =
GridView1.Data Keys[e.Row.DataItemI ndex].Value.ToString ();

It doesn't appear as if you're actually binding the datasource to the
DropDownList...

Something like:

DropDownList ddl = e.Row.Cells[...].FindControl(". ..");
ddl.DataSource = ds;
ddl.DataBind();

You'll also need to specify which field in your datasource is the value
and which the text of each of the ListItems in your DropDownList...

Mar 24 '07 #6
One error I found in the code sample was:

ds.SelectParame ters["categoryID "].DefaultValue =
GridView1.DataK eys[e.Row.DataItemI ndex].Value.ToString ();

Should be:

ds.SelectParame ters["categoryID "].DefaultValue =
GridView1.DataK eys[e.Row.RowIndex].Value.ToString ();

I received an error when I had paging enabled, the e.Row.DataItemI ndex would be an invalid number (#11 in a 10 row GridView). e.Row.RowIndex on the other hand gives you the current row #.

EggHeadCafe.com - .NET Developer Portal of Choice
http://www.eggheadcafe.com
Mar 30 '07 #7

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

Similar topics

3
13730
by: NateDawg | last post by:
I'm reposting this. I'm kinda in a bind untill i get this figured out, so if anyone has some input it would sure help me out. Ok, I’ve noticed a few gridview problems floating around the forum. Everyone wants to do a java confirmation box when a user clicks the delete button. Fair enough, basic user design rules state that you should...
0
1466
by: SimonZ | last post by:
If I have gridView and one of the columns is template cpolumn, where I have listBox in edit mode: <asp:TemplateField> <HeaderTemplate>CategorName:</HeaderTemplate> <ItemTemplate> <asp:Label runat="server" text='<%# Eval("CategoryName")%>'></asp:Label> </ItemTemplate> <EditItemTemplate>
4
4843
by: Marcos Beccar Varela | GamaCom Argentina | last post by:
Hello Everyone. I need to use a gridview, that when I use the Update command one of the colums, instead of showing a textbox where the user can write, I need a combobox (listobx), where there are 3 options. EG OF GRIDVIEW: USUER AGE carlosg old rominat young gonzalor normal florenciat ...
4
8316
by: Ken Wigle | last post by:
All, I would be very grateful for any help on this question. I have an application in asp.net 2.0 where I dynamically create a datatable and then bind that to a gridview. Unfortunately, the date column always shows the date and time while I just want the short date. I have tried applying a format string {0:d} but to no avail. I saw a...
0
3008
by: awmb | last post by:
Language C#, Version ASP.Net 2.0 Hi I have a GridView which is bound to a table which contains Restaurant information. In the Edit Row there is a Listbox (ListBox1) in the Food Type column, bound to a table containing the food types. <EditItemTemplate> <asp:ListBox ID="ListBox1" runat="server" AppendDataBoundItems="True"...
2
12001
by: j.m.osterman | last post by:
I haven't found exactly what I've been trying to do. All I am trying to do for now is just display usernames from Active Directory into a ListBox control on a page. I have found some code however that will just capture a Full Name from Text Box and display information from the Active Directory into a DataTable. I will display that code...
7
2319
by: =?Utf-8?B?SmVmZiBCZWVt?= | last post by:
The default paging behavior of the gridview doesn't work well with very large sets of data which means we have to implement some sort of custom paging. The examples I have seen (4guysfromrolla, etc.) suggest using an ObjectDataSource which has built-in paging functionality that, when used in conjunction with certain SQL 2005 functionality,...
1
1353
by: =?Utf-8?B?U21pdGE=?= | last post by:
I have a gridview, and a listbox which has a different datasource. The listbox contains distinct types of contacts, whereas the gridview will get populated upon contact type selection. The data is displayed but when on submission of the contact type from the list box i get a null reference exception. I already tried to trap using...
1
2612
by: =?Utf-8?B?cGVsZWdrMQ==?= | last post by:
i have a GridView which i can Page on (go to page 2,10,...) the thing is that i have a dynamic query which set the GridView from starts on page 1. the thing is that when i start to go over the pages - the dynamic query isnt saved and i cant go to the real page 4 for example of the dynamic query,rather i go to page 4 of the original...
0
7664
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...
0
7583
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...
0
7885
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7638
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...
0
7948
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...
1
5484
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...
0
5213
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...
1
1198
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
923
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...

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.