问题
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