Telerik Forums
UI for ASP.NET AJAX Forum
1 answer
43 views
Hi

i'm making radgrid in batch mode. and there is a columns using radcombobox in edititemtempete. - COLUMN_A

here's a problem. there is select box outside the grid. and if the select box's value is changed. 

I try to make the  whole COLUMN_A 's value is changing. 


<select id="SelColumnA" runat="server" onchange="jf_st_read_sel();" style="width:125px">
         <option title="VALUE01">TEXT1</option>
         <option title="VALUE02">TEXT2</option>
         <option title="VALUE02">TEXT2</option>
</select>
 
<telerik:RadGrid ID="RadGrid1" OnNeedDataSource="RadGrid1_DataSource" AllowSorting="false"
            AllowAutomaticUpdates="true" Skin="Office2010Silver" OnBatchEditCommand="RadGrid1_BatchEditCommand"
            OnItemDataBound="RadGrid1_ItemDataBound" AutoGenerateColumns="false" runat="server">
            <ClientSettings Scrolling-AllowScroll="False" EnableRowHoverStyle="True">
                <Selecting AllowRowSelect="True" />
                <Resizing AllowColumnResize="true" />
                <Scrolling AllowScroll="true" UseStaticHeaders="True" ScrollHeight=""/>
            </ClientSettings>
        <MasterTableView DataKeyNames="MENUID" EditMode="Batch"
            CommandItemDisplay="Top" AutoGenerateColumns="False"
            BatchEditingSettings-OpenEditingEvent="Click" CssClass="mst_table">
                <Columns>
                    <telerik:GridTemplateColumn ItemStyle-HorizontalAlign="Center" FilterControlAltText="Filter MENUID column" HeaderText="MENUID" ="MENUID" UniqueName="MENUID" DataField="MENUID">
                        <ItemTemplate>
                            <asp:Label ID="lb_MENUID" runat="server" Text='<%# Eval("MENUID")%>'></asp:Label>
                        </ItemTemplate>
                        <HeaderStyle Width="40px" />
                        <ItemStyle HorizontalAlign="Center" />
                    </telerik:GridTemplateColumn>
                    <telerik:GridTemplateColumn HeaderText="COLUMN_A" HeaderStyle-Width="100px" FilterControlAltText="Filter COLUMN_A column"
                        UniqueName="COLUMN_A" DataField="COLUMN_A" >
                        <ItemTemplate>
                            <asp:Label ID="lb_COLUMN_A_NAME" runat="server" Text='<%# Eval("COLUMN_A_NAME")%>'></asp:Label>
                        </ItemTemplate>
                        <EditItemTemplate>
                            <telerik:RadComboBox ID="COLUMN_A_CodeComboBox" runat="server" OnPreRender="COLUMN_A_CodeComboBox_OnPreRender" Width="100px"  >
                            </telerik:RadComboBox>
                        </EditItemTemplate>
                    </telerik:GridTemplateColumn>
                </Columns>
            </MasterTableView>
        </telerik:RadGrid>


i can change label - lb_COLUMN_A_NAME .Text  in server side. like the following.  but it's not chaging value(?) . 
the actual value that saved in database is a code, and the text on column is a name. it's not same. 

so i don't know how can i,  and where can i put this value on.

protected void SelectBoxValueChanged(object sender, EventArgs e)
        {
            for (int i = 0; i < this.RadGrid1.Items.Count; i++)
            {
                (this.RadGrid1.Items[i].FindControl("lb_COLUMN_NAME") as Label).Text = this.SelColumnA.Items[SelColumnA
.SelectedIndex].Text;
                }
            }
        }



and in the end on the BatchEditCommand to save, it doesn't have changes so it has no command. 


please let me solve this problem. you brilliant handsomes guys~


thank you~~
Konstantin Dikov
Telerik team
 answered on 23 Oct 2013
2 answers
627 views
Hi All,

I have been searching for a fix for this issue but I dont feel im getting very far.

I have a grid with a DetailTables/GridTableView to expand the rows.

The grid is bound to a list of objects, these objects has a property which is another list of objects which holds the 'Code' property.

This issue does not happen on our dev servers, only on the production server.

Markup

<telerik:radgrid id="grdData" height="400px" width="100%" runat="server"
                        pagesize="50" showstatusbar="True" allowmultirowselection="False" allowpaging="True"
                        autogeneratecolumns="False" allowsorting="true" gridlines="None" cssclass="gridControl"
                        onneeddatasource="OnNeedDataSource" ondetailtabledatabind="RadGrid1_grdData"
                        onprerender="grdStudentsData_PreRender">
                        <pagerstyle mode="NumericPages"></pagerstyle>
                        <clientsettings allowcolumnsreorder="False" reordercolumnsonclient="False">
                            <Scrolling AllowScroll="True" UseStaticHeaders="True" />
                        </clientsettings>
                        <mastertableview width="98%" summary="Data" clientdatakeynames="PropertyA, PropertyB, PropertyC, PropertyD, PropertyE">
                            <DetailTables>
                                <telerik:GridTableView AutoGenerateColumns="false" DataKeyNames="Code,DisplayValue" Width="100%">
                                    <Columns>
                                        <telerik:GridBoundColumn AllowFiltering="False" AllowSorting="False" DataField="DisplayValue"
                                            Display="True" HeaderText="Display Value" ReadOnly="True" Reorderable="True" Resizable="True"
                                            ShowSortIcon="False" UniqueName="DisplayValue" Visible="True">
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn AllowFiltering="False" AllowSorting="False" DataField="Code"
                                            Display="True" HeaderText="Code" ReadOnly="True" Reorderable="False" Resizable="True"
                                            ShowSortIcon="False" UniqueName="Code" Visible="True">
                                        </telerik:GridBoundColumn>
                                    </Columns>
                                </telerik:GridTableView>
                            </DetailTables>
                            <Columns>
                                <telerik:GridBoundColumn AllowFiltering="False" AllowSorting="False" DataField="PropertyA"
                                    Display="True" HeaderText="PropertyA" ReadOnly="True" Reorderable="True" Resizable="True"
                                    ShowSortIcon="False" UniqueName="Entity" Visible="True">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn AllowFiltering="False" AllowSorting="False" DataField="PropertyB"
                                    Display="True" HeaderText="PropertyB" ReadOnly="True" Reorderable="False"
                                    Resizable="True" ShowSortIcon="False" UniqueName="CodeAttribute" Visible="True">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn AllowFiltering="False" AllowSorting="False" DataField="PropertyC"
                                    Display="True" HeaderText="PropertyC" ReadOnly="True" Reorderable="True"
                                    Resizable="True" ShowSortIcon="False" UniqueName="DescriptionAttribute" Visible="true">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn AllowFiltering="False" AllowSorting="False" DataField="PropertyD"
                                    Display="True" HeaderText="PropertyD" ReadOnly="True" Reorderable="True"
                                    Resizable="True" ShowSortIcon="False" UniqueName="OptionAttribute" Visible="true">
                                </telerik:GridBoundColumn>
                            </Columns>
                        </mastertableview>
                    </telerik:radgrid>

Error

DataBinding: 'Object' does not contain a property with the name 'Code'.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: DataBinding: 'Object' does not contain a property with the name 'Code'.

Stack Trace:

