简体   繁体   English

EXT:来自Codebehind的C#组合框设置值

[英]EXT:C# combobox set value from Codebehind

I have this Combobox: 我有这个组合框:

<ext:ComboBox runat="server" ID="cmbEmailVer"  FieldLabel="Email verification"  Width="420" ForceSelection="true" EmptyText="Select a value..." OnDirectChange="cmbEmailVer_DirectChange" OnLoad="cmbEmailVer_Load" >
     <Items>
           <ext:ListItem Text="Yes" Value="1" />
           <ext:ListItem Text="No" Value="0" />
     </Items>
</ext:ComboBox>

The OnLoad function in Codebehind: 代码背后的OnLoad函数:

protected void cmbEmailVer_Load(object sender, EventArgs e)
        {
            DAL.DataContext cud = new DAL.DataContext();

            var em = (from p in cud.CTs where p.id == ctid select p).FirstOrDefault();

            if (em != null)
            {
                cmbEmailVer.SelectedItem.Value = (em.login_verify_email ? 1 : 0).ToString();
            }
            else
            {
                cmbEmailVer.SelectedItem.Value = "1";
            }
        }

But even though I can see with breakpoints that it sets the correct value from codebehind, the combobox in the application doesnt change 但是,即使我可以从断点处看到断点设置了正确的值,应用程序中的组合框也不会改变

Use SelectedIndex 使用SelectedIndex

if (em != null)
{
   string s = (em.login_verify_email ? 1 : 0).ToString();
   cmbEmailVer.SelectedIndex = cmbEmailVer.Items.IndexOf(s); 
}
else
{
   cmbEmailVer.SelectedIndex = cmbEmailVer.Items.IndexOf("1") 
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM