|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Drop Down List issuedrop 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 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 Show quoteHide quote "KT" wrote: > 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 > > > > > > 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 Show quoteHide quote "Manish Bafna" wrote: > 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 > > "KT" wrote: > > > 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 > > > > > > > > > > > >
ERROR: The state information is invalid for this page and might be corrupted
Problem accessing controls ReportViewer Causing Major Problems Properties do not reliably persist using CompositeControl file upload and download Formfields in Repeaters - validation and save into DB themes Images SiteMap resolve question Any way to set attributes for server controls by referencing properties/methods/variables? Parameter as web user control |
|||||||||||||||||||||||