[HttpException (0x80004005): DataBinding: 'Object' does not contain a property with the name 'Code'.]
   System.Web.UI.DataBinder.GetPropertyValue(Object container, String propName) +11394950
   Telerik.Web.UI.GridTableView.PopulateDataKeys(Object dataItem) +409
 
[GridException: There was a problem extracting DataKeyValues from the DataSource. Please ensure that DataKeyNames are specified correctly and all fields specified exist in the DataSource.]
   Telerik.Web.UI.GridTableView.PopulateDataKeys(Object dataItem) +1060
   Telerik.Web.UI.GridItemBuilder.CreateItems(GridGroupingContext group) +411
   Telerik.Web.UI.GridTableView.CreateControlHierarchy(Boolean useDataSource) +1169
   Telerik.Web.UI.GridTableView.CreateChildControls(IEnumerable dataSource, Boolean useDataSource) +873
   System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data) +94
   System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data) +182
   System.Web.UI.WebControls.DataBoundControl.PerformSelect() +274
   Telerik.Web.UI.GridTableView.DataBind() +432
   Telerik.Web.UI.GridDataItem.OnExpand() +461
   Telerik.Web.UI.GridItem.set_Expanded(Boolean value) +295
   Telerik.Web.UI.RadCompositeDataBoundControl.OnPreRender(EventArgs e) +46
   System.Web.UI.Control.PreRenderRecursiveInternal() +113
   System.Web.UI.Control.PreRenderRecursiveInternal() +222
   System.Web.UI.Control.PreRenderRecursiveInternal() +222
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4201

Anyone got any advice.

This happens as the grid/page loads.

Thanks
Ben
Eyup
Telerik team
 answered on 23 Oct 2013
1 answer
284 views
Hi All,

I am using .Net 4.0 [Visual Studio 2010], Telerik version 2013.

I am facing an issue with the Rad Context menu, when I try to call the RadContextMenu using the "onmouseup" event it is not working. Actually the menu is coming and disappearing immediately. But the same code is working for "onclick" and other events.

Is there any issue with RadContextMenu in 2103 Telerik version. Please help me to resolve. 

Below the code which I used to call the menu,

<form id="form1" runat="server">
     <asp:ScriptManager runat="server" ID="asps"></asp:ScriptManager>
    <div onmouseup="showMenu(event)" runat="server" onmouseup="return false" id="div1">
    <asp:Literal ID="literal1" runat="server">
    This is sample text to test the Rad context menu
    </asp:Literal>
     <telerik:RadContextMenu ID="RadContextMenu1" runat="server"
                    EnableRoundedCorners="true" EnableShadows="true">
                    <Items>
                         <telerik:RadMenuItem Text="Trees" />
                         <telerik:RadMenuItem Text="Sunset" />
                         <telerik:RadMenuItem Text="Mountains" />
                    </Items>
               </telerik:RadContextMenu>
    </div>
    <telerik:RadScriptBlock runat="server">
          <script type="text/javascript">
          function showMenu(e) {
               var contextMenu = $find("<%= RadContextMenu1.ClientID %>");
 
               $telerik.cancelRawEvent(e);
 
               if ((!e.relatedTarget) || (!$telerik.isDescendantOrSelf(contextMenu.get_element(), e.relatedTarget))) {
                    contextMenu.show(e);
               }
          }
      </script>
     </telerik:RadScriptBlock>
    </form>


Thanks in advance.
Dimitar Terziev
Telerik team
 answered on 23 Oct 2013
1 answer
94 views
Hi, i'm using Telerik OrgChart in a asp.net page and i want to do one of this two thigs:

Insert an image on every node with an icon to edit the node;

Or by double-clicking in the node call a function (server-side) to edit the node.

Anyone can help me?
Bruno F.

Peter Filipov
Telerik team
 answered on 23 Oct 2013
2 answers
182 views
Hi,
 I have a Radlistview of my own UserControls.

 Inside the RadListview i have some paging buttons. Either when the ItemCommand is fired (and it equals("Page")) or when the PageIndexChanged event is fired, i need to access my UserControls on this page.

The why: currently, each of my user controls have a Save button. That works fine. however, my client would now like all of my user controls to be saved when they hit any of the paging buttons.
How can i do that? I can't figure out how to access my DataItems (UserControlClass) from within either the PageIndexChanged or ItemCommand Events - partly because the paging buttons are themselves not a Usercontrol.

<telerik:RadListView ID="lvWorkGroups" runat="server"
        DataKeyNames="ID, Name"
        OnItemDataBound="lvWorkGroups_ItemDataBound"
        onneeddatasource="lvWorkGroups_NeedDataSource"
        AllowPaging="True" PageSize="1"
        ItemPlaceholderID="PlaceHolder1"
         onpageindexchanged="lvWorkGroups_PageIndexChanged"
         onpagesizechanged="lvWorkGroups_PageSizeChanged"
         ondatabound="lvWorkGroups_DataBound"
          onitemcommand="lvWorkGroups_ItemCommand">
         
        <LayoutTemplate>
                <asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
 
                <div class="workGroup2" style="text-align:center">
                    <div style="margin:auto;">
                        <asp:Button runat="server" ID="btnFirst" CommandName="Page" CommandArgument="First"
                            Text="First" Enabled="<%#Container.CurrentPageIndex > 0 %>" CausesValidation="false"></asp:Button>
                        <asp:Button runat="server" ID="btnPrev" CommandName="Page" CommandArgument="Prev"
                            Text="Prev" Enabled="<%#Container.CurrentPageIndex > 0 %>" CausesValidation="false"></asp:Button>
                        <span style="vertical-align: middle; line-height:22px; display:inline-block;">Page
                            <%#Container.CurrentPageIndex + 1 %>
                            of
                            <%#Container.PageCount %></span>
                        <asp:Button runat="server" ID="btnNext" CommandName="Page" CommandArgument="Next"
                            Text="Next" Enabled="<%#Container.CurrentPageIndex + 1 < Container.PageCount %>" CausesValidation="false">
                        </asp:Button>
                        <asp:Button runat="server" ID="btnLast" CommandName="Page" CommandArgument="Last"
                            Text="Last" Enabled="<%#Container.CurrentPageIndex + 1 < Container.PageCount %>" CausesValidation="false">
                        </asp:Button>
                    </div>
                </div>
        </LayoutTemplate>
 
        <ItemTemplate>
           <uc1:InspectionWorkGroup ID="InspectionWorkGroup1" runat="server" OnworkGroupSaved="wg_workGroupSaved"/>
        </ItemTemplate>
    </telerik:RadListView>
Eyup
Telerik team
 answered on 23 Oct 2013
1 answer
81 views
Hello Telerik Team,

I am trying to export the values of the child of a RadGrid but it shows "No child records to display" when use gvDoNotCall.MasterTableView.HierarchyDefaultExpanded = true

I attached the code and an image of the grid

Thank you very much


<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true"
    CodeFile="DoNotCall.aspx.cs" Inherits="DoNotCall" %>

