I have this database bound dropdownlist in an ajax enabled web page, precisely using an update panel, but the problem is that after the dropdownlist is populated and you select an item, it will not select that item, but it will select another item in the
same list, the dropdownlist has autopostback set as true. Please what could be the cause of this?
If you have the UpdatePanel set to update when children fire events, only the UpdatePanel should refresh, not the entire page. The code below seems to behave similar to what you are seeking. When changing the drop down, only the update panel posts back
to the server and when you refresh the page, you can get the value out of the session.
timotech
Member
11 Points
60 Posts
Problem with dropdownlist selection
Feb 28, 2013 11:26 AM|LINK
Hi All,
I have this database bound dropdownlist in an ajax enabled web page, precisely using an update panel, but the problem is that after the dropdownlist is populated and you select an item, it will not select that item, but it will select another item in the same list, the dropdownlist has autopostback set as true. Please what could be the cause of this?
Thanks
Tim
me_ritz
Star
9337 Points
1447 Posts
Re: Problem with dropdownlist selection
Feb 28, 2013 11:36 AM|LINK
How are you binding dropdownlist?
If it is in code-behind and on page load then make sure it is inside ...
if(!IsPostBack) { //DataBind Code Here }Nileshwar
Member
33 Points
17 Posts
Re: Problem with dropdownlist selection
Feb 28, 2013 11:39 AM|LINK
DropDownList1.DataSource = Dataset or DataTable;
DropDownList1.DataValueField =anyColoumnName1; //in Dataset or DataTable
DropDownList1.DataTextField =anyColoumnName2; //in Dataset or DataTable
try this
timotech
Member
11 Points
60 Posts
Re: Problem with dropdownlist selection
Feb 28, 2013 11:41 AM|LINK
Thanks me_ritz,
its already wrapped in a if not page.ispostback block
timotech
Member
11 Points
60 Posts
Re: Problem with dropdownlist selection
Feb 28, 2013 11:42 AM|LINK
Thanks Nileshwar,
Ok, i'll try using a datatable instead of using a datareader to get the list.
Pengzhen Son...
Star
8189 Points
842 Posts
Microsoft
Re: Problem with dropdownlist selection
Mar 01, 2013 05:25 AM|LINK
Hi,
If you have the UpdatePanel set to update when children fire events, only the UpdatePanel should refresh, not the entire page. The code below seems to behave similar to what you are seeking. When changing the drop down, only the update panel posts back to the server and when you refresh the page, you can get the value out of the session.
form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <div> Current Time: <asp:Label ID="lblTime" runat="server" /><br /> Session Value: <asp:Label ID="lblSessionValue" runat="server" /><br /> <br /> <asp:UpdatePanel ID="upSetSession" runat="server"> <ContentTemplate> <asp:DropDownList ID="ddlMyList" runat="server" onselectedindexchanged="ddlMyList_SelectedIndexChanged" AutoPostBack="true"> <asp:ListItem>Select One</asp:ListItem> <asp:ListItem>Maybe</asp:ListItem> <asp:ListItem>Yes</asp:ListItem> </asp:DropDownList> </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="ddlMyList" EventName="SelectedIndexChanged" /> </Triggers> </asp:UpdatePanel> </div> </form>protected void Page_Load(object sender, EventArgs e) { this.lblTime.Text = DateTime.Now.ToShortTimeString(); if (Session["MyValue"] != null) this.lblSessionValue.Text = Session["MyValue"].ToString(); } protected void ddlMyList_SelectedIndexChanged(object sender, EventArgs e) { Session.Remove("MyValue"); Session.Add("MyValue", this.ddlMyList.SelectedValue); }Please refer here
http://stackoverflow.com/questions/6772403/dropdownlist-and-update-panel
http://stackoverflow.com/questions/1256943/dropdownlist-in-updatepanel
http://forums.asp.net/t/1354779.aspx/1
Hope it can help you.
Feedback to us
Develop and promote your apps in Windows Store
timotech
Member
11 Points
60 Posts
Re: Problem with dropdownlist selection
Mar 01, 2013 10:26 AM|LINK
Well, i have resorted to using a datatable which works ok for me, but i will explore your suggestion.
Thanks
Tim