473,386 Members | 1,924 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,386 software developers and data experts.

DropDownLists in DataGrids-- can I dynamically name them?


Hi everyone,

I'd like to put some DropDownLists in my DataGrid, populating each from a
database query. I'm having a little trouble naming them based on the
current record in the DataSet.

For example, here's a snippet of what I have now in my DataGrid

<ItemTemplate>
<asp:DropDownList runat="server" id="lstCategories"
DataValueField="CategoryID"
DataTextField="Name"/>
</ItemTemplate>

I can create the DropDownLists ok, but I'm stuck choosing one id for the
name, and having the DataGrid supply the final name for each. I'd like to
name them myself, giving them ids like "lstCategories0," "lstCategories1,"
"lstCategories2," etc. Is it possible to do that somehow?

And, if I can do it, how can I set their DataSource properties and selected
items in my code-behind file? The goal is to have each DropDown reading
from the same data source, but with their selected item dependent on their
id values.

Thanks very much,

-Jim
Nov 19 '05 #1
3 1186
Jim,
Those are good questions, and we get that kind of stuff a lot around here.
Check out my tutorial on databinding and I think you'll find the answers you
are looking for:
http://openmymind.net/databinding/index.html

As a quick note before you go through it though, you should be naming these
dropdownlist with the same id, that is "lstCategories". In other words, you
probably DON'T want the 0,1,2,3,4. You can get a reference to an individual
one by doing something like
myDataGrid.Items[0].FindControl("lstCategories") which will return the
dropdownlist in the 1st row.

As for binding to them, hook into the grid's ItemDataBound event...the
tutorial goes into great detail on this point, so you should find everything
you need for that there.

Hope this helps,
Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Jim Bancroft" <as******@nowhere.com> wrote in message
news:e%****************@TK2MSFTNGP09.phx.gbl...

Hi everyone,

I'd like to put some DropDownLists in my DataGrid, populating each from a
database query. I'm having a little trouble naming them based on the
current record in the DataSet.

For example, here's a snippet of what I have now in my DataGrid

<ItemTemplate>
<asp:DropDownList runat="server" id="lstCategories"
DataValueField="CategoryID"
DataTextField="Name"/>
</ItemTemplate>

I can create the DropDownLists ok, but I'm stuck choosing one id for the
name, and having the DataGrid supply the final name for each. I'd like to
name them myself, giving them ids like "lstCategories0," "lstCategories1,"
"lstCategories2," etc. Is it possible to do that somehow?

And, if I can do it, how can I set their DataSource properties and selected items in my code-behind file? The goal is to have each DropDown reading
from the same data source, but with their selected item dependent on their
id values.

Thanks very much,

-Jim

Nov 19 '05 #2
Create a view of the table, then you can specify the view (which contains
the identical same information as the table) for the other data set.
However, this skirts the issue without solving it.

"Jim Bancroft" <as******@nowhere.com> wrote in message
news:e%****************@TK2MSFTNGP09.phx.gbl...

Hi everyone,

I'd like to put some DropDownLists in my DataGrid, populating each from a
database query. I'm having a little trouble naming them based on the
current record in the DataSet.

For example, here's a snippet of what I have now in my DataGrid

<ItemTemplate>
<asp:DropDownList runat="server" id="lstCategories"
DataValueField="CategoryID"
DataTextField="Name"/>
</ItemTemplate>

I can create the DropDownLists ok, but I'm stuck choosing one id for the
name, and having the DataGrid supply the final name for each. I'd like to
name them myself, giving them ids like "lstCategories0," "lstCategories1,"
"lstCategories2," etc. Is it possible to do that somehow?

And, if I can do it, how can I set their DataSource properties and selected items in my code-behind file? The goal is to have each DropDown reading
from the same data source, but with their selected item dependent on their
id values.

Thanks very much,

-Jim

Nov 19 '05 #3
Thanks, Karl.

-Jim

"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:eQ**************@TK2MSFTNGP12.phx.gbl...
Jim,
Those are good questions, and we get that kind of stuff a lot around here.
Check out my tutorial on databinding and I think you'll find the answers
you
are looking for:
http://openmymind.net/databinding/index.html

Nov 19 '05 #4

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

Similar topics

10
by: MLH | last post by:
I have a database named credifree. I did it with mysql's create command. Yet, I can find no files on my linux box except for a\ directory and a gif file that have the name credifree. Why? What's...
8
by: Peter | last post by:
Hi everybody, I'm a new in C# and have a problem I need to create dynamically the name of object let's say "obj1", "obj2" etc. They're hashtables (Action Script objects) I'm doing like...
2
by: -BA- | last post by:
Hi! I wonder if it is possible to dynamically name a object (e.g. checkbox, combox etc.) during runtime. I know I can create a object during runtime like this: Me.MyLabel = New Label...
5
by: drdave | last post by:
I would like to have ten arraylists created within a loop.. is there a conversion or something I can do to acheive this.. pseudo: Dim counter As Integer = 0 Dim ArrName As ArrayList ...
8
by: CES | last post by:
All, I'm sorry but I still don't get this!! I'm trying to use a variable that is passed into a function to to dynamically name an instance of an Object(). I've created a Timer() Object that seems...
0
by: itdontgo | last post by:
Hi, I'm trying to make an array with the data read from a file. I'm using get GetFiles to find the files in a directory and then I want to make an array for each file it finds. I tried something...
2
by: itsSase | last post by:
Guys i have a page whose layout is Goverened my a Single CSS file Now, I use 2 different types of layout when needed..I do a check which layout to use , using VB.net Code behind.. The Problem...
1
by: WISEMANOFNARNIA | last post by:
I have code in asp.net that is supposed to create a spreadsheet. It works for some people, but others complain that the spreadsheet has no 'sheet1', and instead they are told it has an 'illegal...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.