<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<%@ Import Namespace="Com.PromptAlert.PAPortalCommon" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<style type="text/css">
       .strikethrough
       {
        text-decoration: line-through;
       }
        .rightalign
       {
            float:right;
       }

   </style>
   <script type="text/javascript">
        $(document).ready(function () {

            //We obtain the button we want to hit as default
            $(document).keypress(function (e) {
                var defaultButton = $("[id$=bnSearch]");
                setEnterValue(e, defaultButton);
            });
        });
    </script>


    <telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">
        <script type="text/javascript">
            function onRequestStart(sender, args) {
                if (args.get_eventTarget().indexOf("ExportToExcelButton") >= 0 ||
                               args.get_eventTarget().indexOf("ExportToWordButton") >= 0 ||
                               args.get_eventTarget().indexOf("ExportToPdfButton") >= 0) {
                    args.set_enableAjax(false);
                    if (!confirm("You are exporting information potentially containing Protected Health Information (PHI) and/or Personally Identifiable Information (PII). Please click OK to proceed or Cancel to return to the previous screen")) { return false; }
                }
            }    
        </script>
    </telerik:RadScriptBlock>


    <h1 class="page-title">
        Do Not Call List</h1>
    <div class="box">
        <%--<telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" LoadingPanelID="RadAjaxLoadingPanel1">--%>

        
            <div class="field-box" id="valSumm">
                <asp:ValidationSummary CssClass="error-label" ID="valSummary" runat="server" HeaderText="The following errors occurred on the page: ">
                </asp:ValidationSummary>
            </div>

            <div class="field-box">
                <asp:Label CssClass="left-field" ID="lblSearchPhoneNumber" runat="server" Text="Search Phone Number:"></asp:Label>
                <asp:TextBox CssClass="right-field"  runat="server" ID="txtSearchPhoneNumber" ValidationGroup="vgroup2"></asp:TextBox>
                <span>*&nbsp;
                    <asp:RegularExpressionValidator CssClass="error-label" ID="regexPhone1" runat="server" ValidationExpression="^(\([2-9]\d{2}\)|[2-9]\d{2})[- .]?\d{3}[- .]?\d{4}$" ValidationGroup="vgroup2"
                        ControlToValidate="txtSearchPhoneNumber" ErrorMessage="Invalid Phone Format" Display="Dynamic"></asp:RegularExpressionValidator>
                    <asp:RequiredFieldValidator CssClass="error-label" ID="rfPhone1" runat="server" ErrorMessage="Please enter a valid phone number" ValidationGroup="vgroup2"
                        ControlToValidate="txtSearchPhoneNumber" Display="Dynamic"></asp:RequiredFieldValidator>
                </span>
                
            </div>
            <div class="field-box">
                <asp:Button runat="server" Text="Search" CssClass="action-button left-field" value="Search" ID="bnSearch" ValidationGroup="vgroup2" OnClick="bnSearch_Click"/>
                <asp:Button runat="server" Text="Clear Search" CssClass="action-button right-field" value="ClearSearch" ID="bnClearSearch" CausesValidation="false" OnClick="bnClearSearch_Click"/>
                <asp:Label CssClass="rightalign"  ID="Label1" runat="server" Text="Strike through phone number is <div style='display: inline-block;color:red;'>NOT</div> included in Do Not Call list"></asp:Label>
            </div>

            <telerik:RadAjaxPanel ID="RadAjaxPanel2" runat="server"  ClientEvents-OnRequestStart="onRequestStart">
            <telerik:RadGrid ID="gvDoNotCall" runat="server" AllowFilteringByColumn="false" AllowPaging="True"
                AllowSorting="True" CellSpacing="0" GridLines="None" PageSize="10" OnNeedDataSource="gvDoNotCall_NeedDataSource"
                AutoGenerateColumns="false" OnItemCommand="gvDoNotCall_ItemCommand" OnDeleteCommand="gvDoNotCall_DeleteCommand" OnItemDataBound="gvDoNotCall_ItemDataBound"
                OnInsertCommand="gvDoNotCall_InsertCommand" OnUpdateCommand="gvDoNotCall_UpdateCommand" OnItemCreated="gvDoNotCall_ItemCreated" AutoGenerateHierarchy="true"
                OnPageIndexChanging="gvDoNotCall_PageIndexChanging">
                
                <ClientSettings>
                    <Selecting AllowRowSelect="True" />
                </ClientSettings>
                <MasterTableView DataKeyNames="Id" ClientDataKeyNames="Id" CommandItemDisplay="Top" InsertItemPageIndexAction="ShowItemOnCurrentPage">
                    <DetailTables>
                        <telerik:GridTableView Name="tblClients" DataKeyNames="HomePhone"
                            Width="100%" NoDetailRecordsText="No Client for this number"
                            AllowFilteringByColumn="false" AllowPaging="false">

                            <Columns>
                                <telerik:GridBoundColumn UniqueName="ClientRecordNumber" HeaderText="MRN" DataField="ClientRecordNumber" />
                                <telerik:GridBoundColumn UniqueName="FirstName" HeaderText="Client First Name"
                                    DataField="FirstName" />
                                <telerik:GridBoundColumn UniqueName="LastName" HeaderText="Client Last Name"
                                    DataField="LastName" />
                                <telerik:GridDateTimeColumn UniqueName="DateOfBirth" HeaderText="Date Of Birth" DataField="DateOfBirth"
                                    AllowFiltering="false" DataFormatString="{0:dd MMM yyyy}" />
                                <telerik:GridBoundColumn UniqueName="PrimaryNumber" HeaderText="Primary Number"
                                    DataField="PrimaryNumber" />
                                <telerik:GridBoundColumn UniqueName="SecondaryNumber" HeaderText="Secondary Number"
                                    DataField="SecondaryNumber" />
                                <telerik:GridBoundColumn UniqueName="MatchedNumber" HeaderText="Matched Number" Display="false"
                                    DataField="MatchedNumber" />
                                <telerik:GridBoundColumn UniqueName="MatchedBoth" HeaderText="Matched Both" Display="false"
                                    DataField="MatchedBoth" />
                            </Columns>
                        </telerik:GridTableView>
                    </DetailTables>
                    <Columns>
                        <telerik:GridButtonColumn UniqueName="EditButtonId" ButtonCssClass="edit-button"  ButtonType="ImageButton" CommandName="Edit" HeaderText="Edit" ImageUrl="../App_Themes/Modern/images/edit-button.png" HeaderStyle-Width="100px" ItemStyle-HorizontalAlign="Center" ItemStyle-VerticalAlign="Middle" HeaderStyle-HorizontalAlign="Center"/>
                        <telerik:GridButtonColumn UniqueName="DeleteButtonId" ButtonCssClass="delete-button" HeaderText="Delete" ConfirmText="Delete this do not call entry?" ConfirmDialogType="Classic"  HeaderStyle-HorizontalAlign="Center"
                            ConfirmTitle="Delete" ButtonType="ImageButton" CommandName="Delete" ConfirmDialogHeight="100px" ItemStyle-HorizontalAlign="Center" ItemStyle-VerticalAlign="Middle"
                            ConfirmDialogWidth="220px" ImageUrl="../App_Themes/Modern/images/delete-button.png" HeaderStyle-Width="100px" />
                        <telerik:GridBoundColumn UniqueName="Id" HeaderText="Id" DataField="Id" ReadOnly="true" 
                            Visible="false" />
                        <telerik:GridTemplateColumn UniqueName="PhoneNumber" HeaderText="Phone Number" DataField="PhoneNumber">
                            <ItemTemplate>
                                <asp:Label runat="server" ID="lblPhoneNumber" Text='<%# Eval("PhoneNumber") %>'></asp:Label>
                            </ItemTemplate>
                            <EditItemTemplate>
                                <asp:TextBox runat="server" ID="txtPhoneNumber" Text='<%# Bind("PhoneNumber") %>' ValidationGroup="vgroup1"></asp:TextBox>
                                <span>*&nbsp;
                                    <asp:RegularExpressionValidator CssClass="error-label" ID="regexPhone2" runat="server" ValidationExpression="^(\([2-9]\d{2}\)|[2-9]\d{2})[- .]?\d{3}[- .]?\d{4}$" ValidationGroup="vgroup1"
                                        ControlToValidate="txtPhoneNumber" ErrorMessage="Invalid Phone Format" Display="Dynamic"></asp:RegularExpressionValidator>
                                    <asp:RequiredFieldValidator CssClass="error-label" ID="rfPhone2" runat="server" ErrorMessage="Please enter a valid phone number" ValidationGroup="vgroup1"
                                        ControlToValidate="txtPhoneNumber" Display="Dynamic"></asp:RequiredFieldValidator>
                                </span>
                            </EditItemTemplate>
                        </telerik:GridTemplateColumn>
                        <telerik:GridTemplateColumn UniqueName="LastUpdatedBy" HeaderText="Last Updated By"
                            DataField="LastUpdatedUserId">
                            <ItemTemplate>
                                <asp:Label runat="server" ID="LastUpdatedUserId" Text='<%# Utility.GetUserNameByIdStaff(Convert.ToInt32(Eval("LastUpdatedUserId"))) %>'></asp:Label>
                            </ItemTemplate>
                        </telerik:GridTemplateColumn>
                        <telerik:GridBoundColumn UniqueName="LastUpdatedDateTime" HeaderText="Last Updated Date"
                            DataField="LastUpdatedDateTime" ReadOnly="true" />

                        <telerik:GridTemplateColumn UniqueName="InsertButton" HeaderText="">
                            <EditItemTemplate>
                                <%--<asp:TextBox runat="server" ID="txtPhoneNumber" Text='<%# Bind("PhoneNumber") %>'></asp:TextBox>--%>
                                 <asp:Button ID="btSaveNew" runat="server" CssClass="action-button" Text="Save and New" CommandName="SaveNew" Visible="false" ValidationGroup="vgroup1"></asp:Button>
                                 <asp:Button ID="btSaveClose" runat="server" CssClass="action-button" Text="Save and Close" CommandName="SaveClose" Visible="false" ValidationGroup="vgroup1"></asp:Button>
                                 <asp:Button ID="btCancel" runat="server" CssClass="action-button" Text="Cancel" CommandName="CancelButton" Visible="false" CausesValidation="false"></asp:Button>
                            </EditItemTemplate>
                        </telerik:GridTemplateColumn>
                    </Columns>


                    <CommandItemSettings ShowExportToExcelButton="true" ShowExportToWordButton="true"
                        ShowExportToPdfButton="true" ShowAddNewRecordButton="true" ShowRefreshButton="true" />




                    <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column">
                        <HeaderStyle Width="20px"></HeaderStyle>
                    </RowIndicatorColumn>
                    <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column">
                        <HeaderStyle Width="20px"></HeaderStyle>
                    </ExpandCollapseColumn>
                    <EditFormSettings>
                        <EditColumn FilterControlAltText="Filter EditCommandColumn column">
                        </EditColumn>
                    </EditFormSettings>
                </MasterTableView>


                <ExportSettings ExportOnlyData="true" IgnorePaging="true" OpenInNewWindow="true">
                    <Excel Format="Html" />
                </ExportSettings>


                <FilterMenu EnableImageSprites="False">
                </FilterMenu>
                <HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default">
                </HeaderContextMenu>
                <ValidationSettings CommandsToValidate="PerformInsert,Update" />
            </telerik:RadGrid>
        </telerik:RadAjaxPanel>
        <telerik:RadWindowManager runat="server" ID="RadWindowManager1" Title="PatientPrompt.com"
            InitialBehaviors="Default" KeepInScreenBounds="true">
        </telerik:RadWindowManager>
        <%--<telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" />--%>
    </div>
