'Not selected' property value on drop down box selected value - asp.net

I have an ASP.NET site (either .NET 2.0 or 3.5), and I want to get the selected item of two drop down boxes (call them a and b). B is updated with appropriate values depending on what is selected for A.
However, the following code:
string val = dd1.SelectedItem.Text;
Returns a value of "not selected". Why is this?
Thanks

The only way this could happen is if you have "not selected" set as either the Text property of your selected item, or if Text is null then the Value property will be returned.
From MSDN's documentation on ListItem (which is what SelectedItem inherits from):
If the Text property contains null,
the get accessor returns the value of
the Value property. If the Value
property, in turn, contains null,
String.Empty is returned.

Related

Dynamic Dropdown issue

Hello I am trying to implement a drop down in asp.net. The drop down is being loaded from database and is being binded with drop down. The list has various values and text. But I want to add the first option of "Please Select" which is disabled for selection at the top of drop down list. Also on binding the drop down I want to point to the value which user had previously selected so that's why I am using selectedValue option. the problem is if I add the first item as "please select" from code behind at item 0 and selectedvalue to the value stored in db it still shows me item zero" please select".
DropDownList ddlMinEdit = (DropDownList)currentGrid.Rows
[currentGrid.EditIndex].FindControl("ddlMinEdit");
ddlMinEdit.Items.Insert(0, "Select Please");
ddlMinEdit.Items [0].Attributes.Add("disabled", "disabled");
ddlMinEdit.DataSource = CList;
ddlMinEdit.DataTextField = "empid";
ddlMinEdit.DataValueField = "empname";
ddlMinEdit.DataBind();
ddlMinEdit.SelectedValue = defemp;
So any suggestion how do I add first item and at same time bind a list and point to selected value. thanks
The order that you are doing things doesn't seems correct. You should insert the "Select Please" after the data binding and setting the selected value:
DropDownList ddlMRCClinEdit = (DropDownList)currentGrid.Rows [currentGrid.EditIndex].FindControl("ddlMRCClinEdit");
ddlMRCClinEdit.DataSource = clinList;
ddlMRCClinEdit.DataTextField = "empid";
ddlMRCClinEdit.DataValueField = "empname";
ddlMRCClinEdit.DataBind();
ddlMRCClinEdit.SelectedValue = defemp;
ddlMRCClinEdit.Items.Insert(0, "Select Please");
ddlMRCClinEdit.Items [0].Attributes.Add("disabled", "disabled");

DevExpress VerticalGrid set value of cell that has no fieldname

In the DevExpress VerticalGrid InitNewRecord event, I am able to set the cell value when the row has a value in the fieldname property:
string zipcode = "99999";
VGrid.SetCellValue(VGrid.GetRowByFieldName("zipcode"), e.RecordIndex, zipcode);
However, for rows with no value in their fieldname property, I am unable to do so. This is not working:
string city = "unknown";
VGrid.SetCellValue(VGrid.Rows["rowcity"], e.RecordIndex, city);
The row's (Name) property contains the value rowcity. I'm trying to get the row by its name.
I have also tried
string city = "unknown";
VGrid.SetCellValue(rowcity, e.RecordIndex, city);
where I'm trying to get the row using the member that has been automatically created.
I've also tried casting rowcity to BaseRow:
string city = "unknown";
DevExpress.XtraVerticalGrid.Rows.BaseRow mybaserow;
mybaserow = (DevExpress.XtraVerticalGrid.Rows.BaseRow) rowcity;
VGrid.SetCellValue(mybaserow, e.RecordIndex, city);
Have also tried via Properties:
VGrid.SetCellValue( rowcity.Properties, e.RecordIndex, "unknown");
but no joy.
What am I overlooking?
The CustomUnboundData event is how to accomplish this.
EDIT: In a rush, sorry...
The event fires as many times as there are unbound fields.
In the eventhandler, you examine the eventargs fieldname property (in a switch statment) and set the value of the fieldname(s) you want to set.

Drupal - How to use Computed field in field collection item fields

I have custom content type type_a
Inside that custom type I have few titles
Title
Body
Group1 (field_group1) (Field Collection Item Can have multiple values)
Following are the details of fields inside Group1 (Field Collection Item)
Group Item 1 (field_item1) Can have one value
Group Item 2 (field_item2) (Computed field) Can have one value
I would like to copy value of "Group Item 1" field of same field collection item inside "Group Item 2"
Below is I am using in computed code:
$entity_field[0]['value'] = $entity->field_item1[LANGUAGE_NONE][0]['value'];
But it is not working. I am getting an error
Notice: Undefined index: value in eval() (line 1 of /homepages/13/d160804/htdocs/test/sites/all/modules/computed_field/computed_field.module(466) : eval()'d code).
Please help how to do this. Thanks
$entity->field_item1[LANGUAGE_NONE][0]['value'] contains the entity id of the field collection item (which contains the fields you want to copy).
You either need to load both field collection items and set their individual fields. Eg,
$source_fc = field_collection_item_load($entity->field_item1[LANGUAGE_NONE][0]['value']);
$dest_fc = field_collection_item_load($entity->field_item2[LANGUAGE_NONE][0]['value']);
// now set values of $dest_fc with values from $source_fc
Or do some sort of clone similar to this method: http://drupal.org/node/1233256#comment-5167316

A GridColumn having columnEdit set as RepositoryItemComboBox , on changing SelectedItem, Old Item persists

A gridCoumn is defined in a Devex Xtra GridControl(winform type).
This column has two properties set :
FieldName --> a field name of a column in dataSource. OptionType
ColumnEdit --> as a RepositoryItemCombobox object , this object's 'Items' properties is having two value : Option1 , option2 & option3.
When data is set at runtime , the GridColumn shows the respective values in 'OptionType' column.
But now i cant change the values in any combobox of this column to other option by using the dropDown.
What am i missing ?????

If 2 dropdown showing same value on selected index change

I have been asked question on this scenario.There are 2 dropdownlist populating same data from same table one at top and other at bottom.when Item in first dropdownlist get selected,same item is shown in second dropdownlist and second item get selected,same item is selected in first.That means it is continuous loop.How to handle this situation. Don't want to use query
select name from table where id = ddl1.selecteditem.value and execute it.
On selectedindex function of dropdownlist1,he wrote like this
ddl2.selectedItem.value = ddl.selectedItem.value
and second list
ddl.selectedItem.value = ddl2.selectedItem.value
Does it possible to select the value from these 2 statement?I done like this,but not working.
In order to get the same value in both dropdownlists you need to do this in your dropdownlist1_selectedindexchanged:
DropDownList2.Items.FindByValue(DropDownList1.SelectedValue).Selected = true;
The same in dropdownlist2_selectedindexchanged:
DropDownList1.Items.FindByValue(DropDownList2.SelectedValue).Selected = true;
This should keep the same value in both dropdownlists whenever they have been modified.

Resources