Drop Down List issue

K

KT

I have this code below on my aspx page but it doesn't load this into the
drop down list at runtime. The dropdown list poplulated from a SQL stored
procedure...but adding a value to the list like below should work.



<asp:DropDownList ID="ddlHospitals" AutoPostBack="true" runat="server">

<asp:ListItem Text="Select a Hospital" Value="-1" Enabled="true"
Selected="True"></asp:ListItem>

</asp:DropDownList>





Thanks in advance.



KT
 
M

Manish Bafna

Hi,
It looks you want to add static default value as first item in dropdownlist
apart from dynamic values generated from stored proc.
How about this code:

If(! Page.IsPostBack)
{
// first the data binding code.
HospitalDrpDownList.DataSource = ds(a dataset variable)
HospitalDrpDownList.DataTextField = "Hospital"
HospitalDrpDownList.DataValueField = "HospitalCode"
HospitalDrpDownList.DataBind()


//Thereafter Add following items and select the first item by default.
HospitalDrpDownList.Items.Insert(-1, "Select a Hospital")
HospitalDrpDownList.SelectedIndex=0
}

Thanks and Regards,
Manish bafna
 
M

Manish Bafna

Hi,
also your code for inserting default value is not working because data
binding code of stored procedure will overwrite this default value.That is
why in my previous code i have first written the code for data binding and
then code for inserting default values.

Thanks and regards,
mansih bafna
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top