DropdownList SelectedIndexChanged

I have a page that contains a Dropdownlist.  When the user selects an item  from the list it populates a datagrid based on the selection. The datagrid contatins three columns 1st onse is a label, the second one is a dropdownlis, and the thrid one is empty. Whe the datagrid is created, i use the OnItemDataBound to populate each dropdownlist in each row of the datagrid because the selections for each row are different.  If the use selects other from the dropdownlist in any row of the datagrid I was to make a textboxt in the third row for the user to enter data.  I can't seem to get the SelectedIndexChanged event to fire on the dropdownlist in the datagrid.

Any help would be apprectiated. If you want me to post the code please let me know.

thanks
nstlitAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
praneethaConnect With a Mentor Commented:
AutoPostBack="True" OnSelectedIndexChanged="SelectChanged"

and in codebehind

protected void SelectChanged(object sender, System.EventArgs e)
               {
               Response.Write("hello");
               }
0
 
praneethaCommented:
just make the autopostback=true and then and just attahc a selectindexchanged handler to it too
0
 
praneethaCommented:
make suremetod is protected or public but not private..or you can attach an event handler in itemdatabound..

and in that handler if u need to access the particular datagrid row

 protected void SelectChanged(object sender, System.EventArgs e)
               {

               DropDownList rbl=(DropDownList)sender;
               DataGridItem dgi=(DataGridItem)rbl.NamingContainer;
                       Response.Write(dgi.Cells[1].Text);
               }
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
nstlitAuthor Commented:
paraneetha

Here is what I have. When I select a dropdown it doesn't seem to fire the lstPvalue_SelectedIndexChanged event.  I had it just changeing the top lable to see if it was firing.  I was sure want to put in to add the txtbox to the datagrid.

      public class CreateItem : System.Web.UI.Page
      {
            protected System.Web.UI.WebControls.Label lblTop;
            protected System.Web.UI.WebControls.Label lblTopProp;
            protected System.Web.UI.WebControls.Label lblLoc;
            protected System.Web.UI.WebControls.Label lblName;
            protected System.Web.UI.WebControls.TextBox txtName;
            protected System.Web.UI.WebControls.Label lblDescr;
            protected System.Web.UI.WebControls.TextBox txtDescr;
            protected System.Web.UI.WebControls.Button cmdAdd;
            
            protected System.Web.UI.WebControls.DataGrid dgr_SubProp;
            protected System.Web.UI.WebControls.DropDownList lstType;

            private com.itmHandle itm = new com.itmHandle();
            private com.admin adm = new com.admin();
            private int itmID = 0;
      
            private void Page_Load(object sender, System.EventArgs e)
            {
                  if (!IsPostBack)
                  {
                        //get items types
                        DataSet ds = adm.getProperty();
                        if (ds.Tables[0].Rows.Count > 0)
                        {
                              lstType.DataSource = ds;
                              lstType.DataTextField = "Property";
                              lstType.DataValueField = "MID";
                              lstType.DataBind();
                              lstType.Items.Insert(0, new ListItem("--Select Type--", "0"));
                        }
                        ds.Dispose();
                  }
            }
            private void lstType_SelectedIndexChanged(object sender, System.EventArgs e)
            {
                  if (lstType.SelectedValue != "0")
                  {
                        
                              dgr_SubProp.DataSource = adm.getSubProperty(int.Parse(lstType.SelectedValue));
                              dgr_SubProp.DataBind();
                        
                  }
            }
            protected void Item_Created(Object sender, DataGridItemEventArgs e)

            {
                  if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem ))
                  {
                        int MID = int.Parse(dgr_SubProp.DataKeys[e.Item.ItemIndex].ToString());
                        DropDownList lsttemp;
                        DataSet ds = adm.getPvalues(MID);
                        if (ds.Tables[0].Rows.Count > 0)
                        {
                              lsttemp = (DropDownList) e.Item.FindControl("lstPvalue");
                        
                              lsttemp.DataSource = ds;
                              lsttemp.DataTextField = "Pvalue";
                              lsttemp.DataValueField = "AID";
                              lsttemp.DataBind();
                              lsttemp.AutoPostBack = true;
                              lsttemp.Items.Insert(0, new ListItem("--Select Type--", "0"));
                              lsttemp.Items.Insert(lsttemp.Items.Count, new ListItem("other", "other"));
                              lsttemp.SelectedIndexChanged += new System.EventHandler(this.lstPvalue_SelectedIndexChanged);
                              //e.Item.Cells[1].Controls.Add(lsttemp);
                              
                        }
                  }
            }
            private void lstPvalue_SelectedIndexChanged(object sender, System.EventArgs e)
            {
                  DropDownList temp;
                  temp = (DropDownList) sender;
                  
                  if (temp.SelectedValue == "other")
                  {
                  //Not sure what to put here.
                                                lblTop.Text = temp.SelectedValue;
                  }

            }
0
 
praneethaCommented:
 private void lstPvalue_SelectedIndexChanged(object sender, System.EventArgs e)
          {
               DropDownList temp;

try making it protected or public
0
 
nstlitAuthor Commented:
I tried making it both public and protected, and it still never seems to fire the event.
0
 
praneethaCommented:
did u try doing it in html view like i said...

0
 
nstlitAuthor Commented:
Sorry, I somehow missed the above post, or just read it too fast, It now works.  I will accept your above answer.
0
All Courses

From novice to tech pro — start learning today.