</asp:Content>


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

// logging imports
using log4net;
using log4net.Appender;
using log4net.Config;

using Telerik.Web.UI;

using Com.PromptAlert.PAPortalCommon.Dao;
using Com.PromptAlert.PAPortalCommon;
using Com.PromptAlert.PAPortalCommon.Domain;
using DoNotCallOjb = Com.PromptAlert.Domain.DoNotCall;

public partial class DoNotCall : System.Web.UI.Page
{
    // define loggers
    public static readonly ILog log = LogManager.GetLogger("Account_DoNotCall.aspx.cs");

    private bool isExport = false;

    protected void Page_Load(object sender, EventArgs e)
    {

        if (!Page.IsPostBack)
        {
            FillGrid();
        }

        //LinkButton UpdateButton = (LinkButton)e.Item.FindControl("UpdateButton");
        txtSearchPhoneNumber.Attributes.Add("onkeydown", "if(event.which || event.keyCode){if ((event.which == 13) || (event.keyCode == 13)) {document.getElementById('" + bnSearch.ClientID + "').click();return false;}} else {return true}; ");
        
    }



    protected void gvDoNotCall_ItemCommand(object source, GridCommandEventArgs e)
    {
        if (e.CommandName.Contains("Export"))
        {
            isExport = true;
            gvDoNotCall.MasterTableView.GetColumn("EditButtonId").Visible = false;
            gvDoNotCall.MasterTableView.GetColumn("DeleteButtonId").Visible = false;


           // gvDoNotCall.MasterTableView.HierarchyDefaultExpanded = true;
        
        }

        

        if (e.CommandName.Contains("SaveClose"))
        {
            if (e.Item is GridEditableItem)
            {
                GridEditableItem item = e.Item as GridEditableItem;
                DoNotCallOjb dnc = new DoNotCallOjb();
                item.UpdateValues(dnc);
                AccountDAO.AddDoNotCall(Convert.ToInt32(Session["AccountId"]), dnc.PhoneNumber, Convert.ToInt32(Session["PortalUserId"]));
                //gvDoNotCall.MasterTableView.IsItemInserted = true;
                //FillGrid();
                Response.Redirect("~/dashboard");
            }
        }

        if (e.CommandName.Contains("SaveNew"))
        {
            if (e.Item is GridEditableItem)
            {
                GridEditableItem item = e.Item as GridEditableItem;
                DoNotCallOjb dnc = new DoNotCallOjb();
                item.UpdateValues(dnc);
                AccountDAO.AddDoNotCall(Convert.ToInt32(Session["AccountId"]), dnc.PhoneNumber, Convert.ToInt32(Session["PortalUserId"]));
                gvDoNotCall.MasterTableView.IsItemInserted = true;
                //gvDoNotCall.MasterTableView.IsItemInserted = true;
                FillGrid();
            }
            //else
            //{
            //    var idx = int.Parse(e.CommandArgument.ToString());

            //    GridEditableItem item = gvDoNotCall.Items[idx];
            //    DoNotCallOjb dnc = new DoNotCallOjb();
            //    item.UpdateValues(dnc);
            //    AccountDAO.AddDoNotCall(Convert.ToInt32(Session["AccountId"]), dnc.PhoneNumber, Convert.ToInt32(Session["PortalUserId"]));
            //    gvDoNotCall.MasterTableView.IsItemInserted = true;
            //    //gvDoNotCall.MasterTableView.IsItemInserted = true;
            //    FillGrid();
            //}
        }

        if (e.CommandName.Contains("CancelButton"))
        {
            if (e.Item is GridEditableItem)
            {
                GridEditableItem item = e.Item as GridEditableItem;
                item.Edit = false;
                gvDoNotCall.MasterTableView.Rebind();
            }
        }
    }

