Two-way binding toggle button in grid edit template item

7 posts, 0 answers
  1. Tom
    Tom avatar
    47 posts
    Member since:
    Oct 2010

    Posted 08 Dec 2012 Link to this post

    NB. I am posting this self-answered post because I could not find a solution in the forum. Hopefully it will be useful to someone else.

    I spent *way* too many hours trying to debug this scenario: I have a GridTemplateColumn with a RadButton as a toggle button. I could not get the toggle button state back from the edit form for the insert and update commands for the life of me. The longer it took to solve, the simpler I knew my error had to be. Unfortunately, I could not find any examples in the demos--they all use simple column binding.

    My problem ended up being in my SQL data source: I had declared my "boolean" field as an "int" instead of a "bit". By fixing this, the two way binding worked as desired.

    Here is a snippet of my code, with just the RadButton in the template column (there are other controls in my actual application).

    <telerik:GridTemplateColumn UniqueName="gtcName" HeaderText="Title">
      <ItemTemplate>
        <telerik:RadButton ID="rbOpen" runat="server" ButtonType="ToggleButton" ToggleType="CheckBox" Checked='<%#Bind("isOpen")%>' Height="24" Width="48" ReadOnly="true">
          <ToggleStates>
            <telerik:RadButtonToggleState ImageUrl="iOpen.png" IsBackgroundImage="false" Value="1" Selected="true" />
            <telerik:RadButtonToggleState ImageUrl="iClosed.png" IsBackgroundImage="false" Value="0" />
          </ToggleStates>
        </ItemTemplate>
        <EditItemTemplate>
        <telerik:RadButton ID="erbOpen" runat="server" ButtonType="ToggleButton" ToggleType="CheckBox" Checked='<%#Bind("isOpen")%>' Height="24" Width="48">
          <ToggleStates>
            <telerik:RadButtonToggleState ImageUrl="iOpen.png" IsBackgroundImage="false" Value="1" Selected="true" />
            <telerik:RadButtonToggleState ImageUrl="iClosed.png" IsBackgroundImage="false" Value="0" />
          </ToggleStates>
        </telerik:RadButton>
      </EditItemTemplate>
    </telerik:GridTemplateColumn>


    In the SQL data source, the column "isOpen" is declared like this, even though it is a "bit" in the SQL database:

    <asp:Parameter Name="isOpen" Type="Boolean"/>
  2. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 12 Dec 2012 Link to this post

    Hello Tom,

    Thank you for sharing your case and the resolution you have discovered. I hope this will be of a big help for our community.

    All the best,
    Maria Ilieva
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  3. Hannah
    Hannah avatar
    8 posts
    Member since:
    May 2011

    Posted 08 Sep 2015 in reply to Tom Link to this post

    This is great, but wondering how you can do this for a triple state button. I'm having trouble figuring out how to handle the 'null' state.
  4. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 11 Sep 2015 Link to this post

    Hi Hannah,

    Can you please elaborate a bit more on the exact functionality you need to achieve, so that we can provide proper approach for implementing your scenario?


    Regards,
    Maria Ilieva
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  5. Hannah
    Hannah avatar
    8 posts
    Member since:
    May 2011

    Posted 11 Sep 2015 in reply to Maria Ilieva Link to this post

    Maria,

    I have a RadGrid bound to SQL Server database table. One of the columns is a bit field that allows nulls. (The user needs to know when this particular question has been addressed, so Null indicates they have not yet determined the answer to the question as opposed to defaulting the value to true/yes or false/no.)

    I tried to bind the bit field to a GridCheckBoxColumn, but it does not accommodate triple state. I then tried using the RadButton in a GridTemplateColumn. I was successful in displaying the correct value (Yes=checked, No=unchecked, Null=filled), but not successful in being able to handle this value on insert or edit operations.

    In my opinion, the GridCheckBoxColumn should just have a property you can set to allow 'Triple State', because the workaround requires a lot of extra coding. I submitted a request for this feature.

    Thanks,

    Hannah

     

  6. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 16 Sep 2015 Link to this post

    Hi Hannah,

    Thank you for the additional information provided.

    Can you please post the link to the public item you have logged fr this request. Thus other users can vote for it and increase its priority. Also I will forward your request to our dev team for further revision of the item so that they can discuss its possible implementation.

    Regards,
    Maria Ilieva
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  7. Hannah
    Hannah avatar
    8 posts
    Member since:
    May 2011

    Posted 16 Sep 2015 Link to this post

    Thank you, Maria! 

    Here is the link to the feature request (Triple State property in RadGrid GridCheckBoxColumn)

     http://feedback.telerik.com/Project/108/Feedback/Details/168892-triple-state-gridcheckboxcolumn-allow-binding-to-nullable-bit-field

     Regards,

    Hannah

Back to Top