Click here to Skip to main content
15,922,145 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have two DropDownList in my page and AutoPostBack property is true. But when I am clicking any DropDownList and changing it's index it;s working good. Then when I am clicking another DropDownList than its not working. Can you tell me how it will work every time after PostBack?

C#
protected void drpFrom_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (IsPostBack)
            {
                drpTo.Items.Clear();
                int year = Convert.ToInt16(drpFrom.SelectedItem.Value.ToString());
                for (int i = 0; i < 2; i++)
                {
                    drpTo.Items.Insert(i, (year + 1).ToString());
                    year += 1;
                }
            }
        }

 protected void drpUniversity_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (IsPostBack)
            {
                if (drpUniversity.SelectedItem.Value.ToString() == "Others".ToString())
                {
                    int rowcount = mytable.Rows.Count;
                    HtmlTableRow row = new HtmlTableRow();
                    row.ID = "tbl_row" + (rowcount + 1);
                    HtmlTableCell cell1 = new HtmlTableCell();
                    cell1.ID = "tbl_cell1" + (rowcount + 1);
                    HtmlTableCell cell2 = new HtmlTableCell();
                    cell2.ID = "tbl_cell2" + (rowcount + 1);
                    cell1.Attributes["class"] = "contact";
                    cell2.Attributes["class"] = "contact";
                    TextBox tb = new TextBox();
                    tb.ID = "tbQty" + (rowcount + 1);
                    tb.Width = 276;
                    Label lblotherUniver = new Label();
                    lblotherUniver.ID = "lbluniversity";
                    lblotherUniver.Text = "University Name";
                    cell2.Controls.Add(lblotherUniver);
                    cell1.Controls.Add(tb);
                    row.Cells.Add(cell2);
                    row.Cells.Add(cell1);
                    mytable.Rows.Insert(8, row);
                    mytable.DataBind();
                }
            }
        }

In the second dropdownlist I have add a new TextBox. How can I get value from this textbox too?
Posted
Updated 13-Feb-13 8:38am
v2
Comments
[no name] 13-Feb-13 6:16am    
Remove ispostback from your code and try
Karthik Harve 13-Feb-13 7:01am    
Still confusion is that, which dropdownlist not firing event, drpFrom, drpTo or drpUniversity ?
Bandi Ramesh 13-Feb-13 22:09pm    
better your post your complete code so that we can understand

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900