473,320 Members | 2,146 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.

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
2 1895
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*******@gmail.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
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 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
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
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
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
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
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...
6
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...
5
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...
1
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
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
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
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: 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: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
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
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.