Accessing the selectedIndex of a dynamically created Dropdownlist...
-
Hai, I have created a footer template in my gridview, This footer template contain many dynamically created controls where the dropdownlist is one. I have created the dropdown and assigned a function to it as follows: DropDownList selPage = new DropDownList(); selPage.ID = "selPage"; selPage.CssClass = "GVFooterSel"; for (int cnt = 0; cnt < GVDoctor.PageCount; cnt++) { int curr = cnt + 1; ListItem item = new ListItem(curr.ToString()); if (cnt == GVDoctor.PageIndex) { item.Selected = true; } selPage.Items.Add(item); } selPage.AutoPostBack = true; selPage.SelectedIndexChanged += new EventHandler(selPage_SelectedIndexChanged); selPage.Attributes.Add("onchange", "selPage_SelectedIndexChanged(this,event)"); The functions gets fired but i can't able to find the control and access its selected index. can any help me?
:-) Radiv Jeshya :-)
-
Hai, I have created a footer template in my gridview, This footer template contain many dynamically created controls where the dropdownlist is one. I have created the dropdown and assigned a function to it as follows: DropDownList selPage = new DropDownList(); selPage.ID = "selPage"; selPage.CssClass = "GVFooterSel"; for (int cnt = 0; cnt < GVDoctor.PageCount; cnt++) { int curr = cnt + 1; ListItem item = new ListItem(curr.ToString()); if (cnt == GVDoctor.PageIndex) { item.Selected = true; } selPage.Items.Add(item); } selPage.AutoPostBack = true; selPage.SelectedIndexChanged += new EventHandler(selPage_SelectedIndexChanged); selPage.Attributes.Add("onchange", "selPage_SelectedIndexChanged(this,event)"); The functions gets fired but i can't able to find the control and access its selected index. can any help me?
:-) Radiv Jeshya :-)
Hi, In the selPage_SelectedIndexChanged event, you can get the selected index of the control by using the following code: int selectedIndex = ((DropDownList)sender).SelectedIndex; I hope it will solve your problem. :) Regards Saanj
Either you love IT or leave IT...
-
Hai, I have created a footer template in my gridview, This footer template contain many dynamically created controls where the dropdownlist is one. I have created the dropdown and assigned a function to it as follows: DropDownList selPage = new DropDownList(); selPage.ID = "selPage"; selPage.CssClass = "GVFooterSel"; for (int cnt = 0; cnt < GVDoctor.PageCount; cnt++) { int curr = cnt + 1; ListItem item = new ListItem(curr.ToString()); if (cnt == GVDoctor.PageIndex) { item.Selected = true; } selPage.Items.Add(item); } selPage.AutoPostBack = true; selPage.SelectedIndexChanged += new EventHandler(selPage_SelectedIndexChanged); selPage.Attributes.Add("onchange", "selPage_SelectedIndexChanged(this,event)"); The functions gets fired but i can't able to find the control and access its selected index. can any help me?
:-) Radiv Jeshya :-)
Just add a panel in your .aspx page because u need some controls like panel or table or place holder to display the dynamic controls, Your code here, DropDownList selPage = new DropDownList(); selPage.ID = "selPage"; selPage.CssClass = "GVFooterSel"; for (int cnt = 0; cnt < GVDoctor.PageCount; cnt++) { int curr = cnt + 1; ListItem item = new ListItem(curr.ToString()); if (cnt == GVDoctor.PageIndex) { item.Selected = true; } selPage.Items.Add(item); } // add this line and run. Now u could see your dropdown in the interface. Panel1.Controls.Add(selPage); selPage.AutoPostBack = true; selPage.SelectedIndexChanged += new EventHandler(selPage_SelectedIndexChanged); selPage.Attributes.Add("onchange", "selPage_SelectedIndexChanged(this,event)");