I have a dropdownlist on a page for which I want to set a text so that whether or not user makes any selection, it should always be displayed to the user and not the selected value.
For example:
Here Select Language should always be visible to user even if I select any value from the list i.e. Option 1 or Option 2.
I guess it is more of a CSS task which I am not very much comfortable with.
If you are talking about a simple asp:DropDownList, you just need to insert an item in it, with an index value of 0 (to deal with server-side checks).
myDropDownList.Items.Insert(0, "Select");
dropdownlist1.Text="SomeText";
Dropdownlist need to have the data-source.
Here Select Language should always be visible to user even if I select
any value from the list i.e. Option 1 or Option 2.
Solution:
if your dropdownlist isn't autopost back enabled then
Maintain a hidden field where on change event of the dropdownlist place the selected value or selected index or selected text there in the hidden field to remember the selection.
lets says the id of your dropdownlist is sel and hidden field is hdSel, the jquery code for that look likes below
$('#sel').change(function(){
var val = $("#sel option:selected").text();
$('#hdSel').val(val);
$("#sel").prop('selectedIndex', 0);
}
);
example on Jsfiddle for your understanding
If your dropdownlist is autopostback enable then you can assign the selected value or selected text or selected index of the dropdownlist to the hidden field and reselect the first item again
Hope this help
Related
I have a gridview with radio buttons to select a single row.
The gridview is populated from a SQL DB according to a value selected from a drop down list.
What I want to do is keep the selected radio button when the user moves to a different category, so if he wants to move back via the DDL the value he selected previously is still selected.
What is the best way to do this?
The application will have users and I have read sessions could help me with this but I have no idea how it works!
Thanks in advance
I'm not sure really why you'd want to do it this way but you'd then save it in session this way:
String selectedValue = rblYourRadioButtons.SelectedValue;
Session["SelectedRadioButtonValue"] = selectedValue;
Then, on postback or whenever, on the Item Databound of the gridview you check if the current row Id matches the value stored in the session, if it does then select that value in the radiobutton list.
Personally I'd store the value in the DB rather than session.
I have a drop down with yes/no as data inside a rad grid. When the value of dropdown in row is changed, values of dropdown in other rows excluding this should be set with second item. This must be done with javascript.
You could open this link.
In addition, I would suggest you changing this line:
GridEditFormItem item = DropDownList1.NamingContainer as GridEditFormItem;
to
GridEditableItem item = DropDownList1.NamingContainer as GridEditableItem;
in order to support both edit and insert scenario.
it would require 2 steps
right click on the dropdown a pop up will appear then check the postback option
after that simply double click on the dropdownlist as a result function will get created in your filename.cs file now put the code for adding the option for the other dropdown list there and u r done
In my form there are two DropDownList controls.
1st is enabled and 2nd is disabled.
After selecting 1st dropdown I am changing selected value of 2nd dropdown using javascript.
Its working fine. But when I am trying to get selected value of 2nd dropdown, it will return value of first element (i.e. 'select').
Please refer my code
<asp:DropDownList ID="ddlStartTime1" runat="server" AutoPostBack="false"
Width="70" Enabled="false"></asp:DropDownList>
NOTE: I am using javascript to change selected value of 2nd(disabled) dropdown.
Javascript code:
$(document).ready(function() {
$('#<%= ddlStartTime1.ClientID %>').change(function() {
$('#<%= ddlEndTime1.ClientID %>').val($('#<%= ddlStartTime1.ClientID%>').val());
})
});
Is there any alternate way to get changed value of disabled DropDownList?
If you are trying to read the value of 2nd dropdown (disabled one) at server, you will never be able to read the updated value, becuase data in disabled controls will not be posted back to server from client.
You should either enable the dropdown before posting your data to server or use hidden controls to hold data of your disabled dropdown.
You would need to add another input that is hidden. Whenever you change the value of your 1st DropDownList, you'd change the value of your 2nd DropDownList AND the value of the hidden input.
Server-side, you're not looking at the value of the 2nd DropDownList, but at the value of your hidden input. Make sure the hidden value is always sync with the 2nd DDL when you post your form.
Just Add disabled dropdownlist's value in hidden field on change then read value from hidden field rather than dropdownlist.may be this will help you.
I have 2 datasets. 1 is assigned to dropdown and the other is assigned to repeater. If we select value from drop down, then values in repeater should be populated according to that value.
Initially I have assigned dataview to dropdown:
DataView dw = DataAccess.GetFirmID().Tables[0].DefaultView;
distinctDataTable = dw.ToTable(true, "FirmID");
ddlFirms.DataSource = distinctDataTable;
ddlFirms.DataValueField = "FirmID";
ddlFirms.DataBind();
In repeater:
LinkRepeater.DataSource = DataAccess.GetFirmID();
LinkRepeater.DataBind();
My question: if i change the "FirmID" value, according to that repeater value shoud be populated. Please help me out!
My understanding of your problem is that you want to change the data in a ASP.NET repeater when a certain value is selected in the dropdown.
You should set the AutoPostBack property of the dropdownlist to "true". Then, when the index is changed by the user, the page will postback with the new selected index. You'll want to make sure that the repeater uses the selected item from the dropdownlist to choose what to propagate.
I Have a page where there are two Dropdownlist and both have the same data in it but when user selects the value in Dropdownlist1 ,same value should be selected automatically in Dropdownlist2?
Thanks
Smartdev
You can do that a couple of ways. If you're using the built in asp.net postback approach then you can set the value of the dropdown box server side.
If you're wanting to do this on the front end you can use jQuery (or standard Javascript) to set the selectedIndex of the second dropdown.
I assume that's the kind of answer you are after and not just for someone to write the code for you. :)
so in your code behind OnSelectedIndexChanged, you need to rebind both DropDownList1 and DropDownList2 to the same datasource.