Friday, November 12, 2010

Hello World! :):):):)

Check Boxes in Rad Grids

So this week I had to update a rad grid on the 29Prime administration site for the sales people and customers of 29Prime.  There was an inbox of messages displayed in a telerik rad grid, and we had the information displayed for each message that someone else in the company had sent you or that you had sent them.  It was basically like a simplified email system on the website.

My task was to make this rad grid so that when you clicked on a checkbox that you had received or completed the task in the message, you could check some check boxes to say that.  One check box said Accepted, and another one said Completed.

As the site was set up, the rad grid would automatically, using javascript, open up a window displaying the message for whatever row in the rad box you had selected.

For background, a telerik rad grid is a lot like a normal grid view, if you have ever used them.  The difference is that rad grids are able to be given different styles to make them look cooler.  You can select a premade template from a list in the designer view if you just look for it.

The problem was that having to open up a popup window for each message was a little tedious, and the page had to refresh itself every time you closed a popup window to track in the grid if that message was marked accepted or completed in the popup.  My job was to make it so you could simply check a check box in the rad grid and it would update itself instantaneously.  In order to do this I had to change the column where the checkboxes were now from

<telerik:GridBoundColumn

to

<--
<telerik:GridTemplateColumn HeaderText="Accepted">
    <ItemTemplate>
        <asp:CheckBox ID="AcceptedCheckBox" ValidationGroup='<%#Eval("AlertID") %>'    
                    runat="server" AutoPostBack="true" Checked='<%# Bind("Accepted") %>'        
                    OnCheckedChanged="AcceptedCheckBox_OnCheckedChanged" />
     </ItemTemplate>
</telerik:GridTemplateColumn>
-->

Then, from the code behind I used the validation group to tell the database which message, (or Alert, as the system called it) that I wanted to change.  I could not find any property in an asp checkbox that would take a non-constant value.  I tried to use skinID, and I tried to use other attributes of an asp check box, but either the system would give me an error that those attributes could not be changed when the rad grid was bound, or that when I used the ToolTip attribute, it would show up when the mouse hovered over the rad grid.

That could be a useful tip for debugging, to see which rows are showing up in your grid, but I could not let those kind of features go on a professional looking site.  I settled with using the ValidationGroup attribute because that was the only thing that I could set on databind, and wouldn't show up as a tooltip on mouse hover.

The best part of the whole process is that the program updates the database really fast whenever the checkbox is changed.  I type cast the sender as a checkbox, and then use the checkbox1.checked feature to set the database boolean field as to the value of the checkbox.

The page doesn't even have to refresh itself.  It's like the database update is running on a different thread from the website view.