Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#2.0 C# ASP.NET C#4.0
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?
 
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 12-Feb-13 23:37pm
Edited 13-Feb-13 8:38am
34K
v2
Comments
CShubham at 13-Feb-13 6:16am
   
Remove ispostback from your code and try
Karthik Harve at 13-Feb-13 7:01am
   
Still confusion is that, which dropdownlist not firing event, drpFrom, drpTo or drpUniversity ?
bandi.ramesh at 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)

  Print Answers RSS
0 OriginalGriff 335
1 Sergey Alexandrovich Kryukov 150
2 ChauhanAjay 120
3 BotCar 105
4 Dave Kreskowiak 100
0 Sergey Alexandrovich Kryukov 9,056
1 OriginalGriff 7,981
2 CPallini 2,613
3 Richard MacCutchan 2,121
4 Abhinav S 1,928


Advertise | Privacy | Mobile
Web02 | 2.8.140827.1 | Last Updated 13 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100