    protected void gvDoNotCall_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
    {
        DataSet dsDoNotCall = (DataSet)Session["gvDoNotCall_dtDoNotCall"];
        if (dsDoNotCall != null)
        {
            gvDoNotCall.DataSource = dsDoNotCall;
        }
        
        
    }


    public void FillGrid()
    {

        DataSet dsDoNotCall = AccountDAO.GetDoNotCall(Convert.ToInt32(Session["AccountId"]));
        gvDoNotCall.DataSource = dsDoNotCall;
        gvDoNotCall.DataBind();
        Session["gvDoNotCall_dtDoNotCall"] = dsDoNotCall;
    }

    protected void gvDoNotCall_UpdateCommand(object sender, GridCommandEventArgs e)
    {
        var editableItem = ((GridEditableItem)e.Item);
        var id = (int)editableItem.GetDataKeyValue("Id");
        //int id = Convert.ToInt32(editableItem["Id"].Text);
        DoNotCallOjb dnc = new DoNotCallOjb();
        editableItem.UpdateValues(dnc);
        log.Debug("Calling UpdateDoNotCall. Id = " + id + ", dnc.PhoneNumber = " + dnc.PhoneNumber);

        DataSet dsDoNotCall = AccountDAO.GetDoNotCallByPhoneNumber(Convert.ToInt32(Session["AccountId"]), dnc.PhoneNumber);
        if (dsDoNotCall.Tables[0].Rows.Count == 0)
        {
            AccountDAO.UpdateDoNotCall(Convert.ToInt32(Session["AccountId"]), id, dnc.PhoneNumber, Convert.ToInt32(Session["PortalUserId"]));
            FillGrid();
        }
        else
        {
            ErrorSummary.AddError("The number " + dnc.PhoneNumber + " is already in do not call list!", this);
            return;
        }
    }

    protected void gvDoNotCall_InsertCommand(object sender, GridCommandEventArgs e)
    {
        GridEditableItem item = e.Item as GridEditableItem;
        DoNotCallOjb dnc = new DoNotCallOjb();
        item.UpdateValues(dnc);
        DataSet dsDoNotCall = AccountDAO.GetDoNotCallByPhoneNumber(Convert.ToInt32(Session["AccountId"]), dnc.PhoneNumber);
        if (dsDoNotCall.Tables[0].Rows.Count == 0)
        {
            AccountDAO.AddDoNotCall(Convert.ToInt32(Session["AccountId"]), dnc.PhoneNumber, Convert.ToInt32(Session["PortalUserId"]));
            //gvDoNotCall.MasterTableView.IsItemInserted = true;
            FillGrid();
        }
        else
        {
            ErrorSummary.AddError("The number " + dnc.PhoneNumber + " is already in do not call list!", this);
            return;
        }
        //gvDoNotCall.MasterTableView.Rebind();
        
        //gvDoNotCall.Rebind();
    }

    protected void gvDoNotCall_DeleteCommand(object sender, GridCommandEventArgs e)
    {
        var editableItem = ((GridDataItem)e.Item);
        var id = (int)editableItem.GetDataKeyValue("Id");
        //int id = Convert.ToInt32(editableItem["Id"].Text);
        AccountDAO.DeleteDoNotCall(Convert.ToInt32(Session["AccountId"]), id);
        FillGrid();
    }

    protected void gvDoNotCall_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)
    {
        if (e.Item is GridEditableItem && e.Item.IsInEditMode)
        {
            GridEditableItem item = (GridEditableItem)e.Item;
            TextBox tbPhone = (TextBox)item.FindControl("txtPhoneNumber");
            tbPhone.Focus();
            if (e.Item is GridEditFormInsertItem || e.Item is GridDataInsertItem)
            {
                
                LinkButton InsertButton = (LinkButton)e.Item.FindControl("PerformInsertButton");
                InsertButton.CssClass = "action-button";
                InsertButton.Visible = false;

                LinkButton cancelButton = (LinkButton)e.Item.FindControl("CancelButton");
                cancelButton.CssClass = "action-button";
                cancelButton.Visible = false;

                Button SaveNewButton = (Button)e.Item.FindControl("btSaveNew");
                SaveNewButton.Visible = true;
                Button SaveCloseButton = (Button)e.Item.FindControl("btSaveClose");
                SaveCloseButton.Visible = true;
                Button CancelButton = (Button)e.Item.FindControl("btCancel");
                CancelButton.Visible = true;
                
            }
            else
            {
                LinkButton UpdateButton = (LinkButton)e.Item.FindControl("UpdateButton");
                UpdateButton.CssClass = "action-button";
                //Page.Form.DefaultButton = UpdateButton.ClientID;
                LinkButton cancelButton = (LinkButton)e.Item.FindControl("CancelButton");
                cancelButton.CssClass = "cancel-button";
            }
            
        }
    }

    protected void gvDoNotCall_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridEditableItem && e.Item.IsInEditMode)
        {
            GridEditableItem item = (GridEditableItem)e.Item;
            TextBox tbPhone = (TextBox)item.FindControl("txtPhoneNumber");
            if (e.Item is GridEditFormInsertItem || e.Item is GridDataInsertItem)
            {
                Button SaveNewButton = (Button)e.Item.FindControl("btSaveNew");
                tbPhone.Attributes.Add("onkeydown", "if(event.which || event.keyCode){if ((event.which == 13) || (event.keyCode == 13)) {document.getElementById('" + SaveNewButton.ClientID + "').click();return false;}} else {return true}; ");
            }
            else
            {
                LinkButton UpdateButton = (LinkButton)e.Item.FindControl("UpdateButton");
                tbPhone.Attributes.Add("onkeydown", "if(event.which || event.keyCode){if ((event.which == 13) || (event.keyCode == 13)) {document.getElementById('" + UpdateButton.ClientID + "').click();return false;}} else {return true}; ");

            }
        }

        if (e.Item is GridDataItem && e.Item.OwnerTableView.Name == "Table1")
        {
            GridDataItem item = (GridDataItem)e.Item;
            GridTableCell PNumber = (GridTableCell)item["PrimaryNumber"];
            GridTableCell SNumber = (GridTableCell)item["SecondaryNumber"];
            GridTableCell cell = (GridTableCell)item["MatchedNumber"];
            GridTableCell cell1 = (GridTableCell)item["MatchedBoth"];
            if (cell1.Text == "1")
            {
                PNumber.CssClass = "strikethrough";
                SNumber.CssClass = "strikethrough";
                PNumber.ToolTip = "Number on Do Not Call list";
                SNumber.ToolTip = "Number on Do Not Call list";
                
            }
            else
            {
                if (cell.Text == PNumber.Text)
                {
                    PNumber.CssClass = "strikethrough";
                    PNumber.ToolTip = "Number on Do Not Call list";
                }
                else
                {
                    SNumber.CssClass = "strikethrough";
                    SNumber.ToolTip = "Number on Do Not Call list";
                }
            }


            
        }
    }


    protected void bnSearch_Click(object sender, EventArgs e)
    {
        string phoneNumber = txtSearchPhoneNumber.Text;
        DataSet dsDoNotCall = AccountDAO.GetDoNotCallByPhoneNumber(Convert.ToInt32(Session["AccountId"]), phoneNumber);
        gvDoNotCall.DataSource = dsDoNotCall;
        gvDoNotCall.DataBind();
        Session["gvDoNotCall_dtDoNotCall"] = dsDoNotCall;
    }

    protected void bnClearSearch_Click(object sender, EventArgs e)
    {
        DataSet dsDoNotCall = AccountDAO.GetDoNotCall(Convert.ToInt32(Session["AccountId"]));
        gvDoNotCall.DataSource = dsDoNotCall;
        gvDoNotCall.DataBind();
        Session["gvDoNotCall_dtDoNotCall"] = dsDoNotCall;
        txtSearchPhoneNumber.Text = string.Empty;
    }

}



