Bind the Drop Down to display the selected value on bind - asp.net

let's say I have 2 drop down's and one displays the States list and another Occupation. Both are independent in this scenario.
On the database side, I've a user profile record with fields that saves "state_code" and "Occupation_desc"
The table that saves the state details will have two fields: state_desciption, state_code
The table that saves the state details will have two fields: Occupation_desc, id
When loading the profile, On binding the drop down control, I need to show the state name rather than the short-cut(I need to show California rather than "CA",
but db record will have "CA".)
sample code:
drpdwnstates.DataSource = //binding the results
Me.drpdwnstates.DataTextField = "state_desciption"
Me.drpdwnstates.DataValueField = "state_code"
Me.drpdwnstates.DataBind()
For example, if i'm loading a user profile from California, then i need to highlight/select the California in my dropdown.
Contract to this, other drop down will have the Occupation list need to show the description itself(description itself is saved in the user profile record, not id).
Any help on how to select the saved value on the load??

You can select an item by setting the selected value of the DropDownList:
drpdwnstates.SelectedValue = "CA";
If the state code is saved in the user profile, you may set the value this way:
drpdwnstates.SelectedValue = userProfile.StateCode;
You can adapt this code to the specific data structure of your user profiles.

Related

Select field from SQL Datasource in Google App Maker based on drop down value

I am running into an issue where I have 3 SQL Datasources (Employee, Course, Overview).
I have created a page inherited from the Overview Datasource, where i have created a drop down (options based on the Employee Datasource Employee.items.Name._equals, value set to Overview.Item.Name). When i select his name in the drop down, I want to dynamically fill in a text field where it selects the email field from the Employee Datasource based on the person selection in the drop-down.
Is this possible? If so, how do I proceed? If further information is required please feel free to ask.
Based on your comment change the following items around.
Overview Datasource dropdown options:
#datasources.Employee.items
Leave your dropdown value the same for now.
Dropdown onValueChange event:
widget.root.descendants.EmailTextBox.value = newValue.Email;
Observe that the newValue is a built in variable in the widgets API for a dropdown and points to an object of the options datasource, therefore, if your options are #datasources.Employee.items the options are an array of objects that make up all the Employee items and when selecting one option it points to items[index] and then you are able to call your object at index with the name of your object item. So newValue.Email should get the selected Employee email.

show different label and values for columns in cognos report studio

I have a column "full name" in a list and I want to configure drill down for it so that when I click on a particular user's full name, it displays all the bio data of that user from another table.
My requirement is that at the front end, it should show the full names of the users, but when I click on the user's name, it should pass E-mail address of the user for the drill down.
Please need help for doing it.
I'm going to assume you are using a list object. the instructions for a crosstab would be slightly different:
Add the item you want to pass to the drill-through target to your query
In the report page, select the list
Click on the ellipses (...) in the 'Properties' property of the list object
Check the box next to the data item that you added to the query in step 1 and click 'OK'
When you define the drill-through parameters, select 'Pass the data item value' for the method and the data item added to the query in step 1 as the Value.

Foxpro combobox binding from database

I have Form1. I have table "Category", now I want to display all CategoryName in to combobox cbbCategory in Form1, the category names data are retrieved from Category table, how can I do this?
There are several ways you can do this, from querying the table into an array, writing as a SQL query, etc and setting up the properties.
What I would suggest for a start is this. Open your form.
Right-click anywhere in the form and pick "Data Environment".
If the category table is NOT already shown in the window, right-click and select Add. It will prompt you to pick a table and select your category table. Then close the data environment.
Now, put a combobox on your form if you have not done so already.
Right-click on the combobox and click "Builder". It will walk you through the selection process to get what you want. Start with picking the table... your category table. Then it has picker next to it to identify which column(s) you want to be displayed in the combobox. If your category table has both an ID and a description, I would pick your description FIRST, then the internal ID column second (so we can hide the second column if you dont want to actually show it).
Click on the second tab for "Style", and to clarify the difference between a "Drop-down Combo" vs "Drop-down List" is that a combo will default show you available choices, but if one is not available, allows a user to manually enter a new one which you might want to allow adding to your master category lookup table. "Drop-down List" is fixed to only allow the user to pick an entry from those available and nothing else.
Next, click on the Layout tab. This allows you to adjust the columns widths to see/hide what it will look like during drop-down mode (just stretch/shrink the columns)
Finally, the "Value" tab. It is asking for which column from those you selected to be available do you want to store behind-the-scenes. If an ID column, so be it... if the description, that's fine too. You can leave the last "Field Name" blank for now and it will just store whatever is selected into the comboboxes "Value" property... from which you can do whatever you need to in next phase of you app.

