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

Two-way binding toggle button in grid edit template item

6 Answers 451 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tom
Top achievements
Rank 1
Tom asked on 08 Dec 2012, 07:33 PM
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"/>

6 Answers, 1 is accepted

Sort by
0
Maria Ilieva
Telerik team
answered on 12 Dec 2012, 10:42 AM
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.
0
Hannah
Top achievements
Rank 2
answered on 08 Sep 2015, 09:22 PM
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.
0
Maria Ilieva
Telerik team
answered on 11 Sep 2015, 10:54 AM
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
0
Hannah
Top achievements
Rank 2
answered on 11 Sep 2015, 01:53 PM

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

 

0
Maria Ilieva
Telerik team
answered on 16 Sep 2015, 01:48 PM
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
0
Hannah
Top achievements
Rank 2
answered on 16 Sep 2015, 02:29 PM

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

Tags
Grid
Asked by
Tom
Top achievements
Rank 1
Answers by
Maria Ilieva
Telerik team
Hannah
Top achievements
Rank 2
Share this question
or