标签: selectedvalue

.Net ComboBox绑定问题

我有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存储的值如下:

channelType    channelTypeID
Web             2
Mailer          3
Catalog         4
Run Code Online (Sandbox Code Playgroud)

这在组合框中排序,当我选择第一个项目(排序时为"目录")时,SelectedValue返回2,当我选择第二个项目时它返回3 ....我本来希望"目录"到返回4

.net sorting combobox selectedvalue

3
推荐指数
1
解决办法
1416
查看次数

将 Combobox 与 Dictionary 对象绑定,但在后面的代码中设置所选值不生效

这是我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 语句中检查其是否为非法分隔符,它确实将所选值设置回其后面代码中的原始值,但它不会填充到 …

c# wpf binding combobox selectedvalue

3
推荐指数
1
解决办法
9304
查看次数

html select即使设置为set也不显示为选中

我有一个国家/地区下拉列表,并将所选属性设置为美国。我可以清楚地看到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调用之后。感谢所有的建议和帮助。

html html-select selectedvalue

3
推荐指数
2
解决办法
2万
查看次数

Angular 2材质自动完成选定值

我有自动完成输入

<

<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)函数的参数?

autocomplete selectedvalue angular-material angular

3
推荐指数
1
解决办法
9111
查看次数

如何使用 Laravel 在下拉列表中显示从数据库中选择的值?

我想在页面加载时将数据库中的选定值显示到下拉列表中。

我的控制器索引功能是:

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)

select selectedvalue laravel dropdown laravel-5.5

3
推荐指数
1
解决办法
2万
查看次数

.NET 3.5 列表框选定值 (Winforms)

我正在努力从启用了多选并已绑定到数据库表的 Winforms 列表框中获取选定的值(请注意值而不是文本),获取名称(作为 DisplayMember)和 ID(作为 ValueMember) - 我需要所选项目的 ID。

列表框控件具有用于SelectedValue获取选定项值之一的属性,但不具有用于获取所有选定项值的属性。

SelectedItems属性返回一个Listbox.SelectedObjectCollection我似乎无法从中提取项目值的值。

请帮忙!谢谢。

c# listbox selectedvalue multi-select .net-3.5

2
推荐指数
1
解决办法
5983
查看次数

无法设置Combobox SelectedItem,Value

在我的应用程序中,我有一个可以拥有多个位置的客户.当您在我的下拉框中选择一个客户时,它会在一个包含所有位置的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之前使用它然后它工作.

谢谢,托马斯.

编辑:这个问题还没有解决,我不知道如何解决它.

编辑:这个问题似乎已经解决了.见接受的答案.

c# foreach combobox selectedvalue selecteditem

2
推荐指数
1
解决办法
9903
查看次数

RadComboBox选中的值为空

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 == ""

c# asp.net selectedvalue telerik radcombobox

2
推荐指数
1
解决办法
1万
查看次数

C# Winforms - 设置组合框选定值

我想为组合框设置名称和值对。所以我创建了一个这样命名的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)

c# combobox selectedvalue winforms

2
推荐指数
1
解决办法
5710
查看次数

Angular 4-在下拉列表中找到选定的值

我正在使用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 drop-down-menu angular angular-reactive-forms

2
推荐指数
1
解决办法
1万
查看次数