|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
I am developing a asp.net page which has a datagrid popluating dynamically generated dropdown lists bound to the ID within the datagrid.
I need to javascript to be triggered on index changed of the dropdown list. The placeholder generates a list of the parent procedures. On Click they populate the datagrid with child procedures. Each child procedure has a certain locations where the procedures are performed. I am able to generate the dropdown lists but am having trouble with getting the onSelectedItemIndexChanged to fire the javascript. Please help. The code is as follows. linkButton.aspx ************** <%@ Page language="c#" Codebehind="LinkButton.aspx.cs" AutoEventWireup="false" Inherits="Training.WebForm9" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > <HTML> <HEAD> <title>WebForm9</title> <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1"> <meta name="CODE_LANGUAGE" Content="C#"> <meta name="vs_defaultClientScript" content="JavaScript"> <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5"> </HEAD> <body MS_POSITIONING="GridLayout"> <form id="Form1" method="post" runat="server"> <asp:PlaceHolder id="PlaceHolder1" runat="server"></asp:PlaceHolder> <asp ataGrid id="dgProcedures" DataKeyField="ProcedureID" AutoGenerateColumns="False" style="Z-INDEX: 101; LEFT: 24px; POSITION: absolute; TOP: 104px"runat="server" OnItemDataBound="BuildLocationDropdown"> <Columns> <asp:TemplateColumn> <ItemTemplate> <asp:CheckBox Runat="server" ID="ParentID"></asp:CheckBox> </ItemTemplate> </asp:TemplateColumn> <asp:BoundColumn DataField="ChildName" HeaderText="Procedure"></asp:BoundColumn> <asp:BoundColumn DataField="MaxDuration" HeaderText="Max Duration"></asp:BoundColumn> <asp:BoundColumn DataField="ParentID" HeaderText="Parent ID"></asp:BoundColumn> <asp:TemplateColumn HeaderText="Locations"></asp:TemplateColumn> </Columns> </asp ataGrid></form> <script language="javascript"> function getLocation(i) { // i = LocationID from the dropdown generated alert ("i"); } </script> </body> </HTML> ********** linkButton.aspx.cs ******************* using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Data.SqlClient; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; namespace Training { /// <summary> /// Summary description for WebForm9. /// </summary> public class WebForm9 : System.Web.UI.Page { protected System.Web.UI.WebControls.PlaceHolder PlaceHolder1; protected System.Web.UI.WebControls.DataGrid dgProcedures; DataSet ds=new DataSet(); private void Page_Load(object sender, System.EventArgs e) { if(!Page.IsPostBack) { BindData(2); } LinkButton filterButton = new LinkButton(); Database db=new Database(); SqlDataReader reader = null; db.RunProc("getParentList", out reader); while (reader.Read()) { filterButton= new LinkButton(); filterButton.BackColor=System.Drawing.Color.Beige; filterButton.Text=reader.GetString(1); filterButton.CommandArgument=Convert.ToString(read er.GetInt32(0)); filterButton.Command+=new CommandEventHandler(this.filterData); PlaceHolder1.Controls.Add(filterButton); PlaceHolder1.Controls.Add(new LiteralControl(" | ")); } } public void filterData(object sender, CommandEventArgs e) { BindData(Int32.Parse(e.CommandArgument.ToString()) ); } public void BindData(int ParentID) { Database db=new Database(); SqlDataReader reader=null; SqlParameter[] prams= { db.MakeInParam("@ParentID", SqlDbType.Int, 4, ParentID) }; db.RunProc("getChildList", prams, out reader); dgProcedures.DataSource=reader; string SqlLocation="Select * from tblLocation"; SqlConnection conn; conn=DBUtility.getDatabaseConnection(); SqlCommand cmd=new SqlCommand(SqlLocation, conn); SqlDataAdapter lstDA= new SqlDataAdapter(cmd); conn.Open(); lstDA.Fill(ds,"tblLocation"); dgProcedures.DataBind(); } public void BuildLocationDropdown(object sender, DataGridItemEventArgs e) { if (e.Item.ItemType.Equals(ListItemType.Item) || e.Item.ItemType.Equals(ListItemType.AlternatingIte m)) { DropDownList lstLocation = new DropDownList(); string dlLocationName=""; int ProcedureID=Int32.Parse(((System.Data.Common.DbDat aRecord)e.Item.DataItem)["ProcedureID"].ToString()); DataView LocProcedures = new DataView(); LocProcedures=ds.Tables["tblLocation"].DefaultView; LocProcedures.RowFilter="ProcedureID="+ProcedureID; lstLocation.DataSource=LocProcedures; lstLocation.DataTextField="LocationName"; lstLocation.DataValueField="LocationID"; lstLocation.DataBind(); lstLocation.Items.Insert(0,new ListItem("Select Location","0")); Int32 LocationID = Convert.ToInt32(lstLocation.SelectedIndex); e.Item.Cells[4].Controls.Add(lstLocation); lstLocation.Attributes.Add("OnSelectedIndexChanged", "javascript:getLocation(LocationID)"); lstLocation.Attributes.Add("runat","Server"); lstLocation.Attributes.Add("AutoPostBack","True"); lstLocation.Attributes.Add("DataTextField", "LocationName"); lstLocation.Attributes.Add("DataValueField", "LocationID"); } } #region Web Form Designer generated code override protected void OnInit(EventArgs e) { // // CODEGEN: This call is required by the ASP.NET Web Form Designer. // InitializeComponent(); base.OnInit(e); } /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.Load += new System.EventHandler(this.Page_Load); } #endregion } } ************ |
|
#2
|
|||
|
|||
|
Did you find the solution?
Hello Gopals,
I am trying to do the same thing, and the event doesn't fire, I dont understand why. I will really appreciate if you can share the solution if you found one? Thanks in advance. HAdecco. Quote:
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > .NET Development > Dynamic Dropdown within Datagrid |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|