Display Column information from database into my dropdown - c#

I am trying to display Column information from database into my dropdown. After selecting the item in the dropdown (1) the next dropdown (2) must show the list of items present in selected field..net

If you are using ASP.NET dropdownlist you can set autopostback to true and in the codebehind set the items in the second droplist.

Related

Set caption for dropdown list

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

could not load all results for selected value in asp.net

How to modify the items in listbox when it is databound.
suppose i have 1 listbox and 1 combobox.i want to display results in listbox only for the value selected in combobox and remove the other value in listbox in windows form in asp.net.
I think you should add an OnSelectedIndexChanged to your combobox and set AutoPostBack="True"
Then selecting an item should trigger a post back and call the method you set for the OnSelectedIndexChanged. There you can fill the ListBox with values and remove the selected item from the ListBox too.

Change value of same dropdown in other rows of radgrid when one dropdown value is changed

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

Converting a dropdown selection to a two digit number in ASP.net C#

I have a dropdown list which has items bound to it using sql datasource.
In the database i have the numeric values corresponding to each item.
Now there are many such dropdown list's and on selection of each item i want to form a 14 digit numeric code,which i need to use further for some more functionality.
How can i convert a selected item from a dropdownlist to a numeric digit??or how can i bind the items in the dropdownlist to a database having numeric value for each item?Please help.
E.g if i select 'WT' from dropdown list the corresponding value for it in the database table is 39 so on form submit i want '39' to be formed in codebehind. likewise on selection of all items from different dropdown list the digit formed using codebehind should be '15487523568955'
Ok while binding your dropdown list to the sql datasource, you have to make sure that you bind
dropdownlist.DataSource = <GetSQLDataSource>();
dropdownlistDataTextField="<textvalue>";
dropdownlistDataValueField="<numericID>";
dropdownlist.DataBind();
Then, the Textvalue will be displayed in hte dropdown list and then you can access the corresponding .
Explain your requirement in some more details and if possible also add the table fields which your displaying in the dropdown for more clearance.
If you have corresponding value for the each items in the dropdownlist then while bidning the dropdown bind both the corresponding value as well as well as items to the dropdown, so that u will get the selected item value.

Display selected row of Gridview data to next page in another Gridview?

How can I Display selected row of Gridview data to next page in another Gridview?
For example,
In listing page I want to select particular row and take that data to another page and display over there.
I have two grid view one in 1st page
and next one in 2nd page. Now when I
select a record in 1st page gridview,
than that record will display on 2nd
page gridview on submit button click
from 1st page.
Pass the key of the record via the querystring... and then in rowdatabound event, select the row when the data bound record matches the key in the QS.
For more protection, you can use session to store the variable.
Why not have 2 gridviews, one above the other? The top gridview could be made to only show 1 record which is set to the id of the 2nd gridviews selected item identifier in code. Then in 2nd gridview, have an empty selected item template so that the selected item only shows once for both gridviews. That way the 2nd gridview is free to page through the entire set whilst the first retains the selected item for display above?

Categories