I'm using a dropdownlistfor that populates some data from the database, the idea is that i want that the default value of the dropdown, has to be editable.
So the user can submit one of the options that are populated from the database, or the default one modified
How can i make this?
You could use an onclick event on the first value that triggers a jquery pop-up with a textfield which could rewrite your first value of the dropdown on submit.
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.
There are two Comboboxs, one button, and a GridView in a page.
When I click the button, the selected items of the Comboboxs should be inserted to the GridView and at the same time updated in database.
When I click the button it should not perform a postback. Users should be able to add lots ot records when hitting the submit button.
Here is what you need to do:
Set a script function call in OnClientClick and return false from this method.
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.button.onclientclick.aspx
In this client method use JQuery AJAX to call a web method to update the db.
http://encosia.com/using-jquery-to-directly-call-aspnet-ajax-page-methods/
Add a row to the table with jquery methods that manipulate DOM.
Add table row in jQuery
Of course you can use an UpdatePanel but you have to insert the combo and the grid inside, so this is not going to save you server CPU and traffic.
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've got a bit of an chicken and an egg.
I need to bind a gridview to a set of database values. The gridview is dynamic and the columns, cells are created at run time.
As such, I need to re-bind the grid on every postback in the pre-init, init events after very post back.
However, the data used to populate the grid uses a value from a dropdown box on the same page. As such, the value of dropdown is not accessible through viewstate until after the init event (i.e. the selected index is always the first item in the list until after on init).
How can I get access to the value of the drop down in time to rebind the grid before the pageload event?
If the Gridview always has the same number of columns, you could have the dynamic query generate column names as aliases, and then just rebind the Gridview on dropdown change?
you can use and HtmlHidden control for store the value you need. It doesn't depend by the viewstate and it's available into the page init
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.