473,695 Members | 2,327 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

populating dropdown in datagrid

I am populating a drop down column in a datagrid on page load. Here is
my code :

<asp:TemplateCo lumn>
<ItemTemplate >
<asp:DropDownLi st ID="ddlUserName " Font-Name="Verdana"
Font-Size="8pt" Runat=server
DataValueField= "UserName"
DataTextField=" UserName"
DataSource='<%# GetUserList() %>'>
</asp:DropDownLis t>

</ItemTemplate>
</asp:TemplateCol umn>
public DataSet GetUserList()
{
SqlConnection objConnection = new
SqlConnection(C onfigurationSet tings.AppSettin gs["strAtradiu s"]);

string strUserList = "select username from userlogin where jobrolekey
= 2 ";
strUserList += "order by username";

SqlDataAdapter objDataAdapter = new SqlDataAdapter( strUserList,
objConnection);

objDataAdapter. Fill(dsUsers, "Users");

return dsUsers;
}

dsUsers is global to the page. The problem I have is that the first row
of the datagrid populates correctly, but the following lines append the
contents of the dropdown in the row above. How do I clear the contents
of the dropdown before populating each row?

Any help would be really appreciated.

Cheers,

Mike



*** Sent via Developersdex http://www.developersdex.com ***
Dec 1 '05 #1
2 1914
Hi,

I guess is cause you are adding rows to the Datatable, what if you clear
the table?

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Mike P" <mi*******@gmai l.com> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
I am populating a drop down column in a datagrid on page load. Here is
my code :

<asp:TemplateCo lumn>
<ItemTemplate >
<asp:DropDownLi st ID="ddlUserName " Font-Name="Verdana"
Font-Size="8pt" Runat=server
DataValueField= "UserName"
DataTextField=" UserName"
DataSource='<%# GetUserList() %>'>
</asp:DropDownLis t>

</ItemTemplate>
</asp:TemplateCol umn>
public DataSet GetUserList()
{
SqlConnection objConnection = new
SqlConnection(C onfigurationSet tings.AppSettin gs["strAtradiu s"]);

string strUserList = "select username from userlogin where jobrolekey
= 2 ";
strUserList += "order by username";

SqlDataAdapter objDataAdapter = new SqlDataAdapter( strUserList,
objConnection);

objDataAdapter. Fill(dsUsers, "Users");

return dsUsers;
}

dsUsers is global to the page. The problem I have is that the first row
of the datagrid populates correctly, but the following lines append the
contents of the dropdown in the row above. How do I clear the contents
of the dropdown before populating each row?

Any help would be really appreciated.

Cheers,

Mike



*** Sent via Developersdex http://www.developersdex.com ***

Dec 5 '05 #2
you want to make the call to GetUserList() in Page_Load, then set the
DataSource of the ddlUserName like DataSource='<%# dsUsers %>'> b/c u
don't want to make a call to the db every iteration of the datagrid
items. This will also fix your issue of adding the new rows to the
table.

Dec 5 '05 #3

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

Similar topics

2
2585
by: Lamine Darbouche | last post by:
Can anybody help? I need to have three list boxes automatically populating each other, (ie when region is selected from the first listbox, it will populate automatically the second one which is the TOWNS and when the town is selected is should populate the third one AREA) all data is in the database in one table. Any idea??? Many thanks in adavance. Lamine
0
2026
by: Kilic Beg via .NET 247 | last post by:
Hi, I am having trouble adding a dropdown to DataGrid at runtime. I create all boundColumns and the TemplateColumn for the dropdown at runtime. The dropdown has a different datasource then the DataGrid. 1. If I try to bind the second datasource to the dropdown I get An unhandled exception of type 'System.StackOverflowException' occurred in mscorlib.dll. 2. If I comment that line out it displays always the dropdown. I want it to...
13
2866
by: melih.onvural | last post by:
Group, I'm having a tough time understanding some of the previous posts on this topic so I wanted to write what I've tried and hope that you can help me troubleshoot. I have a dropdown populated from a table and I want to take that selection and use it to populate the next dropdown. So far: 1) I tried using a query that said select specificissue from specific_issue and used as my criterion !!
1
1539
by: Tim::.. | last post by:
Can someone please tell me why this doesn't work! I have a datagrid with a dropdown menu in the footer but for some reason the dropdown just doesn't populate with data! I'm not really sure what I'm doing wrong! Do I need to run the sub from page_load??? If so how??? Thanks for any advice!
1
1963
by: Vijay Kerji | last post by:
Hi, I have a datagrid with dropdown list and Remove hyperlink in it as columns. When I remove a row from the datagrid, Dropdown list selection is retaining its previous value. i.e, removed Dropdown item selection is applied to the next dropdown list. Is there any way to fix this problem?
6
5395
by: Jenna Alten | last post by:
I have a datagrid with a template column that contains a dropdown list. I currently fill and display the dropdown list on the page load. This is working correctly. I am NOT using an Edit Column. I am receiving errors when trying to set the selected value of the dropdown within the ItemDataBound() subroutine. Below is the code I am using. I hope someone can tell me if this is possible. '''HTML''' <asp:datagrid id="dgAssignments"...
5
2281
by: | last post by:
Trying to learn about manipulating collections of objects, and populating these objects dynamically from datasources. Could someone post a code sample that shows the following: Instantiating a collection object -- say, a dictionary. Populating that collection object with custom objects, say, Person. What I really want to see is how to populate the properties of those Person objects from a datasource: instantiate one Person, fill...
1
1772
by: Mike P | last post by:
I am populating a drop down column in a datagrid on page load. Here is my code : <asp:TemplateColumn> <ItemTemplate> <asp:DropDownList ID="ddlUserName" Font-Name="Verdana" Font-Size="8pt" Runat=server DataValueField="UserName" DataTextField="UserName" DataSource='<%# GetUserList() %>'>
2
2847
by: Peter | last post by:
ASP.NET 2003 In the DataGrid how do I select current cell value in the dropdown box when I click on the edit link, currently when I click on the edit link in the DataGrid the dropdown box appears in the cell, but allways the first item in the dropdown box is shown not the current cell value? How do I make the current value in the cell automaticaly be selected in the dropdown box.
0
1694
by: koonda | last post by:
Hi all, I have a Project due after one week. It is a web service project. I have a Web Form which communicates to the web service and this web service communicates to the database. I have all my SQL statements in the Data Acess Layer to create more secure web service application. The Web service class is also in the Data Access Layer. I need to populates the 4 Dropdown list boxes on the web form from one table. I have Customer table which...
0
8638
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8998
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8857
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
8831
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7668
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6494
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4586
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3013
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2278
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.