How to add checkboxes at run time ?

4 posts, 0 answers
  1. Madhu Palakurthi
    Madhu Palakurthi avatar
    48 posts
    Member since:
    Nov 2009

    Posted 29 Nov 2012 Link to this post

    Hi,

    I have a screen that will give search result ( Invoice no(s) ) and need to be binding in check box list.

    this is the check box that i added in aspx page. but  I would like to show dynamically based on search result ( no of invoice no(s))

      <asp:TableCell CssClass="fls">
    <telerik:RadButton ID="chkSearchResult" ToggleType="CheckBox" runat="server" Text="HQ09504">
           <ToggleStates>
                <telerik:RadButtonToggleState Text="HQ09504" PrimaryIconCssClass="rbToggleCheckboxChecked" />
               <telerik:RadButtonToggleState Text="HQ09504" PrimaryIconCssClass="rbToggleCheckbox" />
          </ToggleStates>
    </telerik:RadButton>
    </asp:TableCell>

    Please give me sample code to generate check boxes at run time.

    Thanks in advance.
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 29 Nov 2012 Link to this post

    Hi,

    Try the following code to achieve your scenario.
    C#:
    chkSearchResult.ToggleType = ButtonToggleType.CheckBox;
     chkSearchResult.ButtonType = RadButtonType.ToggleButton;
    RadButtonToggleState state = new RadButtonToggleState();
     state.Text = "HQO9504";
     chkSearchResult.ToggleStates.Add(state);

    Thanks,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Madhu Palakurthi
    Madhu Palakurthi avatar
    48 posts
    Member since:
    Nov 2009

    Posted 30 Nov 2012 Link to this post

    Hi Princy,

    I modified logic as you mentioned above but it showing only one checkbox in display..

    My code is :
    <asp:TableFooterRow>
    <asp:TableCell CssClass="fls">
      <telerik:RadButton ID="chkSearchResult" ToggleType="CheckBox" Text="DSAD" runat="server" >
      <ToggleStates></ToggleStates>                                                                  
      </telerik:RadButton>
    </asp:TableCell>
    </asp:TableFooterRow>
     
    and code behind is :

    chkSearchResult.ToggleType = ButtonToggleType.CheckBox
    chkSearchResult.ButtonType = RadButtonType.ToggleButton
    Dim state As New RadButtonToggleState()
    For index As Integer = 1 To 10
        state.Text = "HQO9504" + (index.ToString())
    Next
    chkSearchResult.ToggleStates.Add(state)

    Still its showing only one checkbox is named with "DSAD" . what is the purpose of loop the states and add in to toggle.
  5. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 02 Dec 2012 Link to this post

    Hi Moegal,

    Following is the full code that I tried to add RadButtonToggleState dynamically to a RadButton.

    ASPX:
    <telerik:RadButton ID="chkSearchResult" ButtonType="ToggleButton" ToggleType="CheckBox" runat="server">
        <ToggleStates>
        </ToggleStates>
    </telerik:RadButton>

    C#:
    protected void Page_Load(object sender, EventArgs e)
    {
            RadButtonToggleState state1 = new RadButtonToggleState();
            state1.Text = "HQO95041";
            state1.PrimaryIconCssClass = "rbToggleCheckboxChecked";
            chkSearchResult.ToggleStates.Add(state1);
            RadButtonToggleState state2 = new RadButtonToggleState();
            state2.Text = "HQO95042";
            state2.PrimaryIconCssClass = "rbToggleCheckbox";
            chkSearchResult.ToggleStates.Add(state2);
    }

    Please elaborate your scenario if it doesn't helps.

    Regards,
    Princy.
Back to Top