Kostadin
Telerik team
 answered on 23 Oct 2013
1 answer
646 views
Hello,
I have an problem to find the detail table view column which is in GridBoundField. Detail table does not use any asp.net control. Please help me to find those value. Its urgent.
Thank in advance
Konstantin Dikov
Telerik team
 answered on 23 Oct 2013
1 answer
127 views
Hi

I have a large grid with a radrating control in one of the column templates.  Since the grid is so large, it takes a bit of time to load when the user rates an item.  I'd like to only have the row that is rated refresh.  I'm curious if that is even possible?

I tried putting an ajax panel around the item template in the grid that contains the rating control, but that is not really feasible.  The whole row needs to update its values, not just the radrating column in that row.

I did find that someone else asked the same question and Telerik answered in a support ticket, but the support ticket isn't viewable of course:  http://www.telerik.com/community/forums/aspnet-ajax/grid/ajax-single-row-rebing.aspx

I'm going to continue to experiment, but I thought it would make sense to ask if I am headed down a dead-end road, so to speak.

Can someone point me in the right direction if it is possible?  Thanks much.  I really appreciate these forums.


Maria Ilieva
Telerik team
 answered on 23 Oct 2013
10 answers
303 views
I have the following Control:
<telerik:RadTextBox ID="txtSoldTo" runat="server" EmptyMessage="Enter Sold To Person" CssClass="txtSoldTo">
    </telerik:RadTextBox>

Then I have the following CSS:
.txtSoldTo
{
    position: relative;
    top: -155px;
    left: 250px;
    float: left;
    width: 100px;
}

The width is not working.  How do I set the width via CSS?  I notice when I look at the markup on the served page that I see the 'size' as 20.







Sonia
Top achievements
Rank 1
 answered on 23 Oct 2013
5 answers
242 views
How can i add multiple drop down lists, from different datatables as the datasource, using the following code?

Currently i have a dropdown lists for "DurationType", but lets say i wanted to add a dropdown list for "Description" and "Size", how would i be able to do that since i already have code that generates one.


invoicer.cs
public class invoicer
{
    public class MyTemplate : ITemplate
    {
        private string colname;
        protected Label lControl;
 
        public MyTemplate(string cName)
        {
            colname = cName;
        }
        public void InstantiateIn(System.Web.UI.Control container)
        {
            lControl = new Label();
            lControl.ID = "Label-DurationType";
            lControl.DataBinding += new EventHandler(lControl_DataBinding);
            container.Controls.Add(lControl);
        }
 
        public void lControl_DataBinding(object sender, EventArgs e)
        {
            Label l = (Label)sender;
            GridDataItem container = (GridDataItem)l.NamingContainer;
            l.Text = ((DataRowView)container.DataItem)[colname].ToString() + "<br />";
        }
    }
 
 
    public class MyEditTemplate : IBindableTemplate
    {
        public void InstantiateIn(Control container)
        {
            GridEditableItem item = ((GridEditableItem)(container.NamingContainer));
            DropDownList drop = new DropDownList();
            drop.ID = "DurationType-DDL";
            drop.DataSource = (DataTable)GetTableForDropDown();
            drop.DataTextField = "DurationType";
            drop.DataValueField = "DurationType";
            container.Controls.Add(drop);
        }
 
        public System.Collections.Specialized.IOrderedDictionary ExtractValues(System.Web.UI.Control container)
        {
            OrderedDictionary od = new OrderedDictionary();
            od.Add("DurationType", ((DropDownList)(((GridDataItem)(container)).FindControl("DurationType-DDL"))).DataValueField);
            return od;
        }
    }
 
    void grid_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
    {
        RadGrid grid = (RadGrid)sender;
        string id = grid.ID;
         
        DataTable current = (DataTable)HttpContext.Current.Session[int.Parse(id.Split(new string[] {"RadGrid"},StringSplitOptions.RemoveEmptyEntries)[0])];
        grid.DataSource = current;
    }
 
 
 
