473,386 Members | 1,752 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.

DropDownList in Datagrid

Sid
Hi All,

I am trying to populate a dropdown list in my Datagrid
control using the OleDbDataReader, but when my function
tries to add items to the dropdownlist it says that my
dropdownlist control has not been 'declared' even though
it is set to runat="server" .

Any ideas?
Nov 17 '05 #1
2 1633
I think you should use data binding to add items to dropdownlist

<asp:DropDownList id=level_DropDownList runat="server" Width="90px"
DataSource="<%# your_function() %>" ></asp:DropDownList>

dropdownlist will bind to the function return value, the function can
return a dataset, array, etc.

Or you can use DataGrid.FindControl("Dropdownlist") to get the instance
of the dropdownlist.
Sid wrote:
Hi All,

I am trying to populate a dropdown list in my Datagrid
control using the OleDbDataReader, but when my function
tries to add items to the dropdownlist it says that my
dropdownlist control has not been 'declared' even though
it is set to runat="server" .

Any ideas?


--
bill
e-mail: bi*****@hotmail.com
MSN Messenger: bi*****@hotmail.com
Web: http://www.minivoice.com

Nov 17 '05 #2
Sid,
when you add controls to a datagrid you can't access them
programmatically by referring to their IDs directly.
At run time you can access the control by first
retrieving it from the datagrid cell.
A good time to do this is within the item_databound or
the item_created events of the datagrid; see the
following code example:

[C#]
private void onItemCreated(object
sender,System.Web.UI.WebControls.DataGridItemEvent Args e)
{
DropDownList c =
(DropDownList)e.Item.Cell[0].Controls[0];
c.DataSource = yourdatareader;
//etc
}

regards,
alex
-----Original Message-----
Hi All,

I am trying to populate a dropdown list in my Datagrid
control using the OleDbDataReader, but when my function
tries to add items to the dropdownlist it says that my
dropdownlist control has not been 'declared' even though
it is set to runat="server" .

Any ideas?
.

Nov 17 '05 #3

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

Similar topics

12
by: Stanley J Mroczek | last post by:
How do you load a dropdownlist when edit is clicked in a datagrid ? <Columns> <asp:BoundColumn DataField="OptionDescription" ItemStyle-Wrap="True" HeaderText="Option...
2
by: rmorvay | last post by:
I am trying to dynamically build a dropdownlist and bind it to a cell in a grid. I tried to utilize the following code but I am stuck at the point where I bind the dropdownlist to the grid cell. ...
2
by: Dominic | last post by:
Hi guys, I'm not sure if this question belongs to FAQ, but I couldn't find a concrete answer. I created a Datagrid control using ItemTemplate, but it's NOT a in-place editing datagrid. One of...
0
by: Shane O. Pinnell | last post by:
I am sure this has come up before, but I haven't been able to find an answer as of yet. That said, any help is definitely appreciated! I have a datagrid populated from a dataset. I have a...
2
by: Shiju Poyilil | last post by:
Hello, I have a datagrid with only one row and its having 2 dropdownlists, I need to populate the secodn dropdownlist on the basis of the selection in the first dropdown. but I am not able to...
1
by: m3ckon | last post by:
Hi there, please help if you can, I'm having an issue with droponnlists in a datagrid I have a datagrid which is populated from a query .. all works fine I've added two extra columns, one...
3
by: Tim::.. | last post by:
Can someone please tell me how I go about preselecting an item in a drop drown list when I click the Edit Command in a datagrid? I have tried the following but it doesn't work for me! I would...
0
by: Daniel Doyle | last post by:
Hello and apologies in advance for the amount of code in this post. I've also sent this message to the Sharepoint group, but thought that ASP.NET developers may also be able to help, even though...
4
by: Mark Waser | last post by:
I've discovered a very odd bug when attempting to put a dropdown list in a datagrid. In the page PreRender step, the selected index of the datagrid is successfully set during databinding. Yet,...
15
by: glenn | last post by:
Hi folks, I have a DropDownList in a DataGrid that is populated from records in a database. I want to add a value that might be a string such as "Select a Company" for the first item since an...
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
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
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...

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.