Home All Groups Group Topic Archive Search About
Author
2 Jun 2006 1:06 PM
Julia
Hi
I am developing a CompoisiteControl. I have problems with adding a row in my
DropDownList with the text "Select". The first time the side is opened the
"Select" row is not there. When I do a postback the row appears.

What do I do wrong?

Thanks
J

Below is some code:

protected override void CreateChildControls()
{
            lblAttrAdditional.Text = "Add an attribute";
            drAttrAdditional = new DropDownList();
            drAttrAdditional.AutoPostBack = true;
            drAttrAdditional.SelectedIndexChanged += new
EventHandler(drAttrAdditional_SelectedIndexChanged);
            this.Controls.Add(drAttrAdditional);
            //DataBind
            if (!Page.IsPostBack)
            {
                BindDropDownLists();
            }
}
private void BindDropDownLists()
{
            dsProducts.Tables["AttributeHeader"].DefaultView.RowFilter =
"Default = '0'";
            drAttrAdditional.DataSource =
dsProducts.Tables["AttributeHeader"].DefaultView;
            drAttrAdditional.DataValueField = "AttrId";
            drAttrAdditional.DataTextField = "Name";
            drAttrAdditional.DataBind();
            drAttrAdditional.Items.Insert(0, new ListItem("Select", "0"));
}

Author
2 Jun 2006 1:30 PM
Riki
Try adding the ddl to the controls collection AFTER running the
BindDropDownLists() method.
I seem to remember a similar problem that was solved in that way.

--

Riki

Show quoteHide quote
"Julia" <Ju***@discussions.microsoft.com> wrote in message
news:11277CE7-F9DC-4308-AAC7-FB61E1DB1382@microsoft.com...
> Hi
> I am developing a CompoisiteControl. I have problems with adding a row in
> my
> DropDownList with the text "Select". The first time the side is opened the
> "Select" row is not there. When I do a postback the row appears.
>
> What do I do wrong?
>
> Thanks
> J
>
> Below is some code:
>
> protected override void CreateChildControls()
> {
>            lblAttrAdditional.Text = "Add an attribute";
>            drAttrAdditional = new DropDownList();
>            drAttrAdditional.AutoPostBack = true;
>            drAttrAdditional.SelectedIndexChanged += new
> EventHandler(drAttrAdditional_SelectedIndexChanged);
>            this.Controls.Add(drAttrAdditional);
>            //DataBind
>            if (!Page.IsPostBack)
>            {
>                BindDropDownLists();
>            }
> }
> private void BindDropDownLists()
> {
>            dsProducts.Tables["AttributeHeader"].DefaultView.RowFilter =
> "Default = '0'";
>            drAttrAdditional.DataSource =
> dsProducts.Tables["AttributeHeader"].DefaultView;
>            drAttrAdditional.DataValueField = "AttrId";
>            drAttrAdditional.DataTextField = "Name";
>            drAttrAdditional.DataBind();
>            drAttrAdditional.Items.Insert(0, new ListItem("Select", "0"));
> }
Author
2 Jun 2006 1:58 PM
CGW
Perhaps it's cheating, but we often add the line in the stored procedure we
use to populate the control. For example...

CREATE PROCEDURE [dbo].[sp_PopulateDropDown]

AS



SELECT
     0                           As IdentityID
    ,'--- Add New Line ---'      As LineSpec


UNION

SELECT
     IdentityID
    ,ItemName                    As LineSpec
FROM
    Items
ORDER BY
    ItemName Asc

--
Thanks,

CGW


Show quoteHide quote
"Julia" wrote:

> Hi
> I am developing a CompoisiteControl. I have problems with adding a row in my
> DropDownList with the text "Select". The first time the side is opened the
> "Select" row is not there. When I do a postback the row appears.
>
> What do I do wrong?
>
> Thanks
> J
>
> Below is some code:
>
> protected override void CreateChildControls()
> {
>             lblAttrAdditional.Text = "Add an attribute";
>             drAttrAdditional = new DropDownList();
>             drAttrAdditional.AutoPostBack = true;
>             drAttrAdditional.SelectedIndexChanged += new
> EventHandler(drAttrAdditional_SelectedIndexChanged);
>             this.Controls.Add(drAttrAdditional);
>             //DataBind
>             if (!Page.IsPostBack)
>             {
>                 BindDropDownLists();
>             }
> }
>  private void BindDropDownLists()
> {
>             dsProducts.Tables["AttributeHeader"].DefaultView.RowFilter =
> "Default = '0'";
>             drAttrAdditional.DataSource =
> dsProducts.Tables["AttributeHeader"].DefaultView;
>             drAttrAdditional.DataValueField = "AttrId";
>             drAttrAdditional.DataTextField = "Name";
>             drAttrAdditional.DataBind();
>             drAttrAdditional.Items.Insert(0, new ListItem("Select", "0"));
> }
Author
2 Jun 2006 1:59 PM
CGW
Oops... the Order By should have been LineSpec
--
Thanks,

CGW


Show quoteHide quote
"CGW" wrote:

> Perhaps it's cheating, but we often add the line in the stored procedure we
> use to populate the control. For example...
>
> CREATE PROCEDURE [dbo].[sp_PopulateDropDown]
>
> AS
>
>
>
> SELECT
>      0                           As IdentityID
>     ,'--- Add New Line ---'      As LineSpec
>
>
> UNION
>
> SELECT
>      IdentityID
>     ,ItemName                    As LineSpec
> FROM
>     Items
> ORDER BY
>     ItemName Asc
>
> --
> Thanks,
>
> CGW
>
>
> "Julia" wrote:
>
> > Hi
> > I am developing a CompoisiteControl. I have problems with adding a row in my
> > DropDownList with the text "Select". The first time the side is opened the
> > "Select" row is not there. When I do a postback the row appears.
> >
> > What do I do wrong?
> >
> > Thanks
> > J
> >
> > Below is some code:
> >
> > protected override void CreateChildControls()
> > {
> >             lblAttrAdditional.Text = "Add an attribute";
> >             drAttrAdditional = new DropDownList();
> >             drAttrAdditional.AutoPostBack = true;
> >             drAttrAdditional.SelectedIndexChanged += new
> > EventHandler(drAttrAdditional_SelectedIndexChanged);
> >             this.Controls.Add(drAttrAdditional);
> >             //DataBind
> >             if (!Page.IsPostBack)
> >             {
> >                 BindDropDownLists();
> >             }
> > }
> >  private void BindDropDownLists()
> > {
> >             dsProducts.Tables["AttributeHeader"].DefaultView.RowFilter =
> > "Default = '0'";
> >             drAttrAdditional.DataSource =
> > dsProducts.Tables["AttributeHeader"].DefaultView;
> >             drAttrAdditional.DataValueField = "AttrId";
> >             drAttrAdditional.DataTextField = "Name";
> >             drAttrAdditional.DataBind();
> >             drAttrAdditional.Items.Insert(0, new ListItem("Select", "0"));
> > }