Click here to Skip to main content
16,022,399 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have binded my drop down here is my code
C#
public void FillDll()
    {
        if (!Page.IsPostBack)
        {
            DataTable droomtype = (DataTable)ViewState["GridView"];
            if (droomtype.Rows[0]["Single"].ToString() != "")
                DdlRoomType.Items.Add(new ListItem("Single", droomtype.Rows[0]["Single"].ToString()));
            if (droomtype.Rows[0]["Double"].ToString() != "")
                DdlRoomType.Items.Add(new ListItem("Double", droomtype.Rows[0]["Double"].ToString()));
            if (droomtype.Rows[0]["Triple"].ToString() != "")
                DdlRoomType.Items.Add(new ListItem("Triple", droomtype.Rows[0]["Triple"].ToString()));
            if (droomtype.Rows[0]["Quad"].ToString() != "")
                DdlRoomType.Items.Add(new ListItem("Quad", droomtype.Rows[0]["Quad"].ToString()));
            if (droomtype.Rows[0]["Twin"].ToString() != "")
                DdlRoomType.Items.Add(new ListItem("Twin", droomtype.Rows[0]["Twin"].ToString()));
            //DdlRoomType.Attributes.Add("onChange", "getDropDownListvalue('" + dp.ClientID + "','" + lblprice2.ClientID + "')");
            //DdlRoomType.Attributes.Add("onChange", "getDropDownListvalue('" + DdlRoomType.ClientID + "','" + lbl_asianprice.ClientID + "')");
            //DdlRoomType.Items.Insert(0, "---Select One---");
            //DdlRoomType.SelectedIndex = 0;
            //DdlRoomType.Attributes.Add("onChange", "getDropDownListvalue('" + DdlRoomType.ClientID + "')");
        }
    }

i have enabled its autopost property true because on indexchange i want to bind a price with label i m getting a problem when i select any of the item the label is binded but again by default 1st is being selected i dont know where i have done mistake kindly help me out
Posted

1 solution

In your code, you are checking if the page is not a postback. If its not a postback, it will execute the code in the if statement.

Therefore, if you're calling the above method after the selected index change, make sure to remove the if condition. See http://msdn.microsoft.com/en-us/library/system.web.ui.page.ispostback.aspx

After the binding, I would suggest to set the selected index to -1 in order not to have any item selected.
 
Share this answer
 

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