在我的母版页中,我在AspxComboBox
项的ASPxMenu
标记中有一个Template
我可以在任意aspx
页面上访问它但是当我尝试设置时其Value或SelectedIndex然后更改不更新
<dx:MenuItem>
<Template>
<dx:ASPxComboBox ID="CbalarmSelect" runat="server" AutoPostBack="true" ViewStateMode="Enabled" OnSelectedIndexChanged="cbalarmselect_changed">
<Items>
<dx:ListEditItem Text="Select Option" Selected="true" Value="0" />
<dx:ListEditItem Text="Sample" Value="1" />
<dx:ListEditItem Text="Demo" Value="2" />
</Items>
</dx:ASPxComboBox>
</Template>
</dx:MenuItem>
访问此ComboBox的C#代码
ASPxMenu item = (ASPxMenu)Master.FindControl("ASPxMenu1");
ASPxComboBox combo = (ASPxComboBox)item.Items.FindByName("AlarmSubscription").FindControl("CbalarmSelect");
combo.SelectedIndex =1 ;
出于测试目的,我将其可见性设置为false combo.Visible = false;
但是可见平均集功能无法正常工作
答案 0 :(得分:0)
我试图在SelectedIndex
事件期间设置Page_Load
并且它无效。然后我在Page_LoadComplete
事件中移动我的代码并且它对我有效
void Page_LoadComplete(object sender, EventArgs e)
{
ASPxMenu item = (ASPxMenu)Master.FindControl("ASPxMenu1");
ASPxComboBox combo = (ASPxComboBox)item.Items.FindByName("AlarmSubscription").FindControl("CbalarmSelect");
combo.SelectedIndex =1 ;
}
答案 1 :(得分:-1)
客户端脚本
将ClientInstanceName属性设置为comboBox以将其作为cbxJobType访问客户端和ID属性以访问控制服务器端。
// by text
comboBox.SetText('Text #2');
// by value
comboBox.SetValue('Value #2');
// by index
comboBox.SetSelectedIndex(1);
服务器端代码
// by text
cbalarmSelect.Text = "Text #2";
// by value
cbalarmSelect.Value = "Value #2";
// by index
cbalarmSelect.SelectedIndex = 1;
此代码也可以正常工作:
cbalarmSelect.SelectedItem = cbalarmSelect.Items.FindByValue("Value #2");