I'm wondering if it is possible, using an asp:dropdownlist if you can fire a postback on every selection, even if it is the same? For example:
<asp:DropDownList ID="DropDownList_SortCars" runat="server" OnSelectedIndexChanged="DropDownList_SortCars">
<asp:ListItem Value="0" Text="Volvo" ></asp:ListItem>
<asp:ListItem Value="1" Text="Saab"></asp:ListItem>
<asp:ListItem Value="2" Text="Audi"></asp:ListItem>
</asp:DropDownList>
So rather than having a 'OnSelectedindexChanged' event you would have a IndexSelected event. The reason? Well, if somebody selects a volvo, and this would be a list of models (or something), if they selected volvo again it would show the same list but in reverse order! At the moment I can only get the list to fire if they change an index.
So basically can you force a postback on selection, any selection?
Related
I have dropdownlist with list item of Yes and No. I want "No" will be displayed on the page but the Selected="true" on the ListItem is not working.
<asp:DropDownList ID="ddlIsDistributor" runat="server">
<asp:ListItem Value="1" Text="Yes">Yes</asp:ListItem>
<asp:ListItem Value="0" Text="No" Selected="True">No</asp:ListItem>
</asp:DropDownList>
Invoke this bit of code in your page load event so it selects the desired value from the dropdown when loading: ddlIsDistributor.SelectedIndex = 0;
I have an ASP.net dropdownlist with four items,
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem Selected="True" Value="0">Select Payment Method</asp:ListItem>
<asp:ListItem>Credit Card</asp:ListItem>
<asp:ListItem>PayPal</asp:ListItem>
<asp:ListItem>WeKea Store Gift Card</asp:ListItem>
</asp:DropDownList>
Is there a way to make "Select Payment Method" not selectable? I read through all the properties of an ASP.net DDL and I dont see anything of the sort.
You can use the disabled attribute (see here) and apply it to the ListItem:
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem Selected="True" Value="0" disabled="disabled">Select Payment Method</asp:ListItem>
<asp:ListItem>Credit Card</asp:ListItem>
<asp:ListItem>PayPal</asp:ListItem>
<asp:ListItem>WeKea Store Gift Card</asp:ListItem>
</asp:DropDownList>
This will render the option as greyed out and it will not be selectable. However, the selected=True will override that and it will be displayed as selected when the page loads, which I think is what you want.
I have the following asp dropdown:
<asp:DropDownList ID="ArticleCategories" runat="server" AppendDataBoundItems="true" CssClass="ArticleCategoriesDropDown" onselectedindexchanged="mCategoryItemSelected" AutoPostBack="True">
<asp:ListItem Text="Select Category" Value="" />
</asp:DropDownList>
Once a selection has been made, and the data loaded, I want to set the value in the dropdown to display the value chosen by the user.
I am doing this by:
ArticleCategories.SelectedValue = CategoryID.ToString();
This works fine the first time, but from then the page is stuck on that selection, as the selected value gets loaded before the new value can load.
I have tried disabling the itemchangelistener by:
ArticleCategories.SelectedIndexChanged += new EventHandler(doNothing);
But that does not work.
I have also tried to disable postback which also does not work.
Any ideas?
You should only set the selection when loading the page the first time. In ASP.NET, you can achieve this by checking the IsPostBack property:
if(!IsPostBack)
{
ArticleCategories.SelectedValue = CategoryID.ToString();
}
You can do Autopostback= false
<asp:DropDownList ID="ArticleCategories" runat="server" AppendDataBoundItems="true" CssClass="ArticleCategoriesDropDown" onselectedindexchanged="mCategoryItemSelected" AutoPostBack="False">
<asp:ListItem Text="Select Category" Value="" />
</asp:DropDownList>
Hey before selecting another item from Dropdown you should clear previous selection then selected another one.
ArticleCategories.ClearSelection();
Hope it helps you.
Is it possible to set Tab Index for ListItems in RadioButtonList. Here is my code:
<asp:RadioButtonList ID="radGender" runat="server">
<asp:ListItem Value="M">Male</asp:ListItem>
<asp:ListItem Value="F">Female</asp:ListItem>
<asp:ListItem Value="U">Not Specified</asp:ListItem>
</asp:RadioButtonList>
Thanks,
Praveen
ASP.Net Cannot tab through all radio buttons when selected
Similar problem to yours. This should help with what you need as well as solve the problem you run into after having a radio buttom selected.
EDIT
Just to specify their solution. It seems after a choice is selected, using the arrow keys will let you move to the other choices where as tab will not. Another solution to getting around this is to have individual radio buttons and group them using the group name property.
What's wrong with?
<asp:RadioButtonList ID="radGender" runat="server">
<asp:ListItem Value="M" tabindex="1">Male</asp:ListItem>
<asp:ListItem Value="F" tabindex="2">Female</asp:ListItem>
<asp:ListItem Value="U" tabindex="3">Not Specified</asp:ListItem>
</asp:RadioButtonList>
Seem to work at least in IE9 and FF (not sure with others).
I have 7 items in my dropdown list like
<asp:DropDownList ID="DdlSortBy" runat="server" OnSelectedIndexChanged="DdlSortBy_SelectedIndexChanged"
AutoPostBack="True">
<asp:ListItem Value="0">Case 1</asp:ListItem>
<asp:ListItem Value="1">Case 2</asp:ListItem>
<asp:ListItem Value="2">Case 3</asp:ListItem>
<asp:ListItem Value="3">Case 4</asp:ListItem>
<asp:ListItem Value="4">Case 5</asp:ListItem>
<asp:ListItem Value="5">Case 6</asp:ListItem>
<asp:ListItem Value="6">Case 7</asp:ListItem>
</asp:DropDownList>
all items except Case 1 value 0 initiate selected index change event.
Any idea how to fix it?
If it is working for one then it should be working for each of them; an instance in which it won't postback upon selection would be if that item was already selected, say, by default - then you would need to select something else, then re-select said "default" value.
Otherwise, I can't see that any single item would be discriminated against.
The reason might be that the first item is selected by default. What you could try is to add a new item and set it to be the first:
<asp:ListItem Value="-1">please select</asp:ListItem>
That way, when you select Case 1, it will fire the event.