Telerik Rad Button Dyanamically check

僤鯓⒐⒋嵵緔 提交于 2019-12-25 09:37:15

问题


Have been unable to dynamically check a Telerik Rad Button control from the code behind in vb.net code. I have used things like chk_TypeEmployee.Checked = True with no result.

 <telerik:RadButton ID="chk_TypeEmployee" runat="server" ToggleType="Radio" ButtonType="StandardButton"     GroupName="StandardButton" Text="Employee"></telerik:RadButton>
  <telerik:RadButton ID="chk_TypeAgency" runat="server" ToggleType="Radio" ButtonType="StandardButton" GroupName="StandardButton" Text="Agency"></telerik:RadButton>

回答1:


You need to use ToggleStates:

<telerik:RadButton ID="chk_Type" runat="server" ToggleType="Radio" ButtonType="StandardButton" GroupName="StandardButton" Checked="true">
    <ToggleStates>
        <telerik:RadButtonToggleState Value="Employee" Text="Employee" PrimaryIconCssClass="rbToggleRadioChecked" />
        <telerik:RadButtonToggleState Value="Agency" Text="Agency" PrimaryIconCssClass="rbToggleRadio" />
    </ToggleStates>
</telerik:RadButton>

To set dynamicaly the button to "Agency" state, assuming it is the second ToggleState for the button:

chk_Type.ToggleStates[0].Selected = false;
chk_Type.ToggleStates[1].Selected = true;

Could be rewritten cleaner this way:

string DBValue = "Agency";
foreach (RadButtonToggleState state in chk_Type.ToggleStates)
{
    state.Selected = state.Value.Equals(DBValue);
}

And to retrieve the selected value, use the chk_Type.SelectedToggleState.Value.

Note: The RadButton's property Checked must be set to true. And at least 1 of your toggle states should be Selected, else the first toggle state would be selected by default. In order to use more than 2 toggle states, please read about ToggleType="Custom".

Read more about Telerik's Toggle Buttons.



来源:https://stackoverflow.com/questions/13687545/telerik-rad-button-dyanamically-check

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!