This is a migrated thread and some comments may be shown as answers.

Set button checked in code

2 Answers 131 Views
ToolBar
This is a migrated thread and some comments may be shown as answers.
John Davis
Top achievements
Rank 2
John Davis asked on 09 May 2008, 03:14 AM

How do you set a two-state button as "checked" in program code?  For example, in the following Telerik example how do you set as checked the button having ImageUrl="~/Images/J.gif" ?

<telerik:RadToolBar ID="RadToolBar1" runat="server" Skin="Hay" >
 
<Items>
   
<telerik:RadToolBarButton
     
runat="server"
     
ImageUrl="~/Images/bold.gif"
     
AllowSelfUnCheck="True"
     
CheckOnClick="True" />
   
<telerik:RadToolBarButton
     
runat="server"
     
ImageUrl="~/Images/Italic.gif"
     
AllowSelfUnCheck="True"
     
CheckOnClick="True" />
   
<telerik:RadToolBarButton
     
runat="server"
     
ImageUrl="~/Images/underline.gif"
     
AllowSelfUnCheck="True"
     
CheckOnClick="True" />
   
<telerik:RadToolBarButton
     
runat="server"
     
Enabled="False"
     
Text="|" />
   
<telerik:RadToolBarButton
     
runat="server"
     
Checked="True"
     
CheckOnClick="True"
     
Group="Justify"
     
ImageUrl="~/Images/LJ.gif" />
   
<telerik:RadToolBarButton
     
runat="server"
     
CheckOnClick="True"
     
Group="Justify"
     
ImageUrl="~/Images/J.gif" />
   
<telerik:RadToolBarButton
     
runat="server"
     
CheckOnClick="True"
     
ImageUrl="~/Images/RJ.gif" />
 
</Items>
</
telerik:RadToolBar>

2 Answers, 1 is accepted

Sort by
0
Accepted
Veselin Vasilev
Telerik team
answered on 09 May 2008, 03:08 PM
Hello John Davis,

You need to first find the button you want for example by using FindItemByValue method. Then you need to cast it to RadToolBarButton class and set its Checked property to true.

    protected void Page_Load(object sender, EventArgs e) 
    { 
        RadToolBarButton btn = (RadToolBarButton)RadToolBar1.FindItemByValue("J"); 
        btn.Checked = true
    } 

I have set Value="J" for that particular item.

I hope this helps.

Kind regards,
Veskoni
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
John Davis
Top achievements
Rank 2
answered on 09 May 2008, 08:46 PM
Veskoni
It works perfectly. Thank you.
john
Tags
ToolBar
Asked by
John Davis
Top achievements
Rank 2
Answers by
Veselin Vasilev
Telerik team
John Davis
Top achievements
Rank 2
Share this question
or