Telerik Forums
UI for ASP.NET AJAX Forum
3 answers
219 views
Can someone review my code. I have been struggling for the last few days.  Everything works except that it is not updating when I click the update. It posts back, but the values remain.

I am using this example as a template:  http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/clienteditbatchupdates/defaultcs.aspx

It probably has to do with namespace. I'm just learning and took it out.

<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Site.Master" CodeBehind="test.aspx.vb" Inherits="WebDataInput.test" %>
<%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" 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 row disposing
            function RowDestroying(sender, eventArgs) {
                if (eventArgs.get_id() === "") return;
                var row = eventArgs.get_gridDataItem().get_element();
                var cells = row.cells;
                for (var j = 0, len = cells.length; j < len; j++) {
                    var cell = 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);
                var rowKeyValue = gridRow.getDataKeyValue("ContributionMasterID");
                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);
 
                //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 "PayDate":
                        HideEditor(editedCell, "textbox");
                        break;
                    case "Totals":
                        HideEditor(editedCell, "textbox");
                        break;
                    case "UnitPrice":
                        HideEditor(editedCell, "textbox");
                        break;
                    case "UnitsInStock":
                        HideEditor(editedCell, "dropdown");
                        break;
                    case "Discontinued":
                        HideEditor(editedCell, "checkbox");
                        break;
                    default:
                        break;
                }
            }
            function CancelChanges() {
                if (editedItemsIds.length > 0) {
                    $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) {
                    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 RadGrid1_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">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="RadGrid1">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1" />
                    <telerik:AjaxUpdatedControl ControlID="RadInputManager1" />
                    <telerik:AjaxUpdatedControl ControlID="Label1" />
                </UpdatedControls>
            </telerik:AjaxSetting>
            <telerik:AjaxSetting AjaxControlID="RadAjaxManager1">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1" />
                    <telerik:AjaxUpdatedControl ControlID="RadInputManager1" />
                    <telerik:AjaxUpdatedControl ControlID="Label1" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>
    <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" />
    <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="0" MaxValue="100000" />
        <telerik:NumericTextBoxSetting BehaviorID="NumberBehavior" EmptyMessage="type.."
            Type="Number" DecimalDigits="0" MinValue="0" MaxValue="100" />
    </telerik:RadInputManager>
    <telerik:RadGrid ID="RadGrid1" DataSourceID="SqlDataSource1" Width="97%" ShowStatusBar="True"
        AllowSorting="True" PageSize="15" GridLines="None" AllowPaging="True" runat="server"
        AutoGenerateColumns="False">
        <MasterTableView TableLayout="Fixed" DataKeyNames="ContributionMasterID" EditMode="InPlace"
            ClientDataKeyNames="ContributionMasterID" CommandItemDisplay="Bottom">
            <CommandItemTemplate>
                <div style="height: 30px; text-align: right;">
<asp:Image ID="imgCancelChanges" runat="server" ImageUrl="../Images/cancelEditGrid.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="../Images/okEditGrid.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="ContributionMasterID"
                    DataField="ContributionMasterID" HeaderText="ContributionMasterID"
                    ReadOnly="True" HeaderStyle-Width="25%"
                    SortExpression="ContributionMasterID" >
                    <HeaderStyle Width="25%"></HeaderStyle>
                 
                </telerik:GridBoundColumn>
                    <telerik:GridTemplateColumn HeaderText="Totals" HeaderStyle-Width="15%" UniqueName="Totals">
                    <ItemTemplate>
                        <asp:Label ID="lblTotals" runat="server" Text='<%# Eval("Totals", "{0:C}") %>' />
                        <asp:TextBox ID="txtTotals" runat="server" Text='<%# Eval("Totals", "{0:C}") %>' Style="display: none" />
                    </ItemTemplate>
                </telerik:GridTemplateColumn>
                            
            </Columns>
        </MasterTableView>
        <ClientSettings>
            <ClientEvents OnRowCreated="RowCreated" OnRowClick="RowClick" OnCommand="RadGrid1_Command"
                OnRowDestroying="RowDestroying" />
        </ClientSettings>
 
<HeaderContextMenu EnableAutoScroll="True"></HeaderContextMenu>
    </telerik:RadGrid>
    <br />
    <asp:Label ID="Label1" runat="server" EnableViewState="false" />
    <br />
     
    <asp:SqlDataSource ID="SqlDataSource1"
        ConnectionString="<%$ ConnectionStrings:RemoteSQLConnection %>" SelectCommand="SELECT ContributionMasterID, Totals FROM tblContributionMaster"
        runat="server"
        UpdateCommand="UPDATE tblContributionMaster SET Totals = @Totals WHERE (ContributionMasterID = @ContributionMasterID)">
        <UpdateParameters>
            <asp:Parameter Name="Totals"/>
            <asp:Parameter Name="ContributionMasterID"/>
         </UpdateParameters>
    </asp:SqlDataSource>
  
</asp:Content>

Code behind

Imports System
Imports Telerik.Web.UI
Imports System.Collections
 
Public Class test
    Inherits System.Web.UI.Page
 
    Private Sub SetMessage(ByVal message As String)
        Label1.Text = String.Format("<span>{0}</span>", message)
    End Sub
    Protected Sub RadGrid1_ItemCreated(ByVal sender As Object, ByVal e As GridItemEventArgs) Handles RadGrid1.ItemCreated
        If TypeOf e.Item Is GridDataItem Then
            Dim dataItem As GridDataItem = CType(e.Item, GridDataItem)
            '***************************************************************************************
            Dim txtBox As TextBox
            txtBox = CType(dataItem.FindControl("txtTotals"), TextBox)
            Dim currencySetting As NumericTextBoxSetting = DirectCast(RadInputManager1.GetSettingByBehaviorID("CurrencyBehavior"), NumericTextBoxSetting)
            currencySetting.TargetControls.Add(New TargetInput(txtBox.UniqueID, True))
 
        End If
    End Sub
    Protected Sub RadAjaxManager1_AjaxRequest(ByVal sender As Object, ByVal e As AjaxRequestEventArgs) Handles RadAjaxManager1.AjaxRequest
        If e.Argument = String.Empty Then
            RadGrid1.Rebind()
        End If
        Dim editedItemIds As String() = e.Argument.Split(":")
        Dim i As Integer
        For i = 0 To editedItemIds.Length - 2
            Dim contributionmasterid As String = editedItemIds(i)
            Dim updatedItem As GridDataItem = CType(RadGrid1.MasterTableView.FindItemByKeyValue("ContributionMasterID", "String"), GridDataItem)
            UpdateValues(updatedItem)
        Next
    End Sub
 
    Protected Sub UpdateValues(ByVal updatedItem As GridDataItem)
 
        Dim txtBox As TextBox
 
        txtBox = CType(updatedItem.FindControl("txtTotals"), TextBox)
        SqlDataSource1.UpdateParameters("Totals").DefaultValue = txtBox.Text
 
        ' Dim ddl As DropDownList = CType(updatedItem.FindControl("ddlUnitsInStock"), DropDownList)
        'SqlDataSource1.UpdateParameters("UnitsInStock").DefaultValue = ddl.SelectedValue
 
        'Dim chkBox As CheckBox = CType(updatedItem.FindControl("chkBoxDiscontinued"), CheckBox)
        'SqlDataSource1.UpdateParameters("Discontinued").DefaultValue = chkBox.Checked
 
        SqlDataSource1.UpdateParameters("ContributionMasterID").DefaultValue = updatedItem.GetDataKeyValue("ContributionMasterID").ToString()
        Try
            SqlDataSource1.Update()
        Catch ex As Exception
            SetMessage(Server.HtmlEncode("Unable to update Products. Reason: " + ex.StackTrace).Replace("'", "'").Replace(vbCrLf, "<br />"))
        End Try
        SetMessage("Product with ID: " & updatedItem.GetDataKeyValue("ContributionMasterID") & " updated")
 
    End Sub
End Class


Iana Tsolova
Telerik team
 answered on 29 Oct 2010
1 answer
65 views
Hi

My question is about RadGrid with NestedViewTemplate.

I Master Table I catch ItemCommand event, but when I'm in a NestedView, where I have another Grid, when I make Update/Insert, program gous through ItemCommand Event with I bind in MasterTable of the mother Grid. How to distinguish, understand who is the invoker - Mester Table Grid or Nested Grid or maybe there is a chance program not to fire Master Table ItemCommand ?

Thank for effort answer me

Best Regard
Radoslav
Telerik team
 answered on 29 Oct 2010
1 answer
176 views

I have several related comboboxes that i populate through javascript. The purpose is to have them all populated and that each has selected value.

1.<telerik:RadComboBox ID="FirstComboBox" EnableLoadOnDemand="false" runat="server"
AllowCustomText="true" MarkFirstMatch="true"
OnClientSelectedIndexChanged="FirstComboSelectedIndexChanged" >
<WebServiceSettings Method="GetFirstItems" Path="ComboboxService.svc" /> </telerik:RadComboBox>
2. 
3.<telerik:RadComboBox ID="SecondComboBox" EnableLoadOnDemand="false" runat="server"
AllowCustomText="true" MarkFirstMatch="true"
OnClientSelectedIndexChanged="SecondComboSelectedIndexChanged" />
<WebServiceSettings Method="GetSecondItems" Path="ComboboxService.svc" /> </telerik:RadComboBox>
4. 
5.<telerik:RadComboBox ID="ThirdComboBox" EnableLoadOnDemand="false" runat="server"
AllowCustomText="true" MarkFirstMatch="true"
OnClientSelectedIndexChanged="ThirdComboSelectedIndexChanged" />
<WebServiceSettings Method="GetSecondItems" Path="ComboboxService.svc" /> </telerik:RadComboBox>

Here is script to populate data and select selected item.

all works great and all combo boxes have proper items and proper value and text. 

01.function pageLoad() {
02.firstComboBox.requestItems(some argument);
03.firstComboBox.set_value(some webService result);                
04.secondComboBox.requestItems(some argument);
05.secondComboBox.set_value(some webService result);          
06.and so on...           
07.                  
08.              
09.  
10.}

The problem is when I focus on a combobox and press TAB key and a combo loose focus. The OnClientSelectedIndexChanged event fires
even though selection did not changed! Why that happens?
I suspect that ComboBox.set_value() function does not set selected index and after loosing focus controls thinks
it has changed but how to fix it?


tomekm
Top achievements
Rank 1
 answered on 29 Oct 2010
2 answers
115 views
Hello,
I can not get the Grouping to work on client side. The page always end up posting back after I drag a column to the grouping area.
Column reordering works fine on the client-side...
 
What am i missing here? 

-Sadiq.


<
body>
    <form id="form1" runat="server">
    <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
    </telerik:RadScriptManager>
    <div>
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="grdRad">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="grdRad" LoadingPanelID="RadAjaxLoadingPanel1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
        </telerik:RadAjaxManager>
        <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" />
    </div>
    <telerik:RadGrid ID="grdRad" runat="server" ShowGroupPanel="True" GridLines="None" AutoGenerateColumns="true">
        <MasterTableView GroupLoadMode="Client">
          
        </MasterTableView>
        <ClientSettings AllowGroupExpandCollapse="True" AllowDragToGroup="true" AllowColumnsReorder="true"
            ReorderColumnsOnClient="True" ColumnsReorderMethod="Reorder" >
        </ClientSettings>
        <GroupingSettings ShowUnGroupButton="true" />
    </telerik:RadGrid>
    </form>
</body>
Maria Ilieva
Telerik team
 answered on 29 Oct 2010
22 answers
641 views
I am getting a wierd error when trying to run a (framework 3.5) radcontrols enabled web application in c# or vb.  When I try and run the web application the first time it says debugging is not enabled.  In the dialog it give me to options to add a new web.config and or to run without debugging.  If I try and add a new web.config which there is one already it give me a the operation could not be completed unspecified error.  If I modify the web.config to enable debugging by hand it still gives me the debugging is not enabled message box.
Erjan Gavalji
Telerik team
 answered on 29 Oct 2010
1 answer
114 views
Hi,

I received the following errors on using Rad Editor.
The steps to repro are:
1. Place large html content in the HTML section of the Rad Editor which also contains some images.
2. Switch to Design View and select any image.
3. Right click on the image and select properties.
The application Hangs and the following screens are displayed.

Screen shot 1
 
After clicking on Ok another error window pops up displaying the following error message.
Screen shot 2 


Please let me know if anybody has similar exception/ Solution
Thanks
Rajesh Soni

Stanimir
Telerik team
 answered on 29 Oct 2010
1 answer
123 views
Hello, 

I'm trying to put an AppointmentContextMenus and it's working well.

Do you have any project to add a fonctionnality like Copy/Cut/Past?
It could be very usefull.

I made something by my own, but the grid is not refersh in ajax when I past. I have to reload the page to see the past...
And I can't enable or not item depending on the state... Can we past? can we copy?

Thank you

Jean-Yves
Shinu
Top achievements
Rank 2
 answered on 29 Oct 2010
2 answers
198 views
Hello,
I have grid that is for printing purposes. It has some GridBoundColumns and some GridTemplateColumns. Now, the users want to change some values in the cells before printing. Therefore I have implemented an EditCommandColumn. By pressing the edit button only the GridBoundColumns can be changed. Is it possible to have the TemplateColumns edited as well? The changed data does not have to be saved or anything else. It just has to be printed later.

Best regards
Ferdinand
Ferdinand
Top achievements
Rank 1
 answered on 29 Oct 2010
1 answer
110 views
  

When I change the order of the items/rows in the grid using client side code, I would like to find the new order representation.
I used the MasterTableView.Items collection and I end up with the original order, as when I bind the grid with the data. 

What is the correct collection property to iterate through to retrieve the current row order of the rearranged grid?

  <telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">
        <script type="text/javascript">
            var _selectedRow;
            function radgvAddress_RowSelected(sender, args) {
                _selectedRow = $get(args.get_id());

            }

            function moveRowUp() {
                if (_selectedRow && _selectedRow.sectionRowIndex > 0) {
                    swapRows(_selectedRow, _selectedRow.parentNode.rows[_selectedRow.sectionRowIndex - 1])
                }
            }

            function moveRowDown() {
                if (_selectedRow && _selectedRow.sectionRowIndex < _selectedRow.parentNode.rows.length - 1) {

                    swapRows(_selectedRow, _selectedRow.parentNode.rows[_selectedRow.sectionRowIndex + 1])
                }
            }

            function serializeChanges(index1, index2) {
                var reorderInput = document.getElementById("ReorderChanges");
                if (reorderInput) {
                    reorderInput.value += index1 + "," + index2 + ";";
                }
            }

            function swapRows(sourceRow, targetRow) {
                for (var i = 0; i < sourceRow.cells.length; i++) {
                    var cellContent1 = targetRow.cells[i].innerHTML;
                    var cellContent2 = sourceRow.cells[i].innerHTML;
                    targetRow.cells[i].innerHTML = cellContent2;
                    sourceRow.cells[i].innerHTML = cellContent1;
                }
                $find("<%= radgvAddress.MasterTableView.ClientID %>").selectItem(targetRow);
                serializeChanges(sourceRow.sectionRowIndex, targetRow.sectionRowIndex);
            }
        </script>
    </telerik:RadScriptBlock>



//// I've used a foreach statement also but then I figured it was the collection.  radgvAddress.MasterTableView.Items return the orginal order for us.

for (int i = radgvAddress.Items.Count; i > 0; i--)
                {
                    //int PatientAddressID = Convert.ToInt32(radgvAddress.Items[i - 1].OwnerTableView.DataKeyValues[radgvAddress.Items[i - 1].ItemIndex]["PatientAddressID"]);
                    int PatientAddressID = Convert.ToInt32(radgvAddress.MasterTableView.Items[i - 1].GetDataKeyValue("PatientAddressID"));
                    QuickviewPMS_BO.PatientAddress PatientAddressObj = QuickviewPMS_BO.PatientAddress.GetPatientAddress(PatientAddressID, SessionHelper.SessionUserObjectsInfo.ClientId);
                    PatientAddressObj.AddressOrder = i;
                    if (!PatientAddressObj.IsValid)
                    {
                        GlobalHelper.ShowMessage(lblMessage, GlobalHelper.GetBrokenRules(PatientAddressObj), GlobalHelper.MessageType.Error);
                        return;
                    }
                    PatientAddressObj.Save();
                                 } 
  radgvAddress.Rebind();

            }





 

 

 

 

<telerik:RadGrid ID="radgvAddress" runat="server" GridLines="None"
   AllowPaging="True" PageSize="5" AutoGenerateColumns="False" Width="100%"
    ShowStatusBar="true" AllowAutomaticDeletes="false" AllowAutomaticInserts="false"
    AllowAutomaticUpdates="false" HorizontalAlign="NotSet" Skin="Vista"
    OnDetailTableDataBind="radgvAddress_DetailTableDataBind"
                            OnInsertCommand="radgvAddress_InsertCommand"
                            OnNeedDataSource="radgvAddress_NeedDataSource"
                            OnUpdateCommand="radgvAddress_UpdateCommand"
                            OnDeleteCommand="radgvAddress_DeleteCommand"
                            OnItemDataBound="radgvAddress_ItemDatabound"
                            onselectedindexchanged="radgvAddress_SelectedIndexChanged">
    <MasterTableView CommandItemDisplay="Top" ClientDataKeyNames="PatientAddressID" DataKeyNames="PatientAddressID" EditMode="PopUp">
        <CommandItemTemplate>
            <telerik:RadToolBar ID="RadToolBar1" OnButtonClick="RadToolBar1_ButtonClick" runat="server"
                Skin="Vista" OnClientButtonClicking="onToolBarClientButtonClicking">
                <Items>
                    <telerik:RadToolBarButton  Text="Add" CommandName="InitInsert" Value="1" ImageUrl="~/Images/AddRecord.gif"
                        Visible='<%# !radgvAddress.MasterTableView.IsItemInserted %>'>
                    </telerik:RadToolBarButton>
                    <telerik:RadToolBarButton Text="Edit" Enabled="false" CommandName="EditSelected" Value="2" ImageUrl="~/Images/Edit.gif"
                        Visible='<%# radgvAddress.EditIndexes.Count == 0 %>'>
                    </telerik:RadToolBarButton>
                    <telerik:RadToolBarButton Text="Update" CausesValidation="false" CommandName="UpdateEdited" Value="3" ImageUrl="~/Images/Update.gif"
                        Visible='<%# radgvAddress.EditIndexes.Count > 0 %>'>
                    </telerik:RadToolBarButton>
                    <telerik:RadToolBarButton Text="Cancel" CausesValidation="false" CommandName="CancelAll" Value="4" ImageUrl="~/Images/Cancel.gif"
                        Visible='<%# radgvAddress.EditIndexes.Count > 0 || radgvAddress.MasterTableView.IsItemInserted %>'>
                    </telerik:RadToolBarButton>                
                    <telerik:RadToolBarButton Text="Delete" Enabled="false" CausesValidation="false"  CommandName="DeleteSelected" Value="5"
                        ImageUrl="~/Images/Delete.gif">
                         </telerik:RadToolBarButton>
                    <telerik:RadToolBarButton Visible="false" Text="ChangeStatus" CommandName="ChangeStatus" Value="6"
                         ImageUrl="~/Images/Edit.gif">
                    </telerik:RadToolBarButton>
                    <telerik:RadToolBarButton  Text="Refresh" CausesValidation="false" CommandName="RebindGrid" Value="7" ImageUrl="~/Images/Refresh.gif">
                    </telerik:RadToolBarButton>
                      <telerik:RadToolBarButton  Text="Save" CausesValidation="false" CommandName="RebindGrid" Value="8" ImageUrl="~/Images/Update.gif">
                    </telerik:RadToolBarButton>
                </Items>
            </telerik:RadToolBar>
        </CommandItemTemplate>
       
        <Columns>
         <telerik:GridTemplateColumn UniqueName="SNo" HeaderText="S No">
                                <ItemTemplate>
                                <asp:Label ID="lblSno" runat="server" ></asp:Label>
                               
                                </ItemTemplate>
                                <HeaderStyle Width="45px" />
                                </telerik:GridTemplateColumn>
                                <telerik:GridTemplateColumn HeaderText="AddressID">
                <ItemTemplate>
              
                                 <asp:Label ID="lblAddressID" runat="server" Text='<%#Bind("PatientAddressID") %>'></asp:Label>
                             
                </ItemTemplate>
                </telerik:GridTemplateColumn>
             <telerik:GridBoundColumn UniqueName="AddressLine" HeaderText="Address Line" DataField="Address1">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn UniqueName="Country" HeaderText="Country" DataField="CountryName">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn UniqueName="StateName" HeaderText="State" DataField="StateName">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn UniqueName="City" HeaderText="City" DataField="CityName">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn UniqueName="ZipCode" HeaderText="Zip Code" DataField="ZipCodeName">
            </telerik:GridBoundColumn>
                    <telerik:GridTemplateColumn HeaderText="Status">
                <ItemTemplate>
                <asp:Label ID="lblStatus" runat="server" Text='<%#Bind("Active") %>'></asp:Label>
                </ItemTemplate>
                </telerik:GridTemplateColumn>
        </Columns>
        <EditFormSettings InsertCaption="Add new Address" CaptionFormatString="Edit Address"
            CaptionDataField="PatientAddressID" PopUpSettings-Width="520" EditFormType="Template" PopUpSettings-Modal="true">
           
             <FormTemplate>
                <table id="Table1" cellspacing="1" cellpadding="1" class="popuptbl" width="520" border="0">
                            <td class="popregtxt">
                        Address Line1<span class="mandatory">*</span> :
                    </td>
                    <td class="popregcontrol">
                        <telerik:RadTextBox Width="160px" TabIndex="1" ID="radtxtAddress1" runat="server" Text='<%# Bind( "Address1") %>'>
                        </telerik:RadTextBox>
                         <br />
                             <asp:RequiredFieldValidator ID="rfvAddress1" runat="server" ControlToValidate="radtxtAddress1"
                        Display="Dynamic" ErrorMessage="Enter Address1" ValidationGroup="Address"  CssClass="validationtxt"   Font-Bold="false" SetFocusOnError="True">
                        </asp:RequiredFieldValidator>  
                    </td>

                     <td class="popregtxt">
                        Address Line2<span class="mandatory"></span> :
                    </td>
                    <td class="popregcontrol">
                        <telerik:RadTextBox Width="160px" TabIndex="2" ID="radtxtAddress2" runat="server" Text='<%# Bind( "Address2") %>'>
                        </telerik:RadTextBox>
                       
                    </td>

                    </tr>
                    <tr>
                   
                    <td class="popregtxt">
                        Country<span class="mandatory">*</span> :
                    </td>
                    <td class="popregcontrol">
                       <telerik:RadComboBox ID="radcmbCountry" Width="160px" TabIndex="3"  DataTextField="CountryName"
                        DataValueField="CountryID" DataSourceID="DsCountryClassSelect" AllowCustomText="false"
                        SelectedValue='<%# Bind("CountryID") %>' AutoCompleteSeparator="" CausesValidation="false" MarkFirstMatch="true" runat="server" 
                        AutoPostBack="true" OnSelectedIndexChanged="radcmbCountry_SelectedIndexChanged">
                       <Items>
                        <telerik:RadComboBoxItem Text="--Select--" Value="-1" Selected="true" runat="server" />
                        </Items>
                      </telerik:RadComboBox>
                       <br />
                        <asp:RequiredFieldValidator ValidationGroup="Address" CssClass="validationtxt" ID="rfvCountry"
                         runat="server" ErrorMessage="Select a Country" InitialValue="--Select--" ControlToValidate="radcmbCountry"></asp:RequiredFieldValidator>
                    </td>

                        <td class="popregtxt">
                            State<span class="mandatory">*</span> :
                        </td>
                        <td class="popregcontrol">
                            <telerik:RadComboBox ID="radcmbState"  runat="server" DataTextField="StateName" DataValueField="StateID"
                            TabIndex="4" AllowCustomText="false" AutoCompleteSeparator="" Width="160px" CausesValidation="false"
                            MarkFirstMatch="true" AutoPostBack="true" OnSelectedIndexChanged="radcmbState_SelectedIndexChanged">
                            <Items>
                            <telerik:RadComboBoxItem Text="--Select--" Value="-1" Selected="true" runat="server" />
                            </Items>
                            </telerik:RadComboBox>
                            <br />
                             <asp:RequiredFieldValidator ValidationGroup="Address" CssClass="validationtxt" ID="rfvState"
                         runat="server" ErrorMessage="Select a State" InitialValue="--Select--" ControlToValidate="radcmbState"></asp:RequiredFieldValidator>
                        </td>
                       
                    </tr>
                    <tr>
                    <td class="popregtxt">
                            City<span class="mandatory">*</span> :
                        </td>
                        <td class="popregcontrol">
                             <telerik:RadComboBox ID="radcmbCity" Width="163px" AllowCustomText="false" runat="server"
                             DataTextField="CityName" DataValueField="CityID" CausesValidation="false" MarkFirstMatch="true" TabIndex="5"
                             AutoPostBack="true" OnSelectedIndexChanged="radcmbCity_SelectedIndexChanged"  >
                             <Items>
                            <telerik:RadComboBoxItem Text="--Select--" Value="-1" runat="server" />
                            </Items>
                           </telerik:RadComboBox>
                            <br />
                        <asp:RequiredFieldValidator ValidationGroup="Address" CssClass="validationtxt" ID="rfvCity"
                         runat="server" ErrorMessage="Select a City" InitialValue="--Select--" ControlToValidate="radcmbCity"></asp:RequiredFieldValidator>
                        </td>
                        <td class="popregtxt">
                            ZipCode<span class="mandatory">*</span> :
                        </td>
                        <td class="popregcontrol">
                            <telerik:RadComboBox ID="radcmbZipCode" Width="163px" runat="server" DataTextField="ZipCodeName"
                            DataValueField="ZipCodeID" AllowCustomText="false" TabIndex="6" AutoCompleteSeparator=""
                            CausesValidation="false" MarkFirstMatch="true" >
                            <Items>
                            <telerik:RadComboBoxItem Text="--Select--" Value="-1" Selected="true" runat="server" />
                            </Items>
                        </telerik:RadComboBox>
                        <br />
                        <asp:RequiredFieldValidator ValidationGroup="Address" CssClass="validationtxt" ID="rfvZipCode"
                         runat="server" ErrorMessage="Select a ZipCode" InitialValue="--Select--" ControlToValidate="radcmbZipCode"></asp:RequiredFieldValidator>
                        </td>
                     
                    </tr>
                    <tr>
                      <td class="popregtxt">
                            Status :
                        </td>
                        <td class="popregcontrol">
                           <telerik:RadComboBox ID="radcmbStatus" runat="server" Width="163px" TabIndex="7" SelectedValue='<%#Bind("Active") %>'>
                                                <Items>
                                                    <telerik:RadComboBoxItem Text="Active" Value="True" />
                                                    <telerik:RadComboBoxItem Text="InActive" Value="False" />
                                                </Items>
                                            </telerik:RadComboBox>
                        </td>

                   
                    </tr>
                    <tr> 
                    <td>
                    </td><td></td></tr>
                </table>
                <table class="popbuttontbl">
                    <tr>
                        <td align="right">
                            <asp:Button ID="Button1" ValidationGroup="Address" TabIndex="10" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>'
                                runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'>
                            </asp:Button>&nbsp;
                            <asp:Button ID="Button2" TabIndex="11" Text="Cancel" runat="server" CausesValidation="False" CommandName="Cancel">
                            </asp:Button>
                        </td>
                    </tr>
                </table>
            </FormTemplate>
        </EditFormSettings>
     </MasterTableView> 
    <ClientSettings>
  <%--   EnablePostBackOnRowClick="true"--%>
        <Selecting AllowRowSelect="True" EnableDragToSelectRows="True" />
     <ClientEvents OnRowSelected="radgvAddress_RowSelected"></ClientEvents>
    </ClientSettings>

</telerik:RadGrid>

 

 

Veli
Telerik team
 answered on 29 Oct 2010
8 answers
289 views
my webpage have two input control that is textbox &  search button. i wrote  textbox keypress event javascript .
if i try to type keywords in textbox, the keypress event is firing and then click search button control .again i try  to type keywords in textbox the keypress event not firing..

Hope u could understand what i meant, plz help me..


this is my code:


<head id="Head1" runat="server">
 
</head>
<body>
    <form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" EnableScriptGlobalization="True">
     <Scripts>
        <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
        <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" />
        <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js" />    
    </Scripts>
</asp:ScriptManager>
  
  <script type="text/javascript">
    window.$ = $telerik.$;
    $(document).ready(function() {
        var typeDelay = function(){
            var timer = 0;
            return function(callback, ms){
               clearTimeout (timer);
               timer = setTimeout(callback, ms);
            
        }();
         
        $("#query").keypress(function(){
        
               // your ajax search here, with a 300 ms delay...   
               typeDelay(function(){
                
               alert('controls comes here.!'); 
                
                }, 300);
        });
    }); 
  
 </script>
<telerik:RadAjaxManager id="RadAjaxManager1" runat="server" DefaultLoadingPanelID="RadAjaxLoadingPanel1">
    <ajaxsettings>
              <telerik:AjaxSetting AjaxControlID="RadAjaxPanel1">
                <UpdatedControls>
                               <telerik:AjaxUpdatedControl ControlID="RadAjaxPanel1" />  
                </UpdatedControls>
            </telerik:AjaxSetting>                
  </ajaxsettings>
</telerik:RadAjaxManager>
 
<telerik:RadAjaxLoadingPanel id="RadAjaxLoadingPanel1" Runat="server" Skin="Default"  Width="100%"></telerik:RadAjaxLoadingPanel>
<telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" Width="100%">
         <asp:TextBox ID="query" MaxLength="100" runat="server" />
        <asp:Button ID="btnSubmit" runat="server" Text="Search" />
                
        </telerik:RadAjaxPanel>
    </form>
</body>
</html>
nanthakumar thangavel
Top achievements
Rank 1
 answered on 29 Oct 2010
Narrow your results
Selected tags
Tags
+? more
Top users last month
Marco
Top achievements
Rank 4
Iron
Iron
Iron
Hiba
Top achievements
Rank 1
Iron
Iron
Rob
Top achievements
Rank 3
Bronze
Bronze
Iron
Max
Top achievements
Rank 1
Veteran
Iron
Alina
Top achievements
Rank 1
Want to show your ninja superpower to fellow developers?
Top users last month
Marco
Top achievements
Rank 4
Iron
Iron
Iron
Hiba
Top achievements
Rank 1
Iron
Iron
Rob
Top achievements
Rank 3
Bronze
Bronze
Iron
Max
Top achievements
Rank 1
Veteran
Iron
Alina
Top achievements
Rank 1
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?