473,386 Members | 1,821 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

ASP DropdownListBox Default not working

Hi

I have a DDLB in a gridview that allows record entry. The default is set by the QueryString. Here is the code:

Expand|Select|Wrap|Line Numbers
  1.                 <FooterTemplate>
  2.                     <asp:DropDownList ID="MenuInsert" runat="server" OnDataBound="test">
  3.                         <asp:ListItem Text="" Value=""></asp:ListItem>
  4.                         <asp:ListItem Text="Top Menu" Value="Top Menu" Selected="<%if(1==1){Response.Write('True')}else{Response.Write('False')};%>"></asp:ListItem>
  5.                         <asp:ListItem Text="Side Menu" Value="Side Menu" Selected="<%if(1==2){Response.Write('True')}else{Response.Write('False')};%>"></asp:ListItem>
  6.                     </asp:DropDownList>
  7.                     <asp:RequiredFieldValidator ID="valMenuInsert" runat="server" Display="Dynamic" ControlToValidate="MenuInsert" ErrorMessage="NB!" ValidationGroup="valInsert"></asp:RequiredFieldValidator>
  8.                 </FooterTemplate>
  9.  
This gives me the error:
System.Web.HttpException: Cannot have multiple items selected in a DropDownList.

Previously, I had tried:
Expand|Select|Wrap|Line Numbers
  1.     protected void Page_Load(object sender, EventArgs e)
  2.     {
  3.         DropDownList MenuInsert = MyGridView.FooterRow.FindControl("MenuInsert") as DropDownList;
  4.         MenuInsert.SelectedValue = Server.UrlDecode(Request.QueryString["Menu"]);
  5.     }
  6.  
That sort of worked. On a fresh load, it set the default. But after editing/deleting/inserting a record in the grid, ie. after postback, then it remained blank, wasn't set.

any help why/how?
May 25 '08 #1
1 1314
nateraaaa
663 Expert 512MB
Hi

I have a DDLB in a gridview that allows record entry. The default is set by the QueryString. Here is the code:

Expand|Select|Wrap|Line Numbers
  1.  <FooterTemplate>
  2. <asp:DropDownList ID="MenuInsert" runat="server" OnDataBound="test">
  3. <asp:ListItem Text="" Value=""></asp:ListItem>
  4. <asp:ListItem Text="Top Menu" Value="Top Menu" Selected="<%if(1==1){Response.Write('True')}else{Response.Write('False')};%>"></asp:ListItem>
  5. <asp:ListItem Text="Side Menu" Value="Side Menu" Selected="<%if(1==2){Response.Write('True')}else{Response.Write('False')};%>"></asp:ListItem>
  6. </asp:DropDownList>
  7. <asp:RequiredFieldValidator ID="valMenuInsert" runat="server" Display="Dynamic" ControlToValidate="MenuInsert" ErrorMessage="NB!" ValidationGroup="valInsert"></asp:RequiredFieldValidator>
  8. </FooterTemplate>
  9.  
This gives me the error:
System.Web.HttpException: Cannot have multiple items selected in a DropDownList.

Previously, I had tried:
Expand|Select|Wrap|Line Numbers
  1.  protected void Page_Load(object sender, EventArgs e)
  2. {
  3. DropDownList MenuInsert = MyGridView.FooterRow.FindControl("MenuInsert") as DropDownList;
  4. MenuInsert.SelectedValue = Server.UrlDecode(Request.QueryString["Menu"]);
  5. }
  6.  
That sort of worked. On a fresh load, it set the default. But after editing/deleting/inserting a record in the grid, ie. after postback, then it remained blank, wasn't set.

any help why/how?
In your page_load event use the code you already tried but put that code inside of a !IsPostBack conditional statement.
Expand|Select|Wrap|Line Numbers
  1.  protected void Page_Load(object sender, EventArgs e)
  2. {
  3. if(!IsPostBack)
  4. {
  5. DropDownList MenuInsert = MyGridView.FooterRow.FindControl("MenuInsert") as DropDownList;
  6. MenuInsert.SelectedValue = Server.UrlDecode(Request.QueryString["Menu"]);
  7. }
  8. }
  9.  
Nathan
May 27 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Max | last post by:
Have a DropDownListBox where I want to give users the option to select one of the values, but allow them to enter a freeform text value if they choose to do so in lieu of the proffered values. Kind...
7
by: Eduardo M?ndez | last post by:
Hello: I have an aspx page with a TextBox and a DropDownListBox both have Autopostback property set to true and some code in the TextChanged and SelectedIndexChanged events. When text in...
2
by: kgs | last post by:
I dynamically added a DropDownListBox to a footer of datagrid on itemcreated event. In which event in postback can i access the selected item. Interesting thing i noted that even though i create...
4
by: | last post by:
I think we have some bug in dropdownlistbox server control. Following are the values. <asp:DropDownList id="DropDownList1" runat="server"> <asp:ListItem value="46">INR</asp:ListItem>...
1
by: pari kanaga | last post by:
I have server control dropdownlistbox populated with data from table. I don't know how to make this dropdownlistbox searchable. ( for example if i click the dropdownlistbox and type the name it...
1
by: raj | last post by:
hello i want to set the tooltip of data displaying in dropdownlistbox , i have bound the dropdownlistbox with datasource and i want that tooltip shld be display at every item of dropdownlistbox...
2
by: Kenichi666 | last post by:
I am new to ASP.NET and C#. I have populate a dropdownlistbox from a sqltable. I would like to set the selected value in the dropdownlistbox to an sql UPDATE command. like fx. "UPDATE name =...
1
by: jeyapriya | last post by:
Dear Friends This is Jeyapriya. Right now I am working in the ASP.NET with VB coding & the back end is SQL SERVER 2000. My dilemma is I have to design a form with 2 DropDownListboxes. I have...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.