link two fields select type symfony2

i work with Symfony2 and I want to see how I can use Form Events to link two fields select type.
The first field contains the cities and the second contains the country.
here is my entities:
user
- id
- name
- IdCity
city
- id
- CityName
- IdCountry
country
- id
- countryName
And thank you.
Solution #1
( working without javascript , enhanced with javascript, no reload required, small city amounts )
Create one select field of entity field-type displaying all cities and use group_by to group by country.
hide your single grouped select field with javascript ( type="hidden" )
split the select fields with JavaScript into a country field for the groups and add a second one for cities
change the city field if the country fires onchange event
change the hidden field if the city field fires onchange event
This way you are saving the code necessary to create a second form, inject your current country, filter with a second queryBuilder ... If you do have a lot of cities ( even with a cached result you are outputing too many )... go for solution #2.
Solution #2
( huge amount of cities, therefore loading cities filtered by country selection required )
create a form with an entity field type for the countries
pass the currently selected country into your form - default to null ( i.e. from your action or inject the request and read it from there)
create a subform of entity field type for the cities
if the selected country read from request is null - don't add the subform to the builder
if present -> add the subform and use the queryBuilder city field-type to filter the cities by country
enhance by AJAX-loading the subform on country-select
Hope you get the idea :)

GridView Initial Editing mode?

I am writing a web application that is used for tracking and entering some everyday user data... Every day I need to enter some data for multiple users manually...
I will choose the date with the calendar, and for that date I will get DB values assigned for all users on chosen date...If there are some entries in database for that date i will display it in gridview...
Here is the look of gridview for chosen date...
USERS DATA
------------
User1 Data1
User2 Data2
User3 Data3
But, if I choose the date for which there are no entries in DB, I would like to display the gridview containg User names in each row, but I want the second column (DATA field) to be initially editable for ALL rows (the whole second column should contain textboxes for inserting values, not only selected row as in standard editable gridview mode) allowing inserting of wanted values...
I want it to look something like this
USERS DATA
----------------
User1 TextBox
User2 TextBox
User3 TextBox
My idea is to get Users list from DB and create a datatable with first column containg returned user names, and second column empty... This datatable will be datasource for gridview in which I am going to disable editing mode, and in normal (displaying) mode I am going to have TemplateField containg of textboxes bound to that datatable in second column, and labels displaying usernames in first column... When entering all values there will be SAVE button who is calling a method that will read entered values from datatable and save it to database...
Is there a better way to implement this functionality? If Templatefield textboxes are bound to datatable (as gridview datasource) textboxes entered values are going to be accessible from datable object, but Save button click causes postback, and I don't know how to preserve datatable state? Is there a better way to get wanted gridview with whole second column availibe for inserting new values?
Thank you in advance for your help & time!
Try this
http://www.highoncoding.com/Articles/219_GridView_All_Rows_in_Edit_Mode.aspx
http://csharpdotnetfreak.blogspot.com/2009/05/edit-multiple-records-gridview-checkbox.html
I would retrieve the full dataset using a left join in the database, and if there is no entry for a user, that user will be returned with a blank value. Something like this:
select users.user,
isnull(entries.entry,'')
from users
left join entries on users.userid = entries.userid
I think you can override the OnDataBinding (or OnDataBound) method to check and see if the second column is empty, and place the field in edit mode if it is. This way, if some users have entries but some don't, only the users with no entry will be in edit mode. Any user with an entry will be in display mode. There is a sample for this at http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.onrowdatabound.aspx.

Resources