471,355 Members | 1,641 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,355 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 1796
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Kilic Beg via .NET 247 | last post: by
1 post views Thread by Tim::.. | last post: by
1 post views Thread by Vijay Kerji | last post: by
1 post views Thread by Mike P | last post: by
2 posts views Thread by Peter | last post: by

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.