How to bind radgridview header

7 posts, 0 answers
  1. Ravi Kumar
    Ravi Kumar avatar
    37 posts
    Member since:
    May 2010

    Posted 14 Jul 2010 Link to this post


    Hi,
      Can u suggest how to design the attached design using radgridview control.

      Is it possible to bind radgridview header from database.

    Regards
    Ravi
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 14 Jul 2010 Link to this post

    Hello Ravi,

    Please refer the demo and check the last column of the grid which uses GridTemplateColumn and a table structure in HeaderTemplate to merge the header cells like your case.
    Column Types


    In the case of you want to change the header values, then access the controls from code behind and set the Text property accordingly.


    -Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Ravi Kumar
    Ravi Kumar avatar
    37 posts
    Member since:
    May 2010

    Posted 16 Jul 2010 Link to this post

    Hi Shinu,

    Thanks for response.

    i am taking the ref as you suggested for cell editing in radgridview.but i,m facing problem to do update cell values (get colName is null).
    i,m posting my source code. Can you see in this. its very important to me.

    Thanks in advance
    Ravi

    HTML Page:

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TimeSheetEntry.aspx.cs"
        Inherits="WFSite.TimeSheetEntry" %>

    <%@ Register Assembly="WFControls" Namespace="WFControls" TagPrefix="pdi" %>
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title>Untitled Page</title>
    </head>
    <body>
        <style>
            .bd
            {
                border-bottom: 1px solid gray;
            }
        </style>
        <form id="form1" runat="server">
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server" />
        <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">

            <script type="text/javascript">
             <!--
                //Custom js code section used to edit records, store changes and switch the visibility of column editors
                
                //global variables for edited cell and edited rows ids
                var editedCell;
                var arrayIndex = 0;
                var editedItemsIds = [];

                function RowCreated(sender, eventArgs) {
                    var dataItem = eventArgs.get_gridDataItem();

                    //traverse the cells in the created client row object and attach dblclick handler for each of them
                    for (var i = 1; i < dataItem.get_element().cells.length; i++) {
                        var cell = dataItem.get_element().cells[i];
                        if (cell) {
                            $addHandler(cell, "dblclick", Function.createDelegate(cell, ShowColumnEditor));
                        }
                    }
                }
                //detach the ondblclick handlers from the cells on grid disposing
                function GridDestroying(sender, eventArgs) {
                    for (var i = 0; i < sender.get_masterTableView().get_dataItems().length; i++) {
                        var curRow = sender.get_masterTableView().get_dataItems()[i];
                        for (var j = 0; j < curRow.get_element().cells.length; j++) {
                            var cell = curRow.get_element().cells[j];
                            if (cell) {
                                $clearHandlers(cell);
                            }
                        }
                    }
                }
                function RowClick(sender, eventArgs) {
                    if (editedCell) {
                        //if the click target is table cell or span and there is an edited cell, update the value in it
                        //skip update if clicking a span that happens to be a form decorator element (having a class that starts with "rfd")
                        if ((eventArgs.get_domEvent().target.tagName == "TD") ||
                            (eventArgs.get_domEvent().target.tagName == "SPAN" && !eventArgs.get_domEvent().target.className.startsWith("rfd"))) {
                            UpdateValues(sender);
                            editedCell = false;
                        }
                    }
                }
                function ShowColumnEditor() {
                    editedCell = this;

                    //hide text and show column editor in the edited cell
                    var cellText = this.getElementsByTagName("span")[0];
                    cellText.style.display = "none";
                    
                    //display the span which wrapps the hidden checkbox editor
                    if (this.getElementsByTagName("span")[1]) {
                        this.getElementsByTagName("span")[1].style.display = "";
                    }
                    var colEditor = this.getElementsByTagName("input")[0] || this.getElementsByTagName("select")[0];
                    //if the column editor is a form decorated select dropdown, show it instead of the original
                    if (colEditor.className == "rfdRealInput" && colEditor.tagName.toLowerCase() == "select") colEditor = Telerik.Web.UI.RadFormDecorator.getDecoratedElement(colEditor);
                    colEditor.style.display = "";
                    colEditor.focus();
                }
                function StoreEditedItemId(editCell) {
                    //get edited row key value and add it to the array which holds them
                    var gridRow = $find(editCell.parentNode.id);
                    alert("gridRowID "  + gridRow);
                    var rowKeyValue = gridRow.getDataKeyValue("ID");
                    alert("rowKeyValue " + rowKeyValue);
                    Array.add(editedItemsIds, rowKeyValue);
                }
                function HideEditor(editCell, editorType) {
                    //get reference to the label in the edited cell
                    var lbl = editCell.getElementsByTagName("span")[0];
                    
                    switch (editorType) {
                        case "textbox":
                            var txtBox = editCell.getElementsByTagName("input")[0];
                            if (lbl.innerHTML != txtBox.value) {
                                lbl.innerHTML = txtBox.value;
                                editCell.style.border = "1px dashed";

                                StoreEditedItemId(editCell);
                            }
                            txtBox.style.display = "none";
                            break;
                        case "checkbox":
                            var chkBox = editCell.getElementsByTagName("input")[0];
                            if (lbl.innerHTML.toLowerCase() != chkBox.checked.toString()) {
                                lbl.innerHTML = chkBox.checked;
                                editedCell.style.border = "1px dashed";

                                StoreEditedItemId(editCell);
                            }
                            chkBox.style.display = "none";
                            editCell.getElementsByTagName("span")[1].style.display = "none";
                            break;
                        case "dropdown":
                            var ddl = editCell.getElementsByTagName("select")[0];
                            var selectedValue = ddl.options[ddl.selectedIndex].value;
                            if (lbl.innerHTML != selectedValue) {
                                lbl.innerHTML = selectedValue;
                                editCell.style.border = "1px dashed";

                                StoreEditedItemId(editCell);
                            }
                            //if the form decorator was enabled, hide the decorated dropdown instead of the original.
                            if (ddl.className == "rfdRealInput") ddl = Telerik.Web.UI.RadFormDecorator.getDecoratedElement(ddl);
                            ddl.style.display = "none";
                        default:
                            break;
                    }
                    lbl.style.display = "inline";
                }
                function UpdateValues(grid) {
                    //determine the name of the column to which the edited cell belongs
                    var tHeadElement = grid.get_element().getElementsByTagName("thead")[0];
                    var headerRow = tHeadElement.getElementsByTagName("tr")[0];
                    var colName = grid.get_masterTableView().getColumnUniqueNameByCellIndex(headerRow, editedCell.cellIndex);
                     alert("colName " + colName);
                    //based on the column name, extract the value from the editor, update the text of the label and switch its visibility with that of the column
                    //column. The update happens only when the column editor value is different than the non-editable value. We also set dashed border to indicate
                    //that the value in the cell is changed. The logic is isolated in the HideEditor js method
                    switch (colName) {
                        case "Day1":
                            HideEditor(editedCell, "textbox");
                            break;
                        case "Day2":
                            HideEditor(editedCell, "textbox");
                            break;
                        case "Day3":
                            HideEditor(editedCell, "textbox");
                            break;
                        case "Day4":
                            HideEditor(editedCell, "textbox");
                            break;
                        case "Day5":
                            HideEditor(editedCell, "textbox");
                            break;
                        case "Day6":
                            HideEditor(editedCell, "textbox");
                            break;
                        case "Day7":
                            HideEditor(editedCell, "textbox");
                            break;
                        default:
                            break;
                    }
                }
                function CancelChanges() {
                    if (editedItemsIds.length > 0)
                     {
                     alert("Cancel " + editedItemsIds.length);
                        $find("<%=RadAjaxManager1.ClientID %>").ajaxRequest("");
                    }
                    else {
                        alert("No pending changes to be discarded");
                    }
                    editedItemsIds = [];
                }
                function ProcessChanges() {
                    //extract edited rows ids and pass them as argument in the ajaxRequest method of the manager
                    if (editedItemsIds.length > 0)
                     {
                        alert("Process " + editedItemsIds.length);
                        var Ids = "";
                        for (var i = 0; i < editedItemsIds.length; i++) {
                            Ids = Ids + editedItemsIds[i] + ":";
                        }
                        $find("<%=RadAjaxManager1.ClientID %>").ajaxRequest(Ids);
                    }
                    else {
                        alert("No pending changes to be processed");
                    }
                    editedItemsIds = [];
                }
                function gvwTimeSheet_Command(sender, eventArgs) {
                    //Note that this code has to be executed if you postback from external control instead from the grid (intercepting its onclientclick handler for this purpose),
                    //otherwise the edited values will be lost or not propagated in the source
                    if (editedItemsIds.length > 0) {
                        if (eventArgs.get_commandName() == "Sort" || eventArgs.get_commandName() == "Page" || eventArgs.get_commandName() == "Filter") {
                            if (confirm("Any unsaved edited values will be lost. Choose 'OK' to discard the changes before proceeding or 'Cancel' to abort the action and process them.")) {
                                editedItemsIds = [];
                            }
                            else{
                                //cancel the chosen action
                                eventArgs.set_cancel(true);
                                
                                //process the changes
                                ProcessChanges();
                                editedItemsIds = [];
                            }
                        }
                    }
                }
                window.onunload = function() {
                    //this code should also be executed on postback from external control (which rebinds the grid) to process any unsaved data
                    if (editedItemsIds.length > 0) {
                        if (confirm("Any unsaved edited values will be lost. Choose 'OK' to discard the changes before proceeding or 'Cancel' to abort the action and process them.")) {
                            editedItemsIds = [];
                        }
                        else {
                            //process the changes
                            ProcessChanges();
                            editedItemsIds = [];
                        }
                    }
                };
         -->    
            </script>

        </telerik:RadCodeBlock>
        <telerik:RadFormDecorator ID="RadFormDecorator1" runat="server" DecoratedControls="Default,Select,Textbox"
            EnableRoundedCorners="false" />
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" OnAjaxRequest="RadAjaxManager1_AjaxRequest">
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="gvwTimeSheet">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="gvwTimeSheet" LoadingPanelID="RadAjaxLoadingPanel1" />
                        <%--<telerik:AjaxUpdatedControl ControlID="RadInputManager1" />--%>
                        <telerik:AjaxUpdatedControl ControlID="Label1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
                <telerik:AjaxSetting AjaxControlID="RadAjaxManager1">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="gvwTimeSheet" LoadingPanelID="RadAjaxLoadingPanel1" />
                        <%--<telerik:AjaxUpdatedControl ControlID="RadInputManager1" />--%>
                        <telerik:AjaxUpdatedControl ControlID="Label1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
        </telerik:RadAjaxManager>
        <%--<telerik:RadInputManager ID="RadInputManager1" EnableEmbeddedBaseStylesheet="false"
            Skin="" runat="server">
            <telerik:TextBoxSetting BehaviorID="StringBehavior" EmptyMessage="type here" />
            <telerik:NumericTextBoxSetting BehaviorID="CurrencyBehavior" EmptyMessage="type.."
                Type="Currency" Validation-IsRequired="true" MinValue="1" MaxValue="100000" />
            <telerik:NumericTextBoxSetting BehaviorID="NumberBehavior" EmptyMessage="type.."
                Type="Number" DecimalDigits="0" MinValue="0" MaxValue="100" />
        </telerik:RadInputManager>--%>
        <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" />
        <table width="98%" border="0" cellpadding="2" cellspacing="2" class="contentArea"
            style="margin: 5px 0px 0px 0px;">
            <tr>
                <td>
                    <asp:Label ID="lblNumber" runat="server" Text="Number:"></asp:Label>
                </td>
                <td colspan="2">
                    <asp:Label ID="lblNumberDescription" runat="server" ForeColor="Blue" Text="3498982 - Fred Williams"></asp:Label>
                </td>
            </tr>
            <tr>
                <td style="width: 25%">
                    <asp:Label ID="lblTimeSheetEntry" runat="server" Text="Time Sheet for the week ending:"></asp:Label>
                </td>
                <td>
                    <pdi:PDIWebComboBox ID="RadComboBox1" runat="server" EmptyMessage="Select work type"
                        Width="200px">
                        <Items>
                            <telerik:RadComboBoxItem Value="Default" Text="03/08/2009 (Not submitted)" />
                            <telerik:RadComboBoxItem Value="Windows7" Text="Windows7" />
                            <telerik:RadComboBoxItem Value="WebBlue" Text="WebBlue" />
                            <telerik:RadComboBoxItem Value="Web20" Text="Web20" />
                            <telerik:RadComboBoxItem Value="Vista" Text="Vista" />
                            <telerik:RadComboBoxItem Value="Telerik" Text="Telerik" />
                            <telerik:RadComboBoxItem Value="Sunset" Text="Sunset" />
                            <telerik:RadComboBoxItem Value="Hay" Text="Hay" />
                            <telerik:RadComboBoxItem Value="Forest" Text="Forest" />
                            <telerik:RadComboBoxItem Value="Simple" Text="Simple" />
                        </Items>
                    </pdi:PDIWebComboBox>
                </td>
                <td style="width: 50%">
                    <asp:Button ID="btnShowHistory" runat="server" Text="ShowHistory" />
                </td>
            </tr>
            <tr>
                <td colspan="3">
                    <telerik:RadGrid ID="gvwTimeSheet" runat="server" AllowPaging="True" AllowSorting="True"
                        ShowStatusBar="True" AutoGenerateDeleteColumn="false" AutoGenerateEditColumn="false"
                        GridLines="None" AutoGenerateColumns="false" Width="100%" OnNeedDataSource="gvwTimeSheet_NeedDataSource"
                        Style="margin-top: 5px;" OnItemCreated="gvwTimeSheet_ItemCreated">
                        <MasterTableView TableLayout="Fixed" DataKeyNames="ID" EditMode="InPlace" ClientDataKeyNames="ID"
                            CommandItemDisplay="Top">
                            <CommandItemTemplate>
                                <div style="height: 30px; text-align: right;">
                                    <asp:Image ID="imgCancelChanges" runat="server" ImageUrl="~/Grid/Examples/DataEditing/ClientEditBatchUpdates/Img/cancel.gif"
                                        AlternateText="Cancel changes" ToolTip="Cancel changes" Height="24px" Style="cursor: pointer;
                                        margin: 2px 5px 0px 0px;" onclick="CancelChanges();" />
                                    <asp:Image ID="imgProcessChanges" runat="server" ImageUrl="~/Grid/Examples/DataEditing/ClientEditBatchUpdates/Img/ok.gif"
                                        AlternateText="Process changes" ToolTip="Process changes" Height="24px" Style="cursor: pointer;
                                        margin: 2px 5px 0px 0px;" onclick="ProcessChanges();" />
                                </div>
                            </CommandItemTemplate>
                            <Columns>
                                <telerik:GridBoundColumn UniqueName="ID" DataField="ID" HeaderText="ID" ReadOnly="True"
                                    HeaderStyle-Width="5%" />
                                <telerik:GridTemplateColumn UniqueName="WorkType" HeaderText="Work Type" SortExpression="WorkType">
                                    <ItemTemplate>
                                        <pdi:PDIWebComboBox ID="cboTSWorkTypes" runat="server" Width="110px" Height="100px"
                                            EnableLoadOnDemand="true" EmptyMessage="Select Work Type" HighlightTemplatedItems="True"
                                            OnItemsRequested="cboTSWorkTypes_OnItemsRequested" DropDownWidth="220px">
                                            <HeaderTemplate>
                                                <table style="width: 200px" cellspacing="0" cellpadding="0">
                                                    <tr>
                                                        <td style="width: 100px;">
                                                            Work Type
                                                        </td>
                                                        <td style="width: 80px;">
                                                            Work Type ID
                                                        </td>
                                                    </tr>
                                                </table>
                                            </HeaderTemplate>
                                            <ItemTemplate>
                                                <table border="0" style="width: 200px" cellspacing="0" cellpadding="0">
                                                    <tr>
                                                        <td style="width: 100px;">
                                                            <%# DataBinder.Eval(Container, "Text")%>
                                                        </td>
                                                        <td style="width: 80px;">
                                                            <%# DataBinder.Eval(Container, "Attributes['WF_EmpWorktype_Id']")%>
                                                        </td>
                                                    </tr>
                                                </table>
                                            </ItemTemplate>
                                        </pdi:PDIWebComboBox>
                                    </ItemTemplate>
                                </telerik:GridTemplateColumn>
                                <telerik:GridTemplateColumn UniqueName="WorkType_Cat" HeaderText="Category" ReadOnly="true"
                                    ConvertEmptyStringToNull="true">
                                    <ItemTemplate>
                                        <asp:Label ID="lblTScategory" runat="server" Text='<%# Eval("WorkType_Cat") %>' />
                                    </ItemTemplate>
                                </telerik:GridTemplateColumn>
                                <telerik:GridTemplateColumn UniqueName="IsTimeCard" HeaderText="Time Card" HeaderStyle-Wrap="true">
                                    <ItemTemplate>
                                        <asp:CheckBox ID="chkTSIsTimeCard" runat="server" Checked='<%# Eval("IsTimeCard")%>' />
                                    </ItemTemplate>
                                </telerik:GridTemplateColumn>
                                <telerik:GridTemplateColumn UniqueName="Day1">
                                    <HeaderTemplate>
                                        <table id="Table1" border="0" cellspacing="0" cellpadding="0" style="width: 110%;">
                                            <tr>
                                                <td align="center" class="bd">
                                                    <asp:Label ID="lblTSDay1" runat="server" Text='<%# GetDay1 %>' />
                                                </td>
                                            </tr>
                                            <tr>
                                                <td align="center">
                                                    <asp:Label ID="lblTSDate1" runat="server" Text='<%# GetDate1 %>' />
                                                </td>
                                            </tr>
                                        </table>
                                    </HeaderTemplate>
                                    <ItemTemplate>
                                        <asp:Label ID="Label1" runat="server" Text='<%# Eval("Day1") %>' />
                                        <asp:TextBox ID="RadTextBox1" runat="server" Text='<%# Bind("Day1") %>' Width="95%"
                                            Style="display: none;"></asp:TextBox>
                                    </ItemTemplate>
                                </telerik:GridTemplateColumn>
                                <telerik:GridTemplateColumn UniqueName="Day2">
                                    <HeaderTemplate>
                                        <table id="Table1" border="0" cellspacing="0" cellpadding="0" style="width: 110%;">
                                            <tr>
                                                <td align="center" class="bd">
                                                    <asp:Label ID="lblTSDay2" runat="server" Text='<%# GetDay2 %>' />
                                                </td>
                                            </tr>
                                            <tr>
                                                <td align="center">
                                                    <asp:Label ID="lblTSDate2" runat="server" Text='<%# GetDate2 %>' />
                                                </td>
                                            </tr>
                                        </table>
                                    </HeaderTemplate>
                                    <ItemTemplate>
                                        <asp:Label ID="Label2" runat="server" Text='<%# Eval("Day2") %>' />
                                        <asp:TextBox ID="RadTextBox2" runat="server" Text='<%# Bind("Day2") %>' Width="95%"
                                            Style="display: none;"></asp:TextBox>
                                    </ItemTemplate>
                                </telerik:GridTemplateColumn>
                                <telerik:GridTemplateColumn UniqueName="Day3">
                                    <HeaderTemplate>
                                        <table id="Table1" border="0" cellspacing="0" cellpadding="0" style="width: 110%;">
                                            <tr>
                                                <td align="center" class="bd">
                                                    <asp:Label ID="lblTSDay3" runat="server" Text='<%# GetDay3 %>' />
                                                </td>
                                            </tr>
                                            <tr>
                                                <td align="center">
                                                    <asp:Label ID="lblTSDate3" runat="server" Text='<%# GetDate3 %>' />
                                                </td>
                                            </tr>
                                        </table>
                                    </HeaderTemplate>
                                    <ItemTemplate>
                                        <asp:Label ID="Label3" runat="server" Text='<%# Eval("Day3") %>' />
                                        <asp:TextBox ID="RadTextBox3" runat="server" Text='<%# Bind("Day3") %>' Width="95%"
                                            Style="display: none;"></asp:TextBox>
                                    </ItemTemplate>
                                </telerik:GridTemplateColumn>
                                <telerik:GridTemplateColumn UniqueName="Day4">
                                    <HeaderTemplate>
                                        <table id="Table1" border="0" cellspacing="0" cellpadding="0" style="width: 110%;">
                                            <tr>
                                                <td align="center" class="bd">
                                                    <asp:Label ID="lblTSDay4" runat="server" Text='<%# GetDay4 %>' />
                                                </td>
                                            </tr>
                                            <tr>
                                                <td align="center">
                                                    <asp:Label ID="lblTSDate4" runat="server" Text='<%# GetDate4 %>' />
                                                </td>
                                            </tr>
                                        </table>
                                    </HeaderTemplate>
                                    <ItemTemplate>
                                        <asp:Label ID="Label4" runat="server" Text='<%# Eval("Day4") %>' />
                                        <asp:TextBox ID="RadTextBox4" runat="server" Text='<%# Bind("Day4") %>' Width="95%"
                                            Style="display: none;"></asp:TextBox>
                                    </ItemTemplate>
                                </telerik:GridTemplateColumn>
                                <telerik:GridTemplateColumn UniqueName="Day5">
                                    <HeaderTemplate>
                                        <table id="Table1" border="0" cellspacing="0" cellpadding="0" style="width: 110%;">
                                            <tr>
                                                <td align="center" class="bd">
                                                    <asp:Label ID="lblTSDay5" runat="server" Text='<%# GetDay5 %>' />
                                                </td>
                                            </tr>
                                            <tr>
                                                <td align="center">
                                                    <asp:Label ID="lblTSDate5" runat="server" Text='<%# GetDate5 %>' />
                                                </td>
                                            </tr>
                                        </table>
                                    </HeaderTemplate>
                                    <ItemTemplate>
                                        <asp:Label ID="Label5" runat="server" Text='<%# Eval("Day5") %>' />
                                        <asp:TextBox ID="RadTextBox5" runat="server" Text='<%# Bind("Day5") %>' Width="95%"
                                            Style="display: none;"></asp:TextBox>
                                    </ItemTemplate>
                                </telerik:GridTemplateColumn>
                                <telerik:GridTemplateColumn UniqueName="Day6">
                                    <HeaderTemplate>
                                        <table id="Table1" border="0" cellspacing="0" cellpadding="0" style="width: 110%;">
                                            <tr>
                                                <td align="center" class="bd">
                                                    <asp:Label ID="lblTSDay6" runat="server" Text='<%# GetDay6 %>' />
                                                </td>
                                            </tr>
                                            <tr>
                                                <td align="center">
                                                    <asp:Label ID="lblTSDate6" runat="server" Text='<%# GetDate6 %>' />
                                                </td>
                                            </tr>
                                        </table>
                                    </HeaderTemplate>
                                    <ItemTemplate>
                                        <asp:Label ID="Label6" runat="server" Text='<%# Eval("Day6") %>' />
                                        <asp:TextBox ID="RadTextBox6" runat="server" Text='<%# Bind("Day6") %>' Width="95%"
                                            Style="display: none;"></asp:TextBox>
                                    </ItemTemplate>
                                </telerik:GridTemplateColumn>
                                <telerik:GridTemplateColumn UniqueName="Day7">
                                    <HeaderTemplate>
                                        <table id="Table1" border="0" cellspacing="0" cellpadding="0" style="width: 110%;">
                                            <tr>
                                                <td align="center" class="bd">
                                                    <asp:Label ID="lblTSDay7" runat="server" Text='<%# GetDay7 %>' />
                                                </td>
                                            </tr>
                                            <tr>
                                                <td align="center">
                                                    <asp:Label ID="lblTSDate7" runat="server" Text='<%# GetDate7 %>' />
                                                </td>
                                            </tr>
                                        </table>
                                    </HeaderTemplate>
                                    <ItemTemplate>
                                        <asp:Label ID="Label7" runat="server" Text='<%# Eval("Day7") %>' />
                                        <asp:TextBox ID="RadTextBox7" runat="server" Text='<%# Bind("Day7") %>' Width="95%"
                                            Style="display: none;"></asp:TextBox>
                                    </ItemTemplate>
                                </telerik:GridTemplateColumn>
                                <telerik:GridTemplateColumn UniqueName="Total" HeaderText="Total" HeaderStyle-Wrap="true">
                                    <ItemTemplate>
                                        <asp:Label ID="lblTSTotal" runat="server" Text='<%# Bind("Total")%>' />
                                    </ItemTemplate>
                                </telerik:GridTemplateColumn>
                                <telerik:GridButtonColumn ConfirmText="Delete this entry?" ConfirmDialogType="RadWindow"
                                    ConfirmTitle="Delete" ButtonType="ImageButton" CommandName="Delete" HeaderText="Delete" />
                            </Columns>
                        </MasterTableView>
                        <ClientSettings>
                            <ClientEvents OnRowCreated="RowCreated" OnRowClick="RowClick" OnCommand="gvwTimeSheet_Command"
                                OnGridDestroying="GridDestroying" />
                        </ClientSettings>
                    </telerik:RadGrid>
                    <br />
                    <asp:Label ID="Label1" runat="server" EnableViewState="false" />
                    <br />
                </td>
            </tr>
        </table>
        </form>
    </body>
    </html>
    **********************************************************************************************************
    **********************************************************************************************************
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Configuration;
    using System.Data;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Xml.Linq;
    using Telerik.Web.UI;
    using profdata.com.WorkForce;
    using profdata.com.WorkForce.Exceptions;
    using profdata.com.WorkForce.Utilities;

    namespace WFSite
    {
        public partial class TimeSheetEntry : System.Web.UI.Page
        {
            private libWFDALController dalController = null;
            private static DataSet dsWorkTypes = null;
            protected void Page_Load(object sender, EventArgs e)
            {
                DateTime date;
                DataSet dsTimesheet = new DataSet();
                DateTime.TryParse("2010-07-13", out date);

                this.DataBind();
                if (!IsPostBack)
                {
                    dalController = new libWFDALController();
                    dsWorkTypes = new DataSet();
                    dsWorkTypes = dalController.GetWorkTypesByEmployee(1, date);
                }

            }
            #region  Day Properties
            public string GetDay1 { get; set; }
            public string GetDay2 { get; set; }
            public string GetDay3 { get; set; }
            public string GetDay4 { get; set; }
            public string GetDay5 { get; set; }
            public string GetDay6 { get; set; }
            public string GetDay7 { get; set; }
            public string GetDate1 { get; set; }
            public string GetDate2 { get; set; }
            public string GetDate3 { get; set; }
            public string GetDate4 { get; set; }
            public string GetDate5 { get; set; }
            public string GetDate6 { get; set; }
            public string GetDate7 { get; set; }
            #endregion
            private void SetMessage(string message)
            {
                Label1.Text = string.Format("<span>{0}</span>", message);
            }
            protected void gvwTimeSheet_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
            {
                DateTime date1;
                DateTime.TryParse("2010-07-13", out date1);
                List<bocWFEmployeeTimesheet> timesheetList = null;
                timesheetList = dalController.GetTimesheetByEmployee(1, date1);

                var headerData = Enumerable.Empty<bocWFEmployeeTimesheet>();
                var itemData = Enumerable.Empty<bocWFEmployeeTimesheet>();
                if (timesheetList != null)
                {
                    headerData = timesheetList.Take(2);
                    itemData = timesheetList.Skip(2);
                }

                var days = from data in headerData
                           where data.Record_Type == "Weekday"
                           select data;
                if (days != null)
                {
                    foreach (var day in days)
                    {
                        GetDay1 = day.Day1;
                        GetDay2 = day.Day2;
                        GetDay3 = day.Day3;
                        GetDay4 = day.Day4;
                        GetDay5 = day.Day5;
                        GetDay6 = day.Day6;
                        GetDay7 = day.Day7;
                    }
                }
                var dates = from data in headerData
                            where data.Record_Type == "Date"
                            select data;
                if (dates != null)
                {
                    foreach (var date in dates)
                    {
                        GetDate1 = date.Day1;
                        GetDate2 = date.Day2;
                        GetDate3 = date.Day3;
                        GetDate4 = date.Day4;
                        GetDate5 = date.Day5;
                        GetDate6 = date.Day6;
                        GetDate7 = date.Day7;
                    }
                }
                gvwTimeSheet.DataSource = itemData;


            }
            protected void cboTSWorkTypes_OnItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
            {
                DataView dvCountries = new DataView();
                RadComboBox cboTemp = new RadComboBox();

                // Find combobox inside gridview
                cboTemp = gvwTimeSheet.Items[0].FindControl("cboTSWorkTypes") as RadComboBox;
                if (cboTemp == null) return;

                if (dsWorkTypes.Tables != null && dsWorkTypes != null && dsWorkTypes.Tables[0].Rows.Count > 0)
                {
                    dvCountries.Table = dsWorkTypes.Tables[0];
                    string filter = string.Empty;
                    if (!string.IsNullOrEmpty(e.Text))
                    {
                        if (utlTypeChecking.IsNumeric(e.Text))
                            filter = "WF_EmpWorktype_Id = " + e.Text;
                        else
                            filter = "WF_EmpWorkType_Code '%" + e.Text + "%'";
                    }
                    dvCountries.RowFilter = filter;
                    foreach (DataRowView drV in dvCountries)
                    {
                        RadComboBoxItem item = new RadComboBoxItem();
                        item.Text = drV["WF_EmpWorkType_Code"].ToString();
                        item.Value = drV["WF_EmpWorktype_Id"].ToString();

                        string code = drV["WF_EmpWorktype_Id"].ToString();
                        item.Attributes.Add("WF_EmpWorktype_Id", code);

                        cboTemp.Items.Add(item);
                        item.DataBind();
                    }
                }
            }
            protected void gvwTimeSheet_ItemCreated(object sender, GridItemEventArgs e)
            {
                if (e.Item is GridDataItem)
                {
                    GridDataItem dataItem = (GridDataItem)e.Item;

                    //TextBox txtBox = (TextBox)dataItem.FindControl("RadTextBox1");
                    //NumericTextBoxSetting numericSetting1 = (NumericTextBoxSetting)RadInputManager1.GetSettingByBehaviorID("NumberBehavior");
                    //numericSetting1.TargetControls.Add(new TargetInput(txtBox.UniqueID, true));

                    //txtBox = (TextBox)dataItem.FindControl("RadTextBox2");
                    //numericSetting1.TargetControls.Add(new TargetInput(txtBox.UniqueID, true));

                    //txtBox = (TextBox)dataItem.FindControl("RadTextBox3");
                    //numericSetting1.TargetControls.Add(new TargetInput(txtBox.UniqueID, true));

                    //txtBox = (TextBox)dataItem.FindControl("RadTextBox4");
                    //numericSetting1.TargetControls.Add(new TargetInput(txtBox.UniqueID, true));

                    //txtBox = (TextBox)dataItem.FindControl("RadTextBox5");
                    //numericSetting1.TargetControls.Add(new TargetInput(txtBox.UniqueID, true));

                    //txtBox = (TextBox)dataItem.FindControl("RadTextBox6");
                    //numericSetting1.TargetControls.Add(new TargetInput(txtBox.UniqueID, true));

                    //txtBox = (TextBox)dataItem.FindControl("RadTextBox7");
                    //numericSetting1.TargetControls.Add(new TargetInput(txtBox.UniqueID, true));
                }
            }
            protected void RadAjaxManager1_AjaxRequest(object sender, Telerik.Web.UI.AjaxRequestEventArgs e)
            {
                if (e.Argument == string.Empty)
                {
                    gvwTimeSheet.Rebind();
                }
                string[] editedItemIds = e.Argument.Split(':');
                int i;
                for (i = 0; i <= editedItemIds.Length - 2; i++)
                {
                    string productId = editedItemIds[i];
                    GridDataItem updatedItem = gvwTimeSheet.MasterTableView.FindItemByKeyValue("ID", int.Parse(productId));

                    UpdateValues(updatedItem);
                }
            }
            protected void UpdateValues(GridDataItem updatedItem)
            {
                TextBox txtBox1 = (TextBox)updatedItem.FindControl("RadTextBox1");
                TextBox txtBox2 = (TextBox)updatedItem.FindControl("RadTextBox2");
                TextBox txtBox3 = (TextBox)updatedItem.FindControl("RadTextBox3");
                TextBox txtBox4 = (TextBox)updatedItem.FindControl("RadTextBox4");
                TextBox txtBox5 = (TextBox)updatedItem.FindControl("RadTextBox5");
                TextBox txtBox6 = (TextBox)updatedItem.FindControl("RadTextBox6");
                TextBox txtBox7 = (TextBox)updatedItem.FindControl("RadTextBox7");
                //DropDownList ddl = (DropDownList)updatedItem.FindControl("ddlUnitsInStock");
                //CheckBox chkBox = (CheckBox)updatedItem.FindControl("chkBoxDiscontinued");

                SetMessage("Product with ID: " + updatedItem.GetDataKeyValue("ProductID") + " updated");
            }
         
        }
    }

  5. Ravi Kumar
    Ravi Kumar avatar
    37 posts
    Member since:
    May 2010

    Posted 16 Jul 2010 Link to this post

    Hi

    i got the problem where i was stuck. actually i had CommandItemDisplay="Top" thats why   "var headerRow = tHeadElement.getElementsByTagName("tr")[0];" was not able  to find the "Column name" of the radgridview.

    But if want to show CommandItemDisplay="Top" then how do i get resolve the problem.

    Thanks
    Ravi
  6. Ravi Kumar
    Ravi Kumar avatar
    37 posts
    Member since:
    May 2010

    Posted 16 Jul 2010 Link to this post

    Hi

    Is it possible to do aggregate column's cell in footer column using java script.

    please find the attached screen to understand the problem.


    regards
    ravi
  7. Radoslav
    Admin
    Radoslav avatar
    1564 posts

    Posted 22 Jul 2010 Link to this post

    Hi Ravi,

    Regarding the question in your previous post, about the headerRow:

    In order to achieve the desired functionality when the CommandItemDisplay property is set to Top, you could try using the following line of code for finding the headerRow:
    var headerRow = tHeadElement.getElementsByTagName("tr")[1];

    With respect to the question in your last post:

    The RadGrid does not support the desired functionality. Also there is no simple way to do aggregate column's cell in footer column. To achieve it you could try iterate over the RadGrid cells into the <tbody> and <tfoot> elements and calculate or assign values to them.

    I hope this helps.

    Regards,
    Radoslav
    the Telerik team
    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 Public Issue Tracking system and vote to affect the priority of the items
  8. Brian
    Brian avatar
    1 posts
    Member since:
    May 2011

    Posted 25 May 2011 Link to this post

    Ravi,

    I am looking to make the exact same RadGrid.  When i found your post I was thrilled that someone has already done this with RadGrid.

    Can you direct me to your latest code that helped solve your DataBinding and Grid Setup?

    Thanks,

    Brian
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017