473,493 Members | 2,274 Online
Bytes | Software Development & Data Engineering Community
Create 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:TemplateColumn>
<ItemTemplate>
<asp:DropDownList ID="ddlUserName" Font-Name="Verdana"
Font-Size="8pt" Runat=server
DataValueField="UserName"
DataTextField="UserName"
DataSource='<%# GetUserList() %>'>
</asp:DropDownList>

</ItemTemplate>
</asp:TemplateColumn>
public DataSet GetUserList()
{
SqlConnection objConnection = new
SqlConnection(ConfigurationSettings.AppSettings["strAtradius"]);

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
1 1757
The code that you posted shows that you return an object named dsUsers but it
does not show when the object was instantiated. If the scope of that
variable "dsUsers" is outside the scope of the function GetUsersList then
your table would keep appending records for each row of the datagrid
processed. You should move the steps of populating the table to the
Page_Load if they are not dependent on any value in the datagrid item
otherwise you code has to change to return only a DataTable that is local in
scope to the "GetUsersList" function.
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"Mike P" wrote:
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() %>'>
</asp:DropDownList>

</ItemTemplate>
</asp:TemplateColumn>
public DataSet GetUserList()
{
SqlConnection objConnection = new
SqlConnection(ConfigurationSettings.AppSettings["strAtradius"]);

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 #2

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

Similar topics

2
2562
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...
0
2006
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...
13
2850
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...
1
1529
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...
1
1952
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...
5
2263
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...
2
1900
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"...
2
2833
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...
0
1671
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...
0
7119
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,...
0
7157
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,...
1
6873
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...
0
7367
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...
0
5453
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,...
0
4579
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...
0
3088
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1400
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 ...
1
644
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.