Home All Groups Group Topic Archive Search About
Author
12 Dec 2006 12:30 AM
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

Author
12 Dec 2006 8:41 AM
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

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
>
>
>
>
>
>
Author
12 Dec 2006 8:50 AM
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

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
> >
> >
> >
> >
> >
> >