    protected void grid_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
    {
        if (e.Item is GridEditableItem && e.Item.IsInEditMode)
        {
            GridEditableItem editItem = (GridEditableItem)e.Item;
            DropDownList ddl = (DropDownList)editItem.FindControl("DurationType-DDL");
            ddl.DataSource = (DataTable)GetTableForDropDown();
            ddl.DataTextField = "DurationType";
            ddl.DataValueField = "DurationType";
            ddl.SelectedIndex = editItem.ItemIndex;
            ddl.SelectedValue = DataBinder.Eval(editItem.DataItem, "DurationType").ToString(); // To get the selected value        
        }
    }
 
 
    public void DefineGridStructure(int i, PlaceHolder ph,Boolean bl)
    {
 
        RadGrid grid = new RadGrid();
        grid.ID = "RadGrid" + i.ToString();
        grid.Visible = bl;
        grid.NeedDataSource += new GridNeedDataSourceEventHandler(grid_NeedDataSource);
        grid.AutoGenerateEditColumn = true;
        grid.AutoGenerateDeleteColumn = true;
        grid.AllowAutomaticInserts = false;
        grid.Width = Unit.Percentage(100);
        grid.PageSize = 15;
        grid.AllowPaging = true;
        grid.AllowFilteringByColumn = false;
        grid.PagerStyle.Mode = GridPagerMode.NextPrevAndNumeric;
        grid.AutoGenerateColumns = false;
        grid.MasterTableView.Width = Unit.Percentage(100);
        grid.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.TopAndBottom;
        grid.AllowAutomaticDeletes = false;
        grid.AllowAutomaticUpdates = false;
        grid.ItemDataBound += new GridItemEventHandler(grid_ItemDataBound);
        grid.InsertCommand += grid_InsertCommand;
        grid.DeleteCommand += grid_DeleteCommand;
        grid.UpdateCommand += grid_UpdateCommand;
        grid.MasterTableView.DataKeyNames = new string[] { "RowNumber" };
        GridBoundColumn boundColumn = new GridBoundColumn();
        boundColumn.DataField = "RowNumber";
        boundColumn.HeaderText = "RowNumber";
        boundColumn.ReadOnly = true;
        grid.MasterTableView.Columns.Add(boundColumn);
        boundColumn = new GridBoundColumn();
        boundColumn.DataField = "Size";
        boundColumn.HeaderText = "Size";
        grid.MasterTableView.Columns.Add(boundColumn);
        boundColumn = new GridBoundColumn();
        boundColumn.DataField = "Description";
        boundColumn.HeaderText = "Description";
        grid.MasterTableView.Columns.Add(boundColumn);
        boundColumn = new GridBoundColumn();
        boundColumn.DataField = "Quantity";
        boundColumn.HeaderText = "Quantity";
        grid.MasterTableView.Columns.Add(boundColumn);
        boundColumn = new GridBoundColumn();
        boundColumn.DataField = "Unit";
        boundColumn.HeaderText = "Unit";
        grid.MasterTableView.Columns.Add(boundColumn);
         
        boundColumn = new GridBoundColumn();
        boundColumn.DataField = "Duration";
        boundColumn.HeaderText = "Duration";
        grid.MasterTableView.Columns.Add(boundColumn);
 
        GridTemplateColumn objGridTemplateColumn = new GridTemplateColumn();
        objGridTemplateColumn.HeaderText = "DurationType";
        objGridTemplateColumn.DataField = "DurationType";
        objGridTemplateColumn.ItemTemplate = new MyTemplate("DurationType");
        objGridTemplateColumn.EditItemTemplate = new MyEditTemplate();
        grid.MasterTableView.Columns.Add(objGridTemplateColumn);
 
        boundColumn = new GridBoundColumn();
        boundColumn.DataField = "Amount";
        boundColumn.HeaderText = "Amount";
        grid.MasterTableView.Columns.Add(boundColumn);
        grid.MasterTableView.EditMode = GridEditMode.InPlace;
 
        LinkButton lb = new LinkButton();
        lb.ID = "Show-Grid-" + i.ToString();
        lb.Text = "Show Grid " + i.ToString();
        lb.Click += new EventHandler(ShowGrid);
 
        LinkButton lbd = new LinkButton();
        lbd.ID = "Delete-Grid-" + i.ToString();
        lbd.Text = "Delete Grid " + i.ToString();
        lbd.Click += (sender, e) => DeleteGrid(sender, e, ph);
        Label lbl = new Label();
        lbl.ID = "Break-" + i.ToString();
        lbl.Text = "<br>";
 
        ph.Controls.Add(lb);
        ph.Controls.Add(lbd);
        ph.Controls.Add(grid);
        ph.Controls.Add(lbl);
    }
 
 
    public void DeleteGrid(object sender, EventArgs e, PlaceHolder ph)
    {
        LinkButton gridLink = (LinkButton)sender;
        String gridNum = gridLink.ID.ToString().Split('-').Last();
 
        System.Web.UI.Page currentPage;
        currentPage = (System.Web.UI.Page)System.Web.HttpContext.Current.Handler;
 
        RadGrid grid = (RadGrid)currentPage.FindControl("RadGrid" + gridNum);
        Label lbl = (Label)currentPage.FindControl("Break-" + gridNum);
        LinkButton lbd = (LinkButton)currentPage.FindControl("Delete-Grid-" + gridNum);
        LinkButton lb = (LinkButton)currentPage.FindControl("Show-Grid-" + gridNum);
 
        ph.Controls.Remove(grid);
        ph.Controls.Remove(lbl);
        ph.Controls.Remove(lb);
        ph.Controls.Remove(lbd);
 
        int next = Convert.ToInt32(GetSession());
        next = next - 1;
        HttpContext.Current.Session.Add("Tables", next);
        HttpContext.Current.Session.Remove(gridNum);
        ph.Controls.Clear();
        loopGrids(ph);
    }
 
 
 
    public void loopGrids(PlaceHolder ph)
    {
        System.Web.UI.Page currentPage;
        currentPage = (System.Web.UI.Page)System.Web.HttpContext.Current.Handler;
 
        string ctrlname = currentPage.Request.Params.Get("__EVENTTARGET");
        for (int i = 1; i <= (int)HttpContext.Current.Session["Tables"]; i++)
        {
            if (i == (int)HttpContext.Current.Session["Tables"])
            {
                if (ctrlname == "Button1")
                {
                    DefineGridStructure(i, ph, false);
                }
                else
                {
                    DefineGridStructure(i, ph, true);
                }
            }
            else
            {
                DefineGridStructure(i, ph, false);
            }
        }
    }
 
 
 
 
    public void ShowGrid(object sender, EventArgs e)
    {
        LinkButton gridLink = (LinkButton)sender;
        String gridNum = gridLink.ID.ToString().Split('-').Last();
 
        System.Web.UI.Page currentPage;
        currentPage = (System.Web.UI.Page)System.Web.HttpContext.Current.Handler;
 
        HttpContext.Current.Response.Write("Current gridnum: " + gridNum);
 
        RadGrid grid = (RadGrid)currentPage.FindControl("RadGrid" + gridNum);
        if (grid.Visible)
        {
            grid.Visible = false;
        }
        else
        {
            grid.Visible = true;
        }
    }
 
 
    public void grid_UpdateCommand(object sender, GridCommandEventArgs e)
    {
        GridEditableItem editItem = e.Item as GridEditableItem;
        Hashtable newValues = new Hashtable();
        newValues["RowNumber"] = (editItem["RowNumber"].Controls[0] as TextBox).Text;
        newValues["Size"] = (editItem["Size"].Controls[0] as TextBox).Text;
        newValues["Description"] = (editItem["Description"].Controls[0] as TextBox).Text;
        newValues["Quantity"] = (editItem["Quantity"].Controls[0] as TextBox).Text;
        newValues["Unit"] = (editItem["Unit"].Controls[0] as TextBox).Text;
        newValues["Duration"] = (editItem["Duration"].Controls[0] as TextBox).Text;
        newValues["DurationType"] = (editItem.FindControl("DurationType-DDL") as DropDownList).SelectedValue;
        newValues["Amount"] = (editItem["Amount"].Controls[0] as TextBox).Text;
        DataTable dtCurrentTable = (DataTable)HttpContext.Current.Session[int.Parse(editItem.OwnerGridID.Split(new string[] { "RadGrid" }, StringSplitOptions.RemoveEmptyEntries)[0])];
 
        foreach (DictionaryEntry entry in newValues)
        {
            dtCurrentTable.Rows[e.Item.ItemIndex][entry.Key.ToString()] = entry.Value;
        }
        SaveTable(editItem.OwnerGridID);
 
    }
 
    public void grid_DeleteCommand(object sender, GridCommandEventArgs e)
    {
        GridDataItem item = e.Item as GridDataItem;
        DataTable dt = (DataTable)HttpContext.Current.Session[int.Parse(item.OwnerGridID.Split(new string[] { "RadGrid" }, StringSplitOptions.RemoveEmptyEntries)[0])];
        dt.Rows.Remove(dt.Rows[item.ItemIndex]);
        ResetRowID(dt);
        SaveTable(item.OwnerGridID);
    }
 
    public void grid_InsertCommand(object sender, GridCommandEventArgs e)
    {
        GridEditableItem editedItem = e.Item as GridEditableItem;
        GridEditManager editMan = editedItem.EditManager;
        //Set new values
        Hashtable newValues = new Hashtable();
        //The GridTableView will fill the values from all editable columns in the hash
 
        DataTable dtCurrentTable = (DataTable)HttpContext.Current.Session[int.Parse(editedItem.OwnerGridID.Split(new string[] { "RadGrid" }, StringSplitOptions.RemoveEmptyEntries)[0])];
        DataRow dr = null;
        int count = dtCurrentTable.Rows.Count;
        count++;
        dr = dtCurrentTable.NewRow();
        dr["RowNumber"] = count;
        newValues["RowNumber"] = count;
        newValues["Size"] = (editedItem["Size"].Controls[0] as TextBox).Text;
        newValues["Description"] = (editedItem["Description"].Controls[0] as TextBox).Text;
        newValues["Quantity"] = (editedItem["Quantity"].Controls[0] as TextBox).Text;
        newValues["Unit"] = (editedItem["Unit"].Controls[0] as TextBox).Text;
        newValues["Duration"] = (editedItem["Duration"].Controls[0] as TextBox).Text;
        newValues["DurationType"] = (editedItem.FindControl("DurationType-DDL") as DropDownList).SelectedValue;
        newValues["Amount"] = (editedItem["Amount"].Controls[0] as TextBox).Text;
        foreach (DictionaryEntry entry in newValues)
        {
            dr[entry.Key.ToString()] = entry.Value;
        }
        dtCurrentTable.Rows.Add(dr);
        SaveTable(editedItem.OwnerGridID);
    }
 
 
 
