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

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 8903
"MikeB" <m@nospam.comwrote in message
news:%2****************@TK2MSFTNGP04.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**@markNOSPAMrae.comwrote in message
news:O9**************@TK2MSFTNGP04.phx.gbl...
"MikeB" <m@nospam.comwrote in message
news:%2****************@TK2MSFTNGP04.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_RowDataBound(object sender, GridViewRowEventArgs e)

{

if (e.Row.RowType == DataControlRowType.DataRow)

{

ObjectDataSource ds =
(ObjectDataSource)e.Row.FindControl("ObjectDataSou rce2");

ds.SelectParameters["categoryID"].DefaultValue =
GridView1.DataKeys[e.Row.DataItemIndex].Value.ToString();

}

}

"MikeB" <m@nospam.comwrote in message
news:%2****************@TK2MSFTNGP04.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.comwrote in message
news:eh**************@TK2MSFTNGP05.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_RowDataBound(object sender, GridViewRowEventArgs
e)

{

if (e.Row.RowType == DataControlRowType.DataRow)

{

ObjectDataSource ds =
(ObjectDataSource)e.Row.FindControl("ObjectDataSou rce2");

ds.SelectParameters["categoryID"].DefaultValue =
GridView1.DataKeys[e.Row.DataItemIndex].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**@markNOSPAMrae.comwrote in message
news:u7**************@TK2MSFTNGP06.phx.gbl...
"MikeB" <m@nospam.comwrote in message
news:eh**************@TK2MSFTNGP05.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_RowDataBound(object sender, GridViewRowEventArgs
e)

{

if (e.Row.RowType == DataControlRowType.DataRow)

{

ObjectDataSource ds =
(ObjectDataSource)e.Row.FindControl("ObjectDataSo urce2");

ds.SelectParameters["categoryID"].DefaultValue =
GridView1.DataKeys[e.Row.DataItemIndex].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.SelectParameters["categoryID"].DefaultValue =
GridView1.DataKeys[e.Row.DataItemIndex].Value.ToString();

Should be:

ds.SelectParameters["categoryID"].DefaultValue =
GridView1.DataKeys[e.Row.RowIndex].Value.ToString();

I received an error when I had paging enabled, the e.Row.DataItemIndex 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
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....
0
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...
4
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...
4
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...
0
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,...
2
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...
7
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,...
1
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...
1
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.