Dropdown event is not firing when item has been changed.
-
Hi, The dropdown event is not firing when i changed an item in drop down list. Can any one suggest what's going wrong in my code.
public class FirstWebPart : System.Web.UI.WebControls.WebParts.WebPart
{
DataSet _listData;
string _SelectedValue = string.Empty;
DropDownList ddlList = new DropDownList();
DataGrid dgSpListData = new DataGrid();public FirstWebPart() { } protected override void CreateChildControls() { base.CreateChildControls(); // TODO: add custom rendering code here. Label lblAssignedTo = new Label(); lblAssignedTo.Text = "Assigned To"; string\[\] Members = { "Satish", "Suman", "Saravana" }; ddlList.DataSource = Members; ddlList.DataBind(); this.Controls.Add(lblAssignedTo); this.Controls.Add(ddlList); this.ddlList.SelectedIndexChanged += new EventHandler(\_ddlList\_SelectedIndexChanged); this.\_SelectedValue = ddlList.SelectedValue.ToString(); dgSpListData.DataSource = GetListData(\_SelectedValue); dgSpListData.DataBind(); this.Controls.Add(dgSpListData); } void \_ddlList\_SelectedIndexChanged(object sender, EventArgs e) { this.\_SelectedValue = ddlList.SelectedValue.ToString(); //DataGrid dgSpListData = new DataGrid(); dgSpListData.DataSource = GetListData(\_SelectedValue); dgSpListData.DataBind(); //this.Controls.Add(dgSpListData); } DataSet GetListData(string \_SelectedValue) { \_listData = new DataSet(); DataTable \_table = new DataTable(); DataColumn dc = new DataColumn("Title"); \_table.Columns.Add(dc); dc = new DataColumn("AssignedTo"); \_table.Columns.Add(dc); dc = new DataColumn("Status"); \_table.Columns.Add(dc); using (SPWeb web = SPContext.Current.Site.RootWeb) { SPList mylist = web.Lists\["MySPList"\]; SPQuery query = new SPQuery(); query.Query = "<Where><Eq><FieldRef Name='AssignedTo'/><Value Type='Text'>" + \_SelectedValue+ "</Value></Eq></Where>"; SPListItemCollection items = mylist.GetItems(query);
-
Hi, The dropdown event is not firing when i changed an item in drop down list. Can any one suggest what's going wrong in my code.
public class FirstWebPart : System.Web.UI.WebControls.WebParts.WebPart
{
DataSet _listData;
string _SelectedValue = string.Empty;
DropDownList ddlList = new DropDownList();
DataGrid dgSpListData = new DataGrid();public FirstWebPart() { } protected override void CreateChildControls() { base.CreateChildControls(); // TODO: add custom rendering code here. Label lblAssignedTo = new Label(); lblAssignedTo.Text = "Assigned To"; string\[\] Members = { "Satish", "Suman", "Saravana" }; ddlList.DataSource = Members; ddlList.DataBind(); this.Controls.Add(lblAssignedTo); this.Controls.Add(ddlList); this.ddlList.SelectedIndexChanged += new EventHandler(\_ddlList\_SelectedIndexChanged); this.\_SelectedValue = ddlList.SelectedValue.ToString(); dgSpListData.DataSource = GetListData(\_SelectedValue); dgSpListData.DataBind(); this.Controls.Add(dgSpListData); } void \_ddlList\_SelectedIndexChanged(object sender, EventArgs e) { this.\_SelectedValue = ddlList.SelectedValue.ToString(); //DataGrid dgSpListData = new DataGrid(); dgSpListData.DataSource = GetListData(\_SelectedValue); dgSpListData.DataBind(); //this.Controls.Add(dgSpListData); } DataSet GetListData(string \_SelectedValue) { \_listData = new DataSet(); DataTable \_table = new DataTable(); DataColumn dc = new DataColumn("Title"); \_table.Columns.Add(dc); dc = new DataColumn("AssignedTo"); \_table.Columns.Add(dc); dc = new DataColumn("Status"); \_table.Columns.Add(dc); using (SPWeb web = SPContext.Current.Site.RootWeb) { SPList mylist = web.Lists\["MySPList"\]; SPQuery query = new SPQuery(); query.Query = "<Where><Eq><FieldRef Name='AssignedTo'/><Value Type='Text'>" + \_SelectedValue+ "</Value></Eq></Where>"; SPListItemCollection items = mylist.GetItems(query);
- Set AutoPostBack = true on the dropdown 2) using (SPWeb web = SPContext.Current.Site.RootWeb) You don't dispose of objects obtained from the SPContext 3) You don't need to create a DataTable from the SPListItemCollection. Use GetDataTable method.
I know the language. I've read a book. - _Madmatt
modified on Monday, October 4, 2010 8:39 AM
-
- Set AutoPostBack = true on the dropdown 2) using (SPWeb web = SPContext.Current.Site.RootWeb) You don't dispose of objects obtained from the SPContext 3) You don't need to create a DataTable from the SPListItemCollection. Use GetDataTable method.
I know the language. I've read a book. - _Madmatt
modified on Monday, October 4, 2010 8:39 AM
Thanks for your reply. It works for me ;)
G. Satish