    public string GetSession()
    {
        string SID = HttpContext.Current.Session["Tables"].ToString();
        return SID;
    }
 
    public void SaveTable(string id)
    {
        DataTable dtCurrentTable = (DataTable)HttpContext.Current.Session[int.Parse(id.Split(new string[] { "RadGrid" }, StringSplitOptions.RemoveEmptyEntries)[0])];
        HttpContext.Current.Session.Add(id.Split(new string[] { "RadGrid" }, StringSplitOptions.RemoveEmptyEntries)[0], dtCurrentTable);
    }
 
    public DataTable GetTable()
    {
        //
        // Here we create a DataTable with a few columns.
        //
        // Create Datatable to store all colums
        DataTable dt = new DataTable();
        DataRow dr = null;
        dt.Columns.Add(new DataColumn("RowNumber", typeof(string)));
        dt.Columns.Add(new DataColumn("Size", typeof(string)));
        dt.Columns.Add(new DataColumn("Description", typeof(string)));
        dt.Columns.Add(new DataColumn("Quantity", typeof(string)));
        dt.Columns.Add(new DataColumn("Unit", typeof(string)));
        dt.Columns.Add(new DataColumn("Duration", typeof(string)));
        dt.Columns.Add(new DataColumn("DurationType", typeof(string)));
        dt.Columns.Add(new DataColumn("Amount", typeof(string)));
        dr = dt.NewRow();
        dr["RowNumber"] = 1;
        dr["Size"] = string.Empty;
        dr["Description"] = string.Empty;
        dr["Quantity"] = string.Empty;
        dr["Unit"] = string.Empty;
        dr["Duration"] = string.Empty;
        dr["DurationType"] = string.Empty;
        dr["Amount"] = string.Empty;
        dt.Rows.Add(dr);
 
        dr = dt.NewRow();
        dr["RowNumber"] = 2;
        dr["Size"] = string.Empty;
        dr["Description"] = string.Empty;
        dr["Quantity"] = string.Empty;
        dr["Unit"] = string.Empty;
        dr["Duration"] = string.Empty;
        dr["DurationType"] = string.Empty;
        dr["Amount"] = string.Empty;
        dt.Rows.Add(dr);
 
        dr = dt.NewRow();
        dr["RowNumber"] = 3;
        dr["Size"] = string.Empty;
        dr["Description"] = string.Empty;
        dr["Quantity"] = string.Empty;
        dr["Unit"] = string.Empty;
        dr["Duration"] = string.Empty;
        dr["DurationType"] = string.Empty;
        dr["Amount"] = string.Empty;
        dt.Rows.Add(dr);
 
        dr = dt.NewRow();
        dr["RowNumber"] = 4;
        dr["Size"] = string.Empty;
        dr["Description"] = string.Empty;
        dr["Quantity"] = string.Empty;
        dr["Unit"] = string.Empty;
        dr["Duration"] = string.Empty;
        dr["DurationType"] = string.Empty;
        dr["Amount"] = string.Empty;
        dt.Rows.Add(dr);
 
        dr = dt.NewRow();
        dr["RowNumber"] = 5;
        dr["Size"] = string.Empty;
        dr["Description"] = string.Empty;
        dr["Quantity"] = string.Empty;
        dr["Unit"] = string.Empty;
        dr["Duration"] = string.Empty;
        dr["DurationType"] = string.Empty;
        dr["Amount"] = string.Empty;
        dt.Rows.Add(dr);
        return dt;
    }
 
 
    static DataTable GetTableForDropDown()
    {
        //
        // Here we create a DataTable with a few columns.
        //
        // Create Datatable to store all colums
        DataTable dt = new DataTable();
        DataRow dr = null;
        dt.Columns.Add(new DataColumn("DurationType", typeof(string)));
 
        dr = dt.NewRow();
        dr["DurationType"] = "Hours";
        dt.Rows.Add(dr);
 
        dr = dt.NewRow();
        dr["DurationType"] = "Days";
        dt.Rows.Add(dr);
 
        dr = dt.NewRow();
        dr["DurationType"] = "Weeks";
        dt.Rows.Add(dr);
 
        dr = dt.NewRow();
        dr["DurationType"] = "Months";
        dt.Rows.Add(dr);
        return dt;
    }
 
    private void ResetRowID(DataTable dt)
    {
        int rowNumber = 1;
 
        if (dt.Rows.Count > 0)
        {
            foreach (DataRow row in dt.Rows)
            {
                row[0] = rowNumber;
                rowNumber++;
            }
        }
    }
}


default.aspx.cs
public partial class _Default : System.Web.UI.Page
{
 
    invoicer inv = new invoicer();
   
    protected void Page_Load(object sender, EventArgs e)
    {
 
    }
 
    protected void Page_Init(object sender, EventArgs e)
    {
        string ctrlname = this.Page.Request.Params.Get("__EVENTTARGET");
 
        if (Session["Tables"] == null)
        {
            Session.Add("Tables", 1);
            DataTable dt = inv.GetTable();
 
            Session.Add(Session["Tables"].ToString(), dt);
            inv.DefineGridStructure(1, PlaceHolder2, true);
        }
        if (IsPostBack)
        {
            int next = Convert.ToInt32(inv.GetSession());
            PlaceHolder2.Controls.Clear();
            inv.loopGrids(PlaceHolder2);
             
            if (ctrlname == "Button1")
            {
                next = next + 1;
                Session.Add("Tables",next);
                Response.Write("Button getSession: " + inv.GetSession());
                DataTable dt = inv.GetTable();
                Session.Add(Session["Tables"].ToString(), dt);
                inv.DefineGridStructure(next, PlaceHolder2,true);
            }
 
        }
    }
 
 
 
 
    protected void Button1_Click(object sender, EventArgs e)
    {
 
    }
     
}
Antonio Stoilkov
Telerik team
 answered on 23 Oct 2013
Narrow your results
Selected tags
Tags
+? more
Top users last month
Jay
Top achievements
Rank 3
Bronze
Iron
Iron
yw
Top achievements
Rank 2
Iron
Iron
Stefan
Top achievements
Rank 2
Iron
Iron
Iron
Kao Hung
Top achievements
Rank 1
Iron
Bohdan
Top achievements
Rank 2
Iron
Iron
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Jay
Top achievements
Rank 3
Bronze
Iron
Iron
yw
Top achievements
Rank 2
Iron
Iron
Stefan
Top achievements
Rank 2
Iron
Iron
Iron
Kao Hung
Top achievements
Rank 1
Iron
Bohdan
Top achievements
Rank 2
Iron
Iron
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?