我有2个组合框,每个组合都绑定到相同的DataTable,如下所示:
channelTypeCB.DataSource = SynergyData.ds.Tables["ChannelTypes"];
channelTypeCB.DisplayMember = "channelType";
channelTypeCB.ValueMember = "channelTypeID";
channelTypeCB.BindingContext = new BindingContext();
newSKChanTypeCB.DataSource = SynergyData.ds.Tables["ChannelTypes"];
newSKChanTypeCB.DisplayMember = "channelType";
newSKChanTypeCB.ValueMember = "channelTypeID";
newSKChanTypeCB.BindingContext = new BindingContext();
Run Code Online (Sandbox Code Playgroud)
当我单击按钮将记录插入数据库时,我使用channelType.SelectedValue ...返回不正确的值.我觉得它与使用ComboBox排序(我在设计视图中设置控件的属性中)有关.有人遇到过这个问题吗?
这是使用C#为winforms应用程序编程的
编辑:
例如,我的Datatable存储的值如下:
Run Code Online (Sandbox Code Playgroud)channelType channelTypeID Web 2 Mailer 3 Catalog 4
这在组合框中排序,当我选择第一个项目(排序时为"目录")时,SelectedValue返回2,当我选择第二个项目时它返回3 ....我本来希望"目录"到返回4
这是我ComboBox在 XAML 中实例化的
<Combobox ItemsSource="{Binding Path=Delimiters}" DisplayMemberPath="Key"
SelectedValue="{Binding Path=SelectedDelimiter, UpdateSourceTrigger=PropertyChanged}" />
Run Code Online (Sandbox Code Playgroud)
以下是视图模型中相应的绑定,并Dictionary在构造函数中填充:
private IDictionary<string,string> _delimiters;
public IDictionary<string,string> Delimiters
{
get{return _delimiters;}
set{_delimiters = value; RaisePropertyChanged("Delimiters");}
}
private KeyValuePair <string, string> _selectedDelimiter;
public KeyValuePair <string, string> SelectedDelimiter
{
get{return _selectedDelimiter;}
set{
if(value.Key != _selectedDelimiter.Key || value.Value != _selectedDelimiter.Value)
{
var prevDelimiter = _selectedDelimiter;
_selectedDelimiter = value;
if(IllegalDelimiter.Contains(_selectedDelimiter)
{
MessageBox.Show("errror", "error");
_selectedDelmiter = prevDelimiter;
}
RaisePropertyChanged("SelectedDelimiter");
}
}
}
Run Code Online (Sandbox Code Playgroud)
我在绑定所选值时遇到问题。正在Dictionary绑定,当我对 UI 进行更改时ComboBox,该设置被正确触发。在 if 语句中检查其是否为非法分隔符,它确实将所选值设置回其后面代码中的原始值,但它不会填充到 …
我有一个国家/地区下拉列表,并将所选属性设置为美国。我可以清楚地看到select =“ selected”进入在萤火虫中具有US值的select OPTION中。但是,无论是Firefox还是Chrome,都不会显示US为选中状态。我有以下用于填充和选择国家/地区的代码。
var countryData = getCountryData();
var html = '<option value="">Select Country</option>';
$.each(countryData, function(key,value) {
if(defaultValue == value.id)
{
html = html + '<option value="'+value.id+'" selected="selected">'+value.name+'</option>';
}
else
{
html = html + '<option value="'+value.id+'">'+value.name+'</option>';
}
});
countryField.html(html);
Run Code Online (Sandbox Code Playgroud)
如果确实由于某种原因浏览器没有显示所选内容,即使我们设置了所选属性也是如此。
更新:好的,正如我所期望的,它必须与其他代码冲突。确实是这样。我正在使用bootstrapValidator和执行此行为的特殊调用“ resetForm”。然而,我不明白的一件事,为什么仍然在Firebug中的html select显示出selected属性?但是最后我将这段代码放在了resetForm调用之后。感谢所有的建议和帮助。
我有自动完成输入
<
<div formArrayName="addresses">
<div class="row"
*ngFor="let itemrow of searchForm.controls.addresses.controls; let i=index"
[formGroupName]="i">
<mat-form-field>
<input type="text"
class="form-control" id="address"
formControlName="address"
matInput
[matAutocomplete]="auto"
(keyup)="getESRI($event.target.value)"
(focusout)="bindLocation($event.target.value)">
<mat-autocomplete #auto="matAutocomplete">
<mat-option *ngFor="let option of testLocation"
[value]="option.text">
{{ option.text }}
</mat-option>
</mat-autocomplete>
</mat-form-field>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
"testlocation":[{"text":"Euronet","magicKey":"dHA9MSNubT1FdXJvbmV0I2NzPTE5OjExI3NjPURFVQ==","isCollection":true},{"text":"Euronet","magicKey":"dHA9MSNubT1FdXJvbmV0I2NzPTE5OjExI3NjPURFVQ==","isCollection":true}]
当我尝试添加值[value] ="option.magicKey时,它在输入option.magicKey中显示,当我选择选项时.我只需将option.magicKey作为值,并选择option.text作为输入选项.其他如何添加option.magicKey作为bindLocation($ event.target.value)函数的参数?
我想在页面加载时将数据库中的选定值显示到下拉列表中。
我的控制器索引功能是:
public function index()
{
$country_data =DB::table('country')->select('country_id','country_name')->get();
$profile_data= DB::table('profiles')->select('*')->where('id',$user_id)->first();
return view('profile_update',compact('profile_data','country_data'));
}
Run Code Online (Sandbox Code Playgroud)
数据库中高度的列名是 :Height
我在 profile_update.blade.php 的下拉菜单是
<select class="select4" name="country" id="country">
<option value="">Please Select</option>
@foreach($country_data as $country)
<option value="{{$country->country_id}}" {{$country_data->country == $country->country_id ? 'selected' : ''}}>{{$country->country_name}}</option>
@endforeach</select>
Run Code Online (Sandbox Code Playgroud) 我正在努力从启用了多选并已绑定到数据库表的 Winforms 列表框中获取选定的值(请注意值而不是文本),获取名称(作为 DisplayMember)和 ID(作为 ValueMember) - 我需要所选项目的 ID。
列表框控件具有用于SelectedValue获取选定项值之一的属性,但不具有用于获取所有选定项值的属性。
该SelectedItems属性返回一个Listbox.SelectedObjectCollection我似乎无法从中提取项目值的值。
请帮忙!谢谢。
在我的应用程序中,我有一个可以拥有多个位置的客户.当您在我的下拉框中选择一个客户时,它会在一个包含所有位置的flowlayoutpanel中加载组合框.
这是我的代码:
IEnumerable<locatie> opstapPlaatsen = Database.getOpstapplaatsen(klant.klant_id);
foreach (locatie opstapplaats in opstapPlaatsen)
{
if (opstapPlaatsen.Count() <= 0)
{
}
else
{
ComboBox cbbOpstap = new ComboBox();
cbbOpstap.Width = 200;
cbbOpstap.Height = 20;
cbbOpstap.DataSource = Database.getLocaties();
cbbOpstap.ValueMember = "locatie_id";
cbbOpstap.SelectedValue = opstapplaats.locatie_id;
cbbOpstap.SelectedItem = opstapplaats;
cbbOpstap.DisplayMember = "FullAdress";
flpOpstapplaats.Controls.Add(cbbOpstap);
}
}
Run Code Online (Sandbox Code Playgroud)
我的问题是我无法设置SelectedItem或/和Value.当我查看断点时,有一个值opstapplaats.locatie_id(正确的值),但SelectedValue保持不变null.
我在循环之外做了类似的事情,对于没有在代码中创建的组合框,它在那里工作.

我不知道是什么原因造成的?这是因为它是在一个foreach,因为我在foreach之前使用它然后它工作.
谢谢,托马斯.
编辑:这个问题还没有解决,我不知道如何解决它.
编辑:这个问题似乎已经解决了.见接受的答案.
SelectedValue = ""当我点击我的按钮时,我得到了.
我的aspx:
<telerik:RadComboBox ID="ddl_contactList" runat="server" AutoPostBack="True" CausesValidation="False"
CollapseDelay="0" Culture="ar-EG" ExpandDelay="0" Filter="StartsWith" ItemsPerRequest="10"
MarkFirstMatch="true" Skin="Outlook" EnableAutomaticLoadOnDemand="True" EmptyMessage="-New Menu-"
ShowMoreResultsBox="True" OnSelectedIndexChanged="ddl_contactList_SelectedIndexChanged"
EnableItemCaching="false" EnableLoadOnDemand="True" EnableVirtualScrolling="True">
</telerik:RadComboBox>
Run Code Online (Sandbox Code Playgroud)
我的.cs:
private void BindContactLists(int year, int main_code)
{
ddl_contactList.Items.Clear();
DataTable dt = ContactList.GetContactListsByDep(year, main_code);
ddl_contactList.DataSource = dt;
ddl_contactList.DataTextField = "list_desc";
ddl_contactList.DataValueField = "list_code";
ddl_contactList.DataBind();
}
Run Code Online (Sandbox Code Playgroud)
我把它称之为,page load因为当我在其中调用它时
!Page.Ispostback,我收到以下错误:
没有分配的数据源.无法完成回叫请求.
我该如何解决这个问题?马上:
ddl_contactList.Text == "MySelectedItemText"
但
selectedValue == "" 和 selectedItem == ""
我想为组合框设置名称和值对。所以我创建了一个这样命名的Item类:
// Content item for the combo box
private class Item
{
private readonly string Name;
private readonly int Value;
private Item(string _name, int _value)
{
Name = _name; Value = _value;
}
private override string ToString()
{
// Generates the text shown in the combo box
return Name;
}
}
Run Code Online (Sandbox Code Playgroud)
和这样的数据集:
comboBox1.DataSource = null;
comboBox1.Items.Clear();
// For example get from database continentals.
var gets = _connection.Continentals;
comboBox1.Items.Add(new Item("--- Select a continental. ---", 0));
foreach (var get in …Run Code Online (Sandbox Code Playgroud) 我正在使用Angular 4反应形式创建一个下拉列表
<select id="city" formControlName="city" (change)="onCitySelect($event)" >
<option *ngFor="let city of cities" [ngValue]="city" >
{{ city }}
</option>
</select>
Run Code Online (Sandbox Code Playgroud)
在下拉列表中选择一个值时,我想调用一个方法并显示所选值。
这是我的代码
onCitySelect(event) {
console.log(event.target.value);
}
Run Code Online (Sandbox Code Playgroud)
我希望它能打印下拉列表中所示的城市名称。但是,它似乎也显示索引号。例如,
2: London
Run Code Online (Sandbox Code Playgroud)
而不是London下拉列表中实际显示的内容。
没有索引如何获取城市名称?
selectedvalue ×10
c# ×5
combobox ×4
angular ×2
.net ×1
.net-3.5 ×1
asp.net ×1
autocomplete ×1
binding ×1
dropdown ×1
foreach ×1
html ×1
html-select ×1
laravel ×1
laravel-5.5 ×1
listbox ×1
multi-select ×1
radcombobox ×1
select ×1
selecteditem ×1
sorting ×1
telerik ×1
winforms ×1
wpf ×1