J
Julia
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}roductDetails runat=server></{0}roductDetails>")]
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
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}roductDetails runat=server></{0}roductDetails>")]
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