DropDownList problem

Discussion in 'ASP .Net Web Controls' started by Julia, May 31, 2006.

  1. Julia

    Julia Guest

    Hi
    I am trying to develop a composite control (i am new in this area). This
    control will be compiled into a dll and used by a web page. The control are
    containing a DataGrid and some DropDownLists that are populated from a
    dataset.

    When I pick a value in a a DropDown I want to apply some RowFilter to my
    DataGrid. The problem is that the entire control is rewritten
    (CreateChildControls is called) so the value that I picket in the DropDown
    are gone. How can I solve this?

    I send you the code here aswell:

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Text;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Data;
    using System.Collections;

    namespace ABBPISControls
    {
    [DefaultProperty("Text")]
    [ToolboxData("<{0}:productDetails runat=server></{0}:productDetails>")]
    public class ProductDetails : CompositeControl
    {
    private DataSet dsProducts = null;

    private DropDownList[] drAttrDefault = null;
    private Label[] lblAttrHeaders = null;
    private DataView[] dvAttrDefault = null;
    private DropDownList drAttrAdditional = new DropDownList();
    private DataGrid dgProductList = new DataGrid();
    private int iDefaultAttr = 0;

    private Button btnTest = new Button();


    protected override void CreateChildControls()
    {
    //Gets a dataset from a web service with product information
    LoadProducts();

    #region dgProductList
    dgProductList.AutoGenerateColumns = false;

    HyperLinkColumn cName = new HyperLinkColumn();
    cName.HeaderText = "TypeCID;
    cName.DataNavigateUrlField = "Url";
    cName.DataTextField = "ProductId";

    BoundColumn bcColumn1 = new BoundColumn();
    bcColumn1.HeaderText = "AbbType";
    bcColumn1.DataField = "AbbType";

    BoundColumn bcColumn2 = new BoundColumn();
    bcColumn2.HeaderText = "ClassCID";
    bcColumn2.DataField = "ClassCID";

    BoundColumn bcColumn3 = new BoundColumn();
    bcColumn3.HeaderText = "Title";
    bcColumn3.DataField = "Title";

    BoundColumn bcColumn4 = new BoundColumn();
    bcColumn4.HeaderText = "TypeCID";
    bcColumn4.DataField = "TypeCID";

    BoundColumn bcColumn5 = new BoundColumn();
    bcColumn5.HeaderText = "UOM";
    bcColumn5.DataField = "UOM";

    dgProductList.Columns.Add(cName);
    dgProductList.Columns.Add(bcColumn1);
    dgProductList.Columns.Add(bcColumn2);
    dgProductList.Columns.Add(bcColumn3);
    dgProductList.Columns.Add(bcColumn4);
    dgProductList.Columns.Add(bcColumn5);

    dgProductList.DataSource = dsProducts.Tables[0];
    dgProductList.DataBind();

    this.Controls.Add(dgProductList);
    #endregion

    #region drAttrDefault & lblAttrHeaders
    iDefaultAttr = dsProducts.Tables["AttributeHeader"].Rows.Count;
    drAttrDefault = new DropDownList[iDefaultAttr];
    lblAttrHeaders = new Label[iDefaultAttr];
    dvAttrDefault = new DataView[iDefaultAttr];
    int i = 0;
    ArrayList alAttrHeaders = new ArrayList();
    foreach (DataRow drAttr in
    dsProducts.Tables["AttributeHeader"].Rows)
    {
    if (drAttr["Default"].ToString() == "1")
    {
    //Create the new DataView and RowFilter
    dvAttrDefault = new
    DataView(dsProducts.Tables["AttributeValue"]);
    dvAttrDefault.RowFilter = "AttrId = '" +
    drAttr["AttrId"].ToString() + "'";

    //Cretate the Label for the header
    lblAttrHeaders = new Label();
    lblAttrHeaders.Text = drAttr["Name"].ToString();

    //Create the DropDown and bind it to the datasourece
    drAttrDefault = new DropDownList();
    drAttrDefault.AutoPostBack = true;
    drAttrDefault.DataSource = dvAttrDefault;
    drAttrDefault.DataValueField = "AttrId";
    drAttrDefault.DataTextField = "Count";
    drAttrDefault.DataBind();

    drAttrDefault.SelectedIndexChanged += new
    EventHandler(ProductDetails_SelectedIndexChanged);

    //Add controls to page
    this.Controls.Add(lblAttrHeaders);
    this.Controls.Add(drAttrDefault);
    i++;
    alAttrHeaders.Add(drAttr["AttrId"]);
    }
    }
    iDefaultAttr = i;
    #endregion

    #region drAttrAdditional
    drAttrAdditional.AutoPostBack = true;
    dsProducts.Tables["AttributeHeader"].DefaultView.RowFilter =
    "Default = '0'";
    drAttrAdditional.DataSource =
    dsProducts.Tables["AttributeHeader"].DefaultView;
    drAttrAdditional.DataValueField = "AttrId";
    drAttrAdditional.DataTextField = "Name";
    drAttrAdditional.DataBind();
    drAttrAdditional.SelectedIndexChanged += new
    EventHandler(myDropDown_SelectedIndexChanged);
    this.Controls.Add(drAttrAdditional);
    #endregion

    btnTest.Text = "Test";
    btnTest.Click += new EventHandler(btnTest_Click);
    this.Controls.Add(btnTest);

    //base.CreateChildControls();

    }
    protected override void RenderContents(HtmlTextWriter output)
    {
    dgProductList.RenderControl(output);
    for (int i = 0; i < iDefaultAttr; i++)
    {
    lblAttrHeaders.RenderControl(output);
    output.Write("<br>");
    drAttrDefault.RenderControl(output);
    output.Write("<br>");
    }
    drAttrAdditional.RenderControl(output);

    btnTest.RenderControl(output);
    }
    #region Events
    void myDropDown_SelectedIndexChanged(object sender, EventArgs e)
    {
    Console.WriteLine("test");
    }
    void btnTest_Click(object sender, EventArgs e)
    {
    Console.WriteLine("test");
    }

    void ProductDetails_SelectedIndexChanged(object sender, EventArgs e)
    {
    Console.WriteLine("test");
    }
    #endregion

    #region Private functions
    private void LoadProducts()
    {
    ABBPortalBusinessComponents.Product oProducts = new
    ABBPortalBusinessComponents.Product();
    dsProducts = oProducts.GetProducts("Default.aspx");
    }
    #endregion


    }
    }

    Thanks
    J
    Julia, May 31, 2006
    #1
    1. Advertising

  2. I would try saving the SelectedIndex property of the DropDownList during the
    postback, and then set the SelectedIndex when the control is recreated.
    --
    Nathan Sokalski

    http://www.nathansokalski.com/

    "Julia" <> wrote in message
    news:...
    > Hi
    > I am trying to develop a composite control (i am new in this area). This
    > control will be compiled into a dll and used by a web page. The control
    > are
    > containing a DataGrid and some DropDownLists that are populated from a
    > dataset.
    >
    > When I pick a value in a a DropDown I want to apply some RowFilter to my
    > DataGrid. The problem is that the entire control is rewritten
    > (CreateChildControls is called) so the value that I picket in the DropDown
    > are gone. How can I solve this?
    >
    > I send you the code here aswell:
    >
    > using System;
    > using System.Collections.Generic;
    > using System.ComponentModel;
    > using System.Text;
    > using System.Web;
    > using System.Web.UI;
    > using System.Web.UI.WebControls;
    > using System.Data;
    > using System.Collections;
    >
    > namespace ABBPISControls
    > {
    > [DefaultProperty("Text")]
    > [ToolboxData("<{0}:productDetails runat=server></{0}:productDetails>")]
    > public class ProductDetails : CompositeControl
    > {
    > private DataSet dsProducts = null;
    >
    > private DropDownList[] drAttrDefault = null;
    > private Label[] lblAttrHeaders = null;
    > private DataView[] dvAttrDefault = null;
    > private DropDownList drAttrAdditional = new DropDownList();
    > private DataGrid dgProductList = new DataGrid();
    > private int iDefaultAttr = 0;
    >
    > private Button btnTest = new Button();
    >
    >
    > protected override void CreateChildControls()
    > {
    > //Gets a dataset from a web service with product information
    > LoadProducts();
    >
    > #region dgProductList
    > dgProductList.AutoGenerateColumns = false;
    >
    > HyperLinkColumn cName = new HyperLinkColumn();
    > cName.HeaderText = "TypeCID;
    > cName.DataNavigateUrlField = "Url";
    > cName.DataTextField = "ProductId";
    >
    > BoundColumn bcColumn1 = new BoundColumn();
    > bcColumn1.HeaderText = "AbbType";
    > bcColumn1.DataField = "AbbType";
    >
    > BoundColumn bcColumn2 = new BoundColumn();
    > bcColumn2.HeaderText = "ClassCID";
    > bcColumn2.DataField = "ClassCID";
    >
    > BoundColumn bcColumn3 = new BoundColumn();
    > bcColumn3.HeaderText = "Title";
    > bcColumn3.DataField = "Title";
    >
    > BoundColumn bcColumn4 = new BoundColumn();
    > bcColumn4.HeaderText = "TypeCID";
    > bcColumn4.DataField = "TypeCID";
    >
    > BoundColumn bcColumn5 = new BoundColumn();
    > bcColumn5.HeaderText = "UOM";
    > bcColumn5.DataField = "UOM";
    >
    > dgProductList.Columns.Add(cName);
    > dgProductList.Columns.Add(bcColumn1);
    > dgProductList.Columns.Add(bcColumn2);
    > dgProductList.Columns.Add(bcColumn3);
    > dgProductList.Columns.Add(bcColumn4);
    > dgProductList.Columns.Add(bcColumn5);
    >
    > dgProductList.DataSource = dsProducts.Tables[0];
    > dgProductList.DataBind();
    >
    > this.Controls.Add(dgProductList);
    > #endregion
    >
    > #region drAttrDefault & lblAttrHeaders
    > iDefaultAttr = dsProducts.Tables["AttributeHeader"].Rows.Count;
    > drAttrDefault = new DropDownList[iDefaultAttr];
    > lblAttrHeaders = new Label[iDefaultAttr];
    > dvAttrDefault = new DataView[iDefaultAttr];
    > int i = 0;
    > ArrayList alAttrHeaders = new ArrayList();
    > foreach (DataRow drAttr in
    > dsProducts.Tables["AttributeHeader"].Rows)
    > {
    > if (drAttr["Default"].ToString() == "1")
    > {
    > //Create the new DataView and RowFilter
    > dvAttrDefault = new
    > DataView(dsProducts.Tables["AttributeValue"]);
    > dvAttrDefault.RowFilter = "AttrId = '" +
    > drAttr["AttrId"].ToString() + "'";
    >
    > //Cretate the Label for the header
    > lblAttrHeaders = new Label();
    > lblAttrHeaders.Text = drAttr["Name"].ToString();
    >
    > //Create the DropDown and bind it to the datasourece
    > drAttrDefault = new DropDownList();
    > drAttrDefault.AutoPostBack = true;
    > drAttrDefault.DataSource = dvAttrDefault;
    > drAttrDefault.DataValueField = "AttrId";
    > drAttrDefault.DataTextField = "Count";
    > drAttrDefault.DataBind();
    >
    > drAttrDefault.SelectedIndexChanged += new
    > EventHandler(ProductDetails_SelectedIndexChanged);
    >
    > //Add controls to page
    > this.Controls.Add(lblAttrHeaders);
    > this.Controls.Add(drAttrDefault);
    > i++;
    > alAttrHeaders.Add(drAttr["AttrId"]);
    > }
    > }
    > iDefaultAttr = i;
    > #endregion
    >
    > #region drAttrAdditional
    > drAttrAdditional.AutoPostBack = true;
    > dsProducts.Tables["AttributeHeader"].DefaultView.RowFilter =
    > "Default = '0'";
    > drAttrAdditional.DataSource =
    > dsProducts.Tables["AttributeHeader"].DefaultView;
    > drAttrAdditional.DataValueField = "AttrId";
    > drAttrAdditional.DataTextField = "Name";
    > drAttrAdditional.DataBind();
    > drAttrAdditional.SelectedIndexChanged += new
    > EventHandler(myDropDown_SelectedIndexChanged);
    > this.Controls.Add(drAttrAdditional);
    > #endregion
    >
    > btnTest.Text = "Test";
    > btnTest.Click += new EventHandler(btnTest_Click);
    > this.Controls.Add(btnTest);
    >
    > //base.CreateChildControls();
    >
    > }
    > protected override void RenderContents(HtmlTextWriter output)
    > {
    > dgProductList.RenderControl(output);
    > for (int i = 0; i < iDefaultAttr; i++)
    > {
    > lblAttrHeaders.RenderControl(output);
    > output.Write("<br>");
    > drAttrDefault.RenderControl(output);
    > output.Write("<br>");
    > }
    > drAttrAdditional.RenderControl(output);
    >
    > btnTest.RenderControl(output);
    > }
    > #region Events
    > void myDropDown_SelectedIndexChanged(object sender, EventArgs e)
    > {
    > Console.WriteLine("test");
    > }
    > void btnTest_Click(object sender, EventArgs e)
    > {
    > Console.WriteLine("test");
    > }
    >
    > void ProductDetails_SelectedIndexChanged(object sender, EventArgs
    > e)
    > {
    > Console.WriteLine("test");
    > }
    > #endregion
    >
    > #region Private functions
    > private void LoadProducts()
    > {
    > ABBPortalBusinessComponents.Product oProducts = new
    > ABBPortalBusinessComponents.Product();
    > dsProducts = oProducts.GetProducts("Default.aspx");
    > }
    > #endregion
    >
    >
    > }
    > }
    >
    > Thanks
    > J
    >
    Nathan Sokalski, May 31, 2006
    #2
    1. Advertising

  3. Julia

    Julia Guest

    Hi

    Thanks for the answer but I am not sure it works. The first thing that
    happens is that the controls are created (private DropDownList
    drAttrAdditional = new DropDownList();) so the selectedInsex will always be
    -1.

    Any other idea?

    Thanks
    J


    "Nathan Sokalski" wrote:

    > I would try saving the SelectedIndex property of the DropDownList during the
    > postback, and then set the SelectedIndex when the control is recreated.
    > --
    > Nathan Sokalski
    >
    > http://www.nathansokalski.com/
    >
    > "Julia" <> wrote in message
    > news:...
    > > Hi
    > > I am trying to develop a composite control (i am new in this area). This
    > > control will be compiled into a dll and used by a web page. The control
    > > are
    > > containing a DataGrid and some DropDownLists that are populated from a
    > > dataset.
    > >
    > > When I pick a value in a a DropDown I want to apply some RowFilter to my
    > > DataGrid. The problem is that the entire control is rewritten
    > > (CreateChildControls is called) so the value that I picket in the DropDown
    > > are gone. How can I solve this?
    > >
    > > I send you the code here aswell:
    > >
    > > using System;
    > > using System.Collections.Generic;
    > > using System.ComponentModel;
    > > using System.Text;
    > > using System.Web;
    > > using System.Web.UI;
    > > using System.Web.UI.WebControls;
    > > using System.Data;
    > > using System.Collections;
    > >
    > > namespace ABBPISControls
    > > {
    > > [DefaultProperty("Text")]
    > > [ToolboxData("<{0}:productDetails runat=server></{0}:productDetails>")]
    > > public class ProductDetails : CompositeControl
    > > {
    > > private DataSet dsProducts = null;
    > >
    > > private DropDownList[] drAttrDefault = null;
    > > private Label[] lblAttrHeaders = null;
    > > private DataView[] dvAttrDefault = null;
    > > private DropDownList drAttrAdditional = new DropDownList();
    > > private DataGrid dgProductList = new DataGrid();
    > > private int iDefaultAttr = 0;
    > >
    > > private Button btnTest = new Button();
    > >
    > >
    > > protected override void CreateChildControls()
    > > {
    > > //Gets a dataset from a web service with product information
    > > LoadProducts();
    > >
    > > #region dgProductList
    > > dgProductList.AutoGenerateColumns = false;
    > >
    > > HyperLinkColumn cName = new HyperLinkColumn();
    > > cName.HeaderText = "TypeCID;
    > > cName.DataNavigateUrlField = "Url";
    > > cName.DataTextField = "ProductId";
    > >
    > > BoundColumn bcColumn1 = new BoundColumn();
    > > bcColumn1.HeaderText = "AbbType";
    > > bcColumn1.DataField = "AbbType";
    > >
    > > BoundColumn bcColumn2 = new BoundColumn();
    > > bcColumn2.HeaderText = "ClassCID";
    > > bcColumn2.DataField = "ClassCID";
    > >
    > > BoundColumn bcColumn3 = new BoundColumn();
    > > bcColumn3.HeaderText = "Title";
    > > bcColumn3.DataField = "Title";
    > >
    > > BoundColumn bcColumn4 = new BoundColumn();
    > > bcColumn4.HeaderText = "TypeCID";
    > > bcColumn4.DataField = "TypeCID";
    > >
    > > BoundColumn bcColumn5 = new BoundColumn();
    > > bcColumn5.HeaderText = "UOM";
    > > bcColumn5.DataField = "UOM";
    > >
    > > dgProductList.Columns.Add(cName);
    > > dgProductList.Columns.Add(bcColumn1);
    > > dgProductList.Columns.Add(bcColumn2);
    > > dgProductList.Columns.Add(bcColumn3);
    > > dgProductList.Columns.Add(bcColumn4);
    > > dgProductList.Columns.Add(bcColumn5);
    > >
    > > dgProductList.DataSource = dsProducts.Tables[0];
    > > dgProductList.DataBind();
    > >
    > > this.Controls.Add(dgProductList);
    > > #endregion
    > >
    > > #region drAttrDefault & lblAttrHeaders
    > > iDefaultAttr = dsProducts.Tables["AttributeHeader"].Rows.Count;
    > > drAttrDefault = new DropDownList[iDefaultAttr];
    > > lblAttrHeaders = new Label[iDefaultAttr];
    > > dvAttrDefault = new DataView[iDefaultAttr];
    > > int i = 0;
    > > ArrayList alAttrHeaders = new ArrayList();
    > > foreach (DataRow drAttr in
    > > dsProducts.Tables["AttributeHeader"].Rows)
    > > {
    > > if (drAttr["Default"].ToString() == "1")
    > > {
    > > //Create the new DataView and RowFilter
    > > dvAttrDefault = new
    > > DataView(dsProducts.Tables["AttributeValue"]);
    > > dvAttrDefault.RowFilter = "AttrId = '" +
    > > drAttr["AttrId"].ToString() + "'";
    > >
    > > //Cretate the Label for the header
    > > lblAttrHeaders = new Label();
    > > lblAttrHeaders.Text = drAttr["Name"].ToString();
    > >
    > > //Create the DropDown and bind it to the datasourece
    > > drAttrDefault = new DropDownList();
    > > drAttrDefault.AutoPostBack = true;
    > > drAttrDefault.DataSource = dvAttrDefault;
    > > drAttrDefault.DataValueField = "AttrId";
    > > drAttrDefault.DataTextField = "Count";
    > > drAttrDefault.DataBind();
    > >
    > > drAttrDefault.SelectedIndexChanged += new
    > > EventHandler(ProductDetails_SelectedIndexChanged);
    > >
    > > //Add controls to page
    > > this.Controls.Add(lblAttrHeaders);
    > > this.Controls.Add(drAttrDefault);
    > > i++;
    > > alAttrHeaders.Add(drAttr["AttrId"]);
    > > }
    > > }
    > > iDefaultAttr = i;
    > > #endregion
    > >
    > > #region drAttrAdditional
    > > drAttrAdditional.AutoPostBack = true;
    > > dsProducts.Tables["AttributeHeader"].DefaultView.RowFilter =
    > > "Default = '0'";
    > > drAttrAdditional.DataSource =
    > > dsProducts.Tables["AttributeHeader"].DefaultView;
    > > drAttrAdditional.DataValueField = "AttrId";
    > > drAttrAdditional.DataTextField = "Name";
    > > drAttrAdditional.DataBind();
    > > drAttrAdditional.SelectedIndexChanged += new
    > > EventHandler(myDropDown_SelectedIndexChanged);
    > > this.Controls.Add(drAttrAdditional);
    > > #endregion
    > >
    > > btnTest.Text = "Test";
    > > btnTest.Click += new EventHandler(btnTest_Click);
    > > this.Controls.Add(btnTest);
    > >
    > > //base.CreateChildControls();
    > >
    > > }
    > > protected override void RenderContents(HtmlTextWriter output)
    > > {
    > > dgProductList.RenderControl(output);
    > > for (int i = 0; i < iDefaultAttr; i++)
    > > {
    > > lblAttrHeaders.RenderControl(output);
    > > output.Write("<br>");
    > > drAttrDefault.RenderControl(output);
    > > output.Write("<br>");
    > > }
    > > drAttrAdditional.RenderControl(output);
    > >
    > > btnTest.RenderControl(output);
    > > }
    > > #region Events
    > > void myDropDown_SelectedIndexChanged(object sender, EventArgs e)
    > > {
    > > Console.WriteLine("test");
    > > }
    > > void btnTest_Click(object sender, EventArgs e)
    > > {
    > > Console.WriteLine("test");
    > > }
    > >
    > > void ProductDetails_SelectedIndexChanged(object sender, EventArgs
    > > e)
    > > {
    > > Console.WriteLine("test");
    > > }
    > > #endregion
    > >
    > > #region Private functions
    > > private void LoadProducts()
    > > {
    > > ABBPortalBusinessComponents.Product oProducts = new
    > > ABBPortalBusinessComponents.Product();
    > > dsProducts = oProducts.GetProducts("Default.aspx");
    > > }
    > > #endregion
    > >
    > >
    > > }
    > > }
    > >
    > > Thanks
    > > J
    > >

    >
    >
    >
    Julia, Jun 1, 2006
    #3
  4. I think it would be easier to help if I could see the actual code so I can
    see what is happening where. It sounds like you are not using my suggestion
    the way I expected.
    --
    Nathan Sokalski

    http://www.nathansokalski.com/

    "Julia" <> wrote in message
    news:...
    > Hi
    >
    > Thanks for the answer but I am not sure it works. The first thing that
    > happens is that the controls are created (private DropDownList
    > drAttrAdditional = new DropDownList();) so the selectedInsex will always
    > be
    > -1.
    >
    > Any other idea?
    >
    > Thanks
    > J
    >
    >
    > "Nathan Sokalski" wrote:
    >
    >> I would try saving the SelectedIndex property of the DropDownList during
    >> the
    >> postback, and then set the SelectedIndex when the control is recreated.
    >> --
    >> Nathan Sokalski
    >>
    >> http://www.nathansokalski.com/
    >>
    >> "Julia" <> wrote in message
    >> news:...
    >> > Hi
    >> > I am trying to develop a composite control (i am new in this area).
    >> > This
    >> > control will be compiled into a dll and used by a web page. The control
    >> > are
    >> > containing a DataGrid and some DropDownLists that are populated from a
    >> > dataset.
    >> >
    >> > When I pick a value in a a DropDown I want to apply some RowFilter to
    >> > my
    >> > DataGrid. The problem is that the entire control is rewritten
    >> > (CreateChildControls is called) so the value that I picket in the
    >> > DropDown
    >> > are gone. How can I solve this?
    >> >
    >> > I send you the code here aswell:
    >> >
    >> > using System;
    >> > using System.Collections.Generic;
    >> > using System.ComponentModel;
    >> > using System.Text;
    >> > using System.Web;
    >> > using System.Web.UI;
    >> > using System.Web.UI.WebControls;
    >> > using System.Data;
    >> > using System.Collections;
    >> >
    >> > namespace ABBPISControls
    >> > {
    >> > [DefaultProperty("Text")]
    >> > [ToolboxData("<{0}:productDetails
    >> > runat=server></{0}:productDetails>")]
    >> > public class ProductDetails : CompositeControl
    >> > {
    >> > private DataSet dsProducts = null;
    >> >
    >> > private DropDownList[] drAttrDefault = null;
    >> > private Label[] lblAttrHeaders = null;
    >> > private DataView[] dvAttrDefault = null;
    >> > private DropDownList drAttrAdditional = new DropDownList();
    >> > private DataGrid dgProductList = new DataGrid();
    >> > private int iDefaultAttr = 0;
    >> >
    >> > private Button btnTest = new Button();
    >> >
    >> >
    >> > protected override void CreateChildControls()
    >> > {
    >> > //Gets a dataset from a web service with product information
    >> > LoadProducts();
    >> >
    >> > #region dgProductList
    >> > dgProductList.AutoGenerateColumns = false;
    >> >
    >> > HyperLinkColumn cName = new HyperLinkColumn();
    >> > cName.HeaderText = "TypeCID;
    >> > cName.DataNavigateUrlField = "Url";
    >> > cName.DataTextField = "ProductId";
    >> >
    >> > BoundColumn bcColumn1 = new BoundColumn();
    >> > bcColumn1.HeaderText = "AbbType";
    >> > bcColumn1.DataField = "AbbType";
    >> >
    >> > BoundColumn bcColumn2 = new BoundColumn();
    >> > bcColumn2.HeaderText = "ClassCID";
    >> > bcColumn2.DataField = "ClassCID";
    >> >
    >> > BoundColumn bcColumn3 = new BoundColumn();
    >> > bcColumn3.HeaderText = "Title";
    >> > bcColumn3.DataField = "Title";
    >> >
    >> > BoundColumn bcColumn4 = new BoundColumn();
    >> > bcColumn4.HeaderText = "TypeCID";
    >> > bcColumn4.DataField = "TypeCID";
    >> >
    >> > BoundColumn bcColumn5 = new BoundColumn();
    >> > bcColumn5.HeaderText = "UOM";
    >> > bcColumn5.DataField = "UOM";
    >> >
    >> > dgProductList.Columns.Add(cName);
    >> > dgProductList.Columns.Add(bcColumn1);
    >> > dgProductList.Columns.Add(bcColumn2);
    >> > dgProductList.Columns.Add(bcColumn3);
    >> > dgProductList.Columns.Add(bcColumn4);
    >> > dgProductList.Columns.Add(bcColumn5);
    >> >
    >> > dgProductList.DataSource = dsProducts.Tables[0];
    >> > dgProductList.DataBind();
    >> >
    >> > this.Controls.Add(dgProductList);
    >> > #endregion
    >> >
    >> > #region drAttrDefault & lblAttrHeaders
    >> > iDefaultAttr =
    >> > dsProducts.Tables["AttributeHeader"].Rows.Count;
    >> > drAttrDefault = new DropDownList[iDefaultAttr];
    >> > lblAttrHeaders = new Label[iDefaultAttr];
    >> > dvAttrDefault = new DataView[iDefaultAttr];
    >> > int i = 0;
    >> > ArrayList alAttrHeaders = new ArrayList();
    >> > foreach (DataRow drAttr in
    >> > dsProducts.Tables["AttributeHeader"].Rows)
    >> > {
    >> > if (drAttr["Default"].ToString() == "1")
    >> > {
    >> > //Create the new DataView and RowFilter
    >> > dvAttrDefault = new
    >> > DataView(dsProducts.Tables["AttributeValue"]);
    >> > dvAttrDefault.RowFilter = "AttrId = '" +
    >> > drAttr["AttrId"].ToString() + "'";
    >> >
    >> > //Cretate the Label for the header
    >> > lblAttrHeaders = new Label();
    >> > lblAttrHeaders.Text = drAttr["Name"].ToString();
    >> >
    >> > //Create the DropDown and bind it to the datasourece
    >> > drAttrDefault = new DropDownList();
    >> > drAttrDefault.AutoPostBack = true;
    >> > drAttrDefault.DataSource = dvAttrDefault;
    >> > drAttrDefault.DataValueField = "AttrId";
    >> > drAttrDefault.DataTextField = "Count";
    >> > drAttrDefault.DataBind();
    >> >
    >> > drAttrDefault.SelectedIndexChanged += new
    >> > EventHandler(ProductDetails_SelectedIndexChanged);
    >> >
    >> > //Add controls to page
    >> > this.Controls.Add(lblAttrHeaders);
    >> > this.Controls.Add(drAttrDefault);
    >> > i++;
    >> > alAttrHeaders.Add(drAttr["AttrId"]);
    >> > }
    >> > }
    >> > iDefaultAttr = i;
    >> > #endregion
    >> >
    >> > #region drAttrAdditional
    >> > drAttrAdditional.AutoPostBack = true;
    >> > dsProducts.Tables["AttributeHeader"].DefaultView.RowFilter =
    >> > "Default = '0'";
    >> > drAttrAdditional.DataSource =
    >> > dsProducts.Tables["AttributeHeader"].DefaultView;
    >> > drAttrAdditional.DataValueField = "AttrId";
    >> > drAttrAdditional.DataTextField = "Name";
    >> > drAttrAdditional.DataBind();
    >> > drAttrAdditional.SelectedIndexChanged += new
    >> > EventHandler(myDropDown_SelectedIndexChanged);
    >> > this.Controls.Add(drAttrAdditional);
    >> > #endregion
    >> >
    >> > btnTest.Text = "Test";
    >> > btnTest.Click += new EventHandler(btnTest_Click);
    >> > this.Controls.Add(btnTest);
    >> >
    >> > //base.CreateChildControls();
    >> >
    >> > }
    >> > protected override void RenderContents(HtmlTextWriter output)
    >> > {
    >> > dgProductList.RenderControl(output);
    >> > for (int i = 0; i < iDefaultAttr; i++)
    >> > {
    >> > lblAttrHeaders.RenderControl(output);
    >> > output.Write("<br>");
    >> > drAttrDefault.RenderControl(output);
    >> > output.Write("<br>");
    >> > }
    >> > drAttrAdditional.RenderControl(output);
    >> >
    >> > btnTest.RenderControl(output);
    >> > }
    >> > #region Events
    >> > void myDropDown_SelectedIndexChanged(object sender, EventArgs e)
    >> > {
    >> > Console.WriteLine("test");
    >> > }
    >> > void btnTest_Click(object sender, EventArgs e)
    >> > {
    >> > Console.WriteLine("test");
    >> > }
    >> >
    >> > void ProductDetails_SelectedIndexChanged(object sender,
    >> > EventArgs
    >> > e)
    >> > {
    >> > Console.WriteLine("test");
    >> > }
    >> > #endregion
    >> >
    >> > #region Private functions
    >> > private void LoadProducts()
    >> > {
    >> > ABBPortalBusinessComponents.Product oProducts = new
    >> > ABBPortalBusinessComponents.Product();
    >> > dsProducts = oProducts.GetProducts("Default.aspx");
    >> > }
    >> > #endregion
    >> >
    >> >
    >> > }
    >> > }
    >> >
    >> > Thanks
    >> > J
    >> >

    >>
    >>
    >>
    Nathan Sokalski, Jun 1, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. mr2_93
    Replies:
    1
    Views:
    3,582
    mr2_93
    Oct 2, 2005
  2. tshad
    Replies:
    8
    Views:
    2,206
    tshad
    Oct 19, 2005
  3. =?Utf-8?B?SnVhbmpv?=

    GridView: Filtr DropDownList from another DropDownList

    =?Utf-8?B?SnVhbmpv?=, Dec 23, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    1,848
    =?Utf-8?B?SnVhbmpv?=
    Dec 23, 2005
  4. =?Utf-8?B?SnVhbmpv?=

    GridView: Filter DropDownList for another DropDownList

    =?Utf-8?B?SnVhbmpv?=, Dec 29, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    1,283
    =?Utf-8?B?SnVhbmpv?=
    Dec 29, 2005
  5. keithb
    Replies:
    1
    Views:
    11,916
    shauns1
    Nov 1, 2006
Loading...

Share This Page