dropdownlist databind problems

  • Thread starter Thread starter Srinivas
  • Start date Start date
S

Srinivas

Hi,

My function returns a datareader object containing only one column of
datatype money. In asp.net I want to bind this datareader to a dropdownlist.
Can anyone suggest me how to do this with some sample code if possible.

Thanks

Srinivas
 
I found it best to load them in functions such as below.

public static void Loadlist(DropDownList thisDropDownList , SqlDataReader
dr)
{
thisDropDownList.Items.Clear();
ListItem li;
while(dr.Read())
{
li = new ListItem(dr[1].ToString().Trim(),dr[0].ToString().Trim());
thisDropDownList.Items.Add(li);
}
dr.Close();
}
 
You can assign your reader to the DropDownList control's "DataSource"
property and call the DataBind() method. You must also set the
DropDownList's "DataTextField" property to the column that you want to bind
to the control.
Here are some code pieces:

reader = command.ExecuteReader();
ddList.DataSource = reader;
ddList.DataTextField = "money";
ddList.DataBind();

<asp:DropDownList ID="ddList" Runat="Server">

Hope this helps,
Martha
 
Thanks

I have tried the code. Its working fine. But the amounts are displayed as
100.000 as the datatype of the column from which the data is retrieved is
money. Is there any way to display the value 100.000 as 100

Srinivas
 
Back
Top