Tab Index for ListItems in RadioButtonList - c#

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).

Related

Auto Select one item on Dropdownlist asp.net c#

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;

asp dropdown reload page when setting dropdown.selectedvalue

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.

Dropdownlist, postback on all selections

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?

DropDownList doesn't call SelectedIndexChanged?

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.

ASP.NET RequiredFieldValidator not working with DropDownList Firefox 6

Having an issue validating a dropdownlist with a requiredfieldvalidator in Firefox 6. The code I have works in all browsers, except Firefox 6.
Here is what happens, I select a value from the dropdownlist that is not the default value and click the button. An error message is returned, meaning validation failed even though I have selected a different field. If I do this again, and select the SAME value from the dropdownlist and click the button. No error message, it passes validation. This only fails the first time you select a value, and only in Firefox 6.
Another example, load up the page, select a value, select the same value again, click the button, and it passes. WTH?
<asp:dropdownlist id="ddlHour" cssclass="select select-small" runat="server">
<asp:listitem value="" text="" selected="true"></asp:listitem>
<asp:listitem value="1">1</asp:listitem>
<asp:listitem value="2">2</asp:listitem>
</asp:dropdownlist>
<asp:requiredfieldvalidator id="rfvHour" initialvalue="" controltovalidate="ddlHour" errormessage="Please select an hour" display="none" validationgroup="banquetForm" runat="server"/>
And I have a button with the same validation group later on in the form. Any help is appreciated, thanks.
Try using the following:
<asp:dropdownlist id="ddlHour" cssclass="select select-small" runat="server">
<asp:listitem value="0" Text="" selected="true"></asp:listitem>
<asp:listitem value="1">1</asp:listitem>
<asp:listitem value="2">2</asp:listitem>
</asp:dropdownlist>
<asp:RequiredFieldValidator ID="HourValidate" runat="server" ControlToValidate="ddlHour" ErrorMessage="Please select an hour" InitialValue="0"></asp:RequiredFieldValidator>
how to set required field validator with DropDownList
suppose you are having this items in your dropdownlist..
DropDownList1.Items.Add(new ListItem("--Select--","0"));
DropDownList1.Items.Add(new ListItem("Kaushal","1"));
DropDownList1.Items.Add(new ListItem("Naresh","2"));
DropDownList1.Items.Add(new ListItem("Pankaj", "3"));
Then -: set the requiredfieldvalidator's controltovalidate property to DropDownlist1 and set the InitialValue property of the requiredfieldvalidator to 0 as this will be the value for
--Select-- you can show above.
Correct me if I'm wrong, but I think you are using the wrong validator. By default, a dropdown always has a value, so making it required doesn't make sense. I think what you want to do is compare it, to make sure it's not the first choice. This page shows a quick demo of how to do that.
http://forums.asp.net/t/1188035.aspx/1

Categories

Resources