Telerik Forums
UI for ASP.NET AJAX Forum
2 answers
142 views

Good day,

I'm currently migrating some user controls to telerik to use the new features. One of our user controls was a image upload control. Basically it had an asp.net img object and a stardard asp.net file upload object.

I changed it for a RadBinaryImage and a RadAsyncUpload. So far, the changes have worked. But I encountered a problem. Due to the lack of validation that the old control had, users could upload any file even if it wasn't images (like pdf, .doc, etc). Of course, it was not displayed properly on the asp.img object but it didn't show any exception, just an "x" sign. With the new user control, when I'm navigating through the records in a table and the control encounters one with a byte array that doesn't correspond to an image, it throws the following exception: "ArgumentException: The provided binary data may not be valid image or may contains unknown header".

I've read several posts in the forum and I already know that this exception is thrown because of the invalid format of the file loaded and that's ok, but I wanted to take control of this error if it happens so I did the following changes in the user control (ascx):

public void ShowImage(byte[] img)
{
    try
    {
        String strImageSessionName = String.Format("imagen{0}", imgMuestra.ClientID);
        Session[strImageSessionName] = img;
        imgMain.DataValue = img;
        imgTooltip.DataValue = img;
        imgMuestra.Style["cursor"] = "pointer";
        this.EnableTooltip = true;
    }
    catch (Exception)
    {
        imgMain.ImageUrl = "~/images/image_not_available.jpg";
        imgTooltip.ImageUrl = "~/images/image_not_available.jpg";
        this.EnableTooltip = false;
    }
     
}
 

 If there's any error when loading the bytes into the control I want to show instead a fixed image. The problem is that the catch block is never reached. It always do the try block entirely even if the data is in an incorrect format. The exception is thrown later in a uncontrolled manner by the form making the form crash.

What could I do to catch this error if it happens and achieve what I want? Thanks in advance for any help.

David
Top achievements
Rank 1
 answered on 10 Jun 2015
2 answers
69 views

I'm new to Telerik. Quite liking the toolkit so far. I encountered some strange behavior I would like some help with.
I'm using Internet Explorer 11.0.19. This bug seems to only happen in that browser, and not on Firefox.

I have a RadEditor with the page load function to turn enable comments and tracking. The problem is after it is turned on, on page load, clicking on a dropdown toolbar item would not do anything, i.e. no dropdown options shown. Getting rid of the code seems to fix the problem, but I need to have the flexibility to turn off and on comments and tracking from code-behind, as I'd like to dynamically change the comments and tracking options depending on the logged in user.

The bug seems to only happen if the first thing I do after page load is click on the dropdown options. If I click on the RadEditor content pane, everything would work fine.

Other things I tried:
* Focus RadEditor on page load (Didn't work)
* Move the C# code of enabling the comments and track changes to RadEditor onload, and oninit (Didn't Work, still same problem)

WebForm2.aspx content:

<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.Master" AutoEventWireup="true" CodeBehind="Telerik RadEditor Bug Problem Demonstration.aspx.cs" Inherits="TelerikRadEditor.WebForm2" %><br><%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %><br><asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server"><br></asp:Content><br><asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server"><br>    <telerik:Radeditor CssClass="RadEditorCustomCSS" runat="server" ID="RadEditor" AutoResizeHeight="true"<br>        ToolsFile="EditorRibbonBar.xml" ToolbarMode="RibbonBar" StripFormattingOptions="MsWord,ConvertWordLists" ContentFilters="DefaultFilters,PdfExportFilter"><br>        <ImageManager ViewPaths="~/fileuploads/images" UploadPaths="~/fileuploads/images" DeletePaths="~/fileuploads/images" EnableImageEditor="true" MaxUploadFileSize="26214400"/><br>        <MediaManager ViewPaths="~/fileuploads/media" UploadPaths="~/fileuploads/media" DeletePaths="~/fileuploads/media" MaxUploadFileSize="26214400"/><br>        <FlashManager ViewPaths="~/fileuploads/flash" UploadPaths="~/fileuploads/flash" DeletePaths="~/fileuploads/flash" MaxUploadFileSize="26214400"/><br>        <TemplateManager ViewPaths="~/fileuploads/templates" UploadPaths="~/fileuploads/templates" DeletePaths="~/fileuploads/templates" MaxUploadFileSize="26214400"/><br>        <DocumentManager ViewPaths="~/fileuploads/documents" UploadPaths="~/fileuploads/documents" DeletePaths="~/fileuploads/documents" MaxUploadFileSize="26214400"/><br>    </telerik:Radeditor><br></asp:Content><br><asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder2" runat="server"><br></asp:Content

C# Code-Behind:

using System;<br>using System.Collections.Generic;<br>using System.Linq;<br>using System.Web;<br>using System.Web.UI.WebControls;<br><br>using System.IO;<br>using Telerik.Web.UI;<br>using Telerik.Web.UI.Editor.Import;<br>using Telerik.Windows.Documents.Flow.FormatProviders.Docx;<br>using Telerik.Windows.Documents.Flow.Model;<br>using Telerik.Windows.Documents.Flow.Model.Styles;<br><br> <br>namespace TelerikRadEditor<br>{<br>    public partial class WebForm2 : System.Web.UI.Page<br>    {<br>        protected void Page_Load(object sender, EventArgs e)<br>        {<br>            //Validate User<br>            //After validation, adjust the below settings accordingly...<br>            RadEditor TRE = RadEditor;<br>            String author = "aUser";<br>            String userColor = "reU0";<br><br>            //Note comments also uses the track change settings author and usercssid<br>            TRE.EnableComments = true;<br>            TRE.EnableTrackChanges = true;<br>            TRE.TrackChangesSettings.CanAcceptTrackChanges = true;<br>            TRE.TrackChangesSettings.Author = author;<br>            TRE.TrackChangesSettings.UserCssId = userColor;<br>        }<br>    }<br>}

 

 

Ianko
Telerik team
 answered on 10 Jun 2015
5 answers
338 views

This seemed easy but I'm having trouble changing the HeaderText of a column inside of the OnExportCellFormatting event when exporting my grid to Excel.

 

As an example I have a column with a headerText value of "11/2013</br>Actual" and I want to change change the </br> to a newline or CR  "/r/n" ? Whatever will make the header wrap and have "11/2013" above "Actual". Which is how it is displayed in the Grid.

In my tests setting the headerText inside of the OnExportCellFormatting as below does not work.

e.FormattedColumn.HeaderText = "New Header Text";

 

 

 

Julian
Top achievements
Rank 1
 answered on 10 Jun 2015
1 answer
1.1K+ views

The image is a little Add png icon (from examples) and it blows it up.  I can't find anywhere to make it the normal size (or force a size).  ItemStyle-width or height, HeaderStyle-width or height, or what's below don't have any affect on it.  See screenshot.

 

                               <MasterTableView DataMember="Devices" DataKeyNames="ArticleID" headerStyle-Font-Bold="true" AllowFilteringByColumn="true" PageSize="20" >


                                    <Columns>

                                        <telerik:GridButtonColumn
                                            CommandName="InitInsert"
                                            Text="Add a Claim for this Device"
                                            UniqueName="AddNewClaim"
                                            ButtonType="imageButton"
                                            ImageUrl="../../resources/Images/AddRecord.png"> <HeaderStyle Width="1px" /><ItemStyle Width="1px" /> </telerik:GridButtonColumn>
              
                                        <telerik:GridBoundColumn
                                            SortExpression="SerialNumber"
                                            HeaderText="Serial Number"
                                            HeaderButtonType="TextButton"
                                            DataField="SerialNumber"
                                            UniqueName="SerialNumber"
                                            HeaderStyle-Width="400"
                                            FilterControlWidth="100"
                                            CurrentFilterFunction="EqualTo"
                                            AutoPostBackOnFilter="True"
                                            AllowFiltering="True" />

                                        <telerik:GridBoundColumn SortExpression="ArticleID" HeaderText="Article ID" HeaderButtonType="TextButton"
                                            DataField="ArticleID" UniqueName="ArticleID" HeaderStyle-Width="800" FilterControlWidth="800" Visible="false" />
                                    </Columns>

Eyup
Telerik team
 answered on 10 Jun 2015
1 answer
169 views

Hello,

 I have a problem with Radcombox that is inside form template, I need that the first radcombo 

 

This is the code aspx 

<telerik:RadGrid runat="server" Id="rgDirecciones" AutoGenerateColumns="False"
                                    OnDeleteCommand="rgDirecciones_DeleteCommand"
                                    OnInsertCommand="rgDirecciones_InsertCommand"
                                    OnItemDataBound="rgDirecciones_ItemDataBound"
                                    OnUpdateCommand="rgDirecciones_UpdateCommand" CellSpacing="-1" GroupPanelPosition="Top" >
                                    <mastertableview datakeynames="IdDireccion,IdSucursal,IdEmpresa">
                                        <rowindicatorcolumn visible="False">
                                        </rowindicatorcolumn>
                                        <expandcollapsecolumn created="True">
                                        </expandcollapsecolumn>
                                        <Columns>
                                            <telerik:GridEditCommandColumn UniqueName="EditCommandColumn" ButtonType="ImageButton"
                                                EditImageUrl="../imagenes/Edit.png" InsertImageUrl="../imagenes/Edit.png" Exportable="False">
                                                <HeaderStyle Width="30px" />
                                            </telerik:GridEditCommandColumn>                           
                                            <telerik:GridBoundColumn DataField="IdDireccion" UniqueName="IdDireccion" HeaderText="No Dirección">
                                                <HeaderStyle Width="80px" />
                                            </telerik:GridBoundColumn>
                                            <telerik:GridBoundColumn DataField="TipoDireccion" UniqueName="TipoDireccion" HeaderText="Tipo">
                                                <HeaderStyle Width="80px" />
                                            </telerik:GridBoundColumn>
                                            <telerik:GridBoundColumn DataField="Direccion" UniqueName="Direccion" HeaderText="Dirección">
                                                <HeaderStyle Width="200px" />
                                            </telerik:GridBoundColumn>
                                            <telerik:GridBoundColumn DataField="Referencia" UniqueName="Referencia" HeaderText="Referencia">
                                                <HeaderStyle Width="200px" />
                                            </telerik:GridBoundColumn>
                                            <telerik:GridBoundColumn DataField="Organizacion" UniqueName="Organizacion" HeaderText="Organización">
                                                <HeaderStyle Width="200px" />
                                            </telerik:GridBoundColumn>
                                            <telerik:GridBoundColumn DataField="NombreContacto" UniqueName="NombreContacto" HeaderText="Nombre de Contacto">
                                                <HeaderStyle Width="200px" />
                                            </telerik:GridBoundColumn>
                                            <telerik:GridBoundColumn DataField="CodigoPostal" UniqueName="CodigoPostal" HeaderText="Código Postal">
                                                <HeaderStyle Width="130px" />
                                            </telerik:GridBoundColumn>
                                            <telerik:GridBoundColumn DataField="RowVersion" UniqueName="RowVersion" Display="False">
                                            </telerik:GridBoundColumn>
                                            <telerik:GridBoundColumn DataField="IdSucursal" UniqueName="IdSucursal" HeaderText="Sucursal" Display="False">
                                                <HeaderStyle Width="150px" />
                                            </telerik:GridBoundColumn>
                                            <telerik:GridBoundColumn DataField="Pais" UniqueName="Pais" Display="False">
                                            </telerik:GridBoundColumn>
                                            <telerik:GridBoundColumn DataField="DivisionTerritorial" UniqueName="DivisionTerritorial" Display="False">
                                            </telerik:GridBoundColumn>
                                            <telerik:GridButtonColumn ConfirmText="Desea eliminar este registro?" ConfirmDialogType="RadWindow" ConfirmTitle="Eliminar" ButtonType="ImageButton" CommandName="Delete" ImageUrl="../imagenes/Delete.png" UniqueName="DeleteColumn" Text="Eliminar" FilterControlAltText="Filter DeleteColumn column"  Exportable="False">
                                                <HeaderStyle Width="30px" />
                                            </telerik:GridButtonColumn>
                                        </Columns>
                                        <editformsettings editformtype="Template">
                                            <editcolumn filtercontrolalttext="Filter EditCommandColumn1 column" uniquename="EditCommandColumn1">
                                            </editcolumn>
                                            <formtemplate>
                                                <table class="table table-condensed">
                                                    <tr>
                                                        <td style="width: 150px">
                                                            <asp:Label ID="lbIdDireccion" runat="server" Text="No Dirección"></asp:Label>
                                                        </td>
                                                        <td>
                                                            <telerik:RadNumericTextBox ID="txtIdDireccion"
                                                                runat="server"
                                                                Enabled="<%# (Container is GridEditFormInsertItem) ? true : false %>"
                                                                MaxLength="2"
                                                                MaxValue="99"
                                                                MinValue="0"
                                                                Text='<%# Bind("IdDireccion") %>'
                                                                Width="80px">
                                                                <numberformat decimaldigits="0" groupseparator="" />
                                                            </telerik:RadNumericTextBox>
                                                            <asp:RequiredFieldValidator ID="rfvIdDireccion" runat="server"
                                                                ControlToValidate="txtIdDireccion" Display="Dynamic"
                                                                ErrorMessage="Campo Obligatorio" ForeColor="Red">
                                                            </asp:RequiredFieldValidator>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td style="width: 150px">
                                                            <asp:Label ID="lbPaisDire" runat="server" Text="País"></asp:Label>
                                                        </td>
                                                        <td>
                                                            <telerik:RadComboBox ID="cmbPais" Runat="server" Width="350px" Height="150px"
                                                                AutoPostBack="True" OnSelectedIndexChanged="combo_SelectedIndexChanged">
                                                            </telerik:RadComboBox>
                                                            <asp:RequiredFieldValidator ID="rfvcmbPais" runat="server" 
                                                                Display="Dynamic" ForeColor="Red"
                                                                ControlToValidate="cmbPais" ErrorMessage="Campo Obligatorio">
                                                            </asp:RequiredFieldValidator>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td style="width: 150px">
                                                            <asp:Label ID="lbDivisionTerritorial" runat="server" Text="División Territorial"></asp:Label>
                                                        </td>
                                                        <td>
                                                            <telerik:RadComboBox ID="cmbDivisionTerritorial" Runat="server" Width="350px">
                                                            </telerik:RadComboBox>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td style="width: 150px">
                                                            <asp:Label ID="lbDireccion" runat="server" Text="Direccion"></asp:Label>
                                                        </td>
                                                        <td>
                                                            <telerik:RadTextBox ID="txtDireccion" Runat="server" MaxLength="200" Text='<%# Bind("Direccion") %>' TextMode="MultiLine" Width="350px">
                                                                <ClientEvents OnValueChanging="removerMasDeUnEspacio" />
                                                            </telerik:RadTextBox>
                                                            <asp:RequiredFieldValidator ID="rfvtxtDireccion" runat="server" 
                                                                Display="Dynamic" ForeColor="Red"
                                                                ControlToValidate="txtDireccion" ErrorMessage="Campo Obligatorio">
                                                            </asp:RequiredFieldValidator>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td style="width: 150px">
                                                            <asp:Label ID="lbNombreContacto" runat="server" Text="NombreContacto"></asp:Label>
                                                        </td>
                                                        <td>
                                                            <telerik:RadTextBox ID="txtNombreContacto" Runat="server"
                                                                Text='<%# Bind("NombreContacto") %>' MaxLength="100" Width="350px">
                                                                <ClientEvents OnValueChanging="removerMasDeUnEspacio" />
                                                            </telerik:RadTextBox>
                                                            <asp:RequiredFieldValidator ID="rfvtxtNombreContacto" runat="server" 
                                                                Display="Dynamic" ForeColor="Red"
                                                                ControlToValidate="txtNombreContacto" ErrorMessage="Campo Obligatorio">
                                                            </asp:RequiredFieldValidator>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td style="width: 150px">
                                                            <asp:Label ID="lbOrganizacion" runat="server" CssClass="opcionales" Text="Organización"></asp:Label>
                                                        </td>
                                                        <td>
                                                            <telerik:RadTextBox ID="txtOrganizacion" Runat="server" Text='<%# Bind("Organizacion") %>'
                                                                MaxLength="100" Width="350px">
                                                                <ClientEvents OnValueChanging="removerMasDeUnEspacio" />
                                                            </telerik:RadTextBox>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td style="width: 150px">
                                                            <asp:Label ID="lbReferencia" runat="server" CssClass="opcionales" Text="Referencia"></asp:Label>
                                                        </td>
                                                        <td>
                                                            <telerik:RadTextBox ID="txtReferencia" Runat="server" Text='<%# Bind("Referencia") %>'
                                                                 MaxLength="100" Width="350px">
                                                                <ClientEvents OnValueChanging="removerMasDeUnEspacio" />
                                                            </telerik:RadTextBox>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td style="width: 150px">
                                                            <asp:Label ID="lbCodigoPostal" runat="server" CssClass="opcionales" Text="CodigoPostal"></asp:Label>
                                                        </td>
                                                        <td>
                                                            <telerik:RadTextBox ID="txtCodigoPostal" Runat="server" Text='<%# Bind("CodigoPostal") %>'
                                                                MaxLength="10" Width="80px">
                                                                <ClientEvents OnValueChanging="removerMasDeUnEspacio" />
                                                            </telerik:RadTextBox>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td colspan="2">
                                                            <telerik:RadButton ID="RadButton1" runat="server" causesvalidation="true" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>' Text='<%# (Container is GridEditFormInsertItem) ? "Agregar" : "Guardar" %>' validationgroup="Textbox">
                                                                <icon primaryiconurl="../imagenes/save_16x16.png" />
                                                            </telerik:RadButton>
                                                                
                                                            <telerik:RadButton ID="RadButton2" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancelar">
                                                                <icon primaryiconurl="../imagenes/cancel.png" />
                                                            </telerik:RadButton>
                                                                   
                                                            <asp:Label ID="Label2" runat="server" CssClass="opcionales" Text="* Opcionales"></asp:Label>
                                                        </td>
                                                    </tr>
                                                </table>
                                            </formtemplate>
                                        </EditFormSettings>
                                        <CommandItemTemplate>
                                            <div class="col-xs-6">
                                                <asp:LinkButton ID="lbAgregarDirecciones" runat="server" CommandName="InitInsert" Visible='<%# !rgDirecciones.MasterTableView.IsItemInserted %>'><img style="border:2px;vertical-align:middle;" alt="" src="../imagenes/AddRecord.png"/> Agregar</asp:LinkButton>  
                                                <asp:LinkButton ID="lbRefrescarDirecciones" runat="server">
                                                    <img style="border:2px;vertical-align:middle;" alt="" src="../imagenes/Refresh.png"/> Refrescar
                                                </asp:LinkButton>  
                                            </div>
                                            <uc1:opcionesimportaciongrid runat="server" id="OpcionesImportacionGrid3" Grid="rgDirecciones" WebForm='<%# Page.Request.RawUrl.Substring(Page.Request.RawUrl.LastIndexOf("/") + 1) %>'  NombreArchivo="Direcciones"/>
                                        </CommandItemTemplate>
                                    </mastertableview>
                                </telerik:RadGrid>

Code  

protected void rgDirecciones_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridEditFormItem && e.Item.IsInEditMode)//editform
            {
                GridEditableItem item = (GridEditableItem)e.Item;
                GridEditFormItem editItem = (GridEditFormItem)e.Item;
 
                if (!(e.Item is IGridInsertItem))
                {
                    RadComboBox comboTipoDirecciones = (RadComboBox)editItem.FindControl("cmbTipoDireccion");
                    comboTipoDirecciones.SelectedValue = editItem["TipoDireccion"].Text;
 
                    RadComboBox comboPais = (RadComboBox)editItem.FindControl("cmbPais");
                    comboPais.SelectedValue = editItem["Pais"].Text;
                }
            }           
        }
 
protected void combo_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
        {
            GridEditableItem editedItem = (sender as RadComboBox).NamingContainer as GridEditableItem;
            GridEditFormItem item = (sender as RadComboBox).NamingContainer as GridEditFormItem;
 
            RadComboBox comboPaises = sender as RadComboBox;
            RadComboBox comboDivisionTerritorial = (RadComboBox)editedItem.FindControl("cmbDivisionTerritorial");
 
            var parametrosSQL = new string[] { null, e.Value };
            DataSet ds = Clases.MetodosGlobales.ObtenerInformacionObjeto("ADMMDivisionesTerritoriales_get", parametrosSQL);
             
            comboDivisionTerritorial.Text = null;
            comboDivisionTerritorial.EmptyMessage = "- Seleccione un valor -";
            comboDivisionTerritorial.Filter = RadComboBoxFilter.StartsWith;
            comboDivisionTerritorial.DataSource = ds.Tables[0];
            comboDivisionTerritorial.DataTextField = "Descripcion";
            comboDivisionTerritorial.DataValueField = "Divisionterritorial";
            comboDivisionTerritorial.DataBind();
        }

The problem is that when I choose value of first radcombo. I fill the second radcombo but all the page load again and I lost the value of first combo and the second combo does not show the information. All the form is blank as if I did nothing

 I do not understand what is the problem.

Regards,

Konstantin Dikov
Telerik team
 answered on 10 Jun 2015
13 answers
412 views
I am using a TimelineView Scheduler and order in which displays items/appointment is pretty random. I have field in the Database called priority and based on the priority, the order of the items/appointment should be displayed.

Let says I have 3 appointments scheduled on the same day for example APP1,APP2 and APP3 and their priorities are 3,2 and 1. I want the scheduler to be displayed as APP3, APP2 and APP1 but instead it displays APP1, APP2 and APP3.

Any ideas how to crack this.

Praveen

jajati
Top achievements
Rank 1
 answered on 10 Jun 2015
3 answers
180 views

hi dear,
i want to thank you about this work :)  because  it is very well.
kindly your support to provide me with an example that print radgrid into html pages and keep the header of grid because i want this html page specific design such as this page should have an image before i put radgid elements then put some radgrid elements then put again image and repeate it again for all items in radgrid.
also i want to ask you if i have radgrid with paging, can i get elements from each page seperately.

can you support me with example of code for both two above problemsvery quickly. 

Thank you a lot.

Konstantin Dikov
Telerik team
 answered on 10 Jun 2015
1 answer
101 views

I have some Numeric Textboxes where I am using the OnValueChanging client event to do some validation and when I utilize the eventArgs.set_cancel(true) function, the value is reverted back to the old value, however the currency format is lost when I exit the field. If I reenter the field and exit again, the dollar sign will display properly.

 

Here is a sample of the script: 

function onValueChanging(sender, eventArgs) {
    var value = eventArgs.get_newValue();
 
    var txtTest = $find("<%= txtTest.ClientID %>");
 
    if ((value < sender.get_minValue()) || (value > txtTest.get_value())) {
        alert('Value must be a non-negative number and cannot exceed txtTest');
        eventArgs.set_cancel(true);
    }
}

Konstantin Dikov
Telerik team
 answered on 10 Jun 2015
1 answer
239 views

Hi,

We have a radgrid.We have a requirement like entering the time and finding the sum of all the cells and display into the last column  of the grid when columns are generating dynamically.

We have tried with client side event on row selected event but sum is not coming when moving from one cell to second cell.

Below i am giving the scenarios how we have used the client events please reply to this thread as early as possible.

 



 

1.       We are
able to fetch the selected cell value but unable to fetch the remaining
corresponding cell values. You can find the same in the sample project
(BatchEdit.aspx – OnBatchEditCellValueChanged event)
source code:
 <html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
      <script type="text/javascript">
          function BatchEditCellValueChanged(sender, args) {


              var grid = sender;

              var row = args.get_row();
              var cell = args.get_cell();
              var tableView = args.get_tableView();
              var column = args.get_column();
              var columnUniqueName = args.get_columnUniqueName();
              var editorValue = args.get_editorValue();
              var cellValue = args.get_cellValue();
              alert(editorValue);

              var columnlength = grid.get_masterTableView().get_columns().length;
              for (i = 0 ; i < columnlength; i++) {
                  cell = grid.get_masterTableView().get_columns()[i].get_uniqueName();
                  alert(cell);
              }

          }
    </script>

</head>
<body>
    <form id="form1" runat="server">
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server"></telerik:RadScriptManager>
       <div>
     <telerik:RadGrid ID="RadGrid1" runat="server">
        <MasterTableView EditMode="Batch" BatchEditingSettings-EditType="Cell">
        </MasterTableView>
        <ClientSettings>
            <Selecting AllowRowSelect="True" CellSelectionMode="MultiCell" />
            <ClientEvents OnBatchEditCellValueChanged="BatchEditCellValueChanged" />
        </ClientSettings>
    </telerik:RadGrid>
    </div>
    </form>
</body>
</html>

 code Behind:
public partial class BatchEdit : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        GetValues();
    }
    private void GetValues()
    {
        DataTable dtTable = new DataTable();
        dtTable.Columns.Add("Sum");
        dtTable.Columns.Add("Value1"); dtTable.Columns.Add("Value2");
        dtTable.Columns.Add("Value3"); dtTable.Columns.Add("Value4");

        DataRow dr = dtTable.NewRow();
        dr["Sum"] = "";
        dr["Value1"] = "1"; dr["Value2"] = "2";
        dr["Value3"] = "3"; dr["Value4"] = "4";
        dtTable.Rows.Add(dr);

        DataRow drr = dtTable.NewRow();
        drr["Sum"] = "";
        drr["Value1"] = "5"; drr["Value2"] = "6";
        drr["Value3"] = "7"; drr["Value4"] = "8";
        dtTable.Rows.Add(drr);


        RadGrid1.DataSource = dtTable;
        RadGrid1.DataBind();

    }
}
2.       We are
able to fetch the selected cell value and corresponding cell values in the same
row by hardcoding the column names, but dynamically we are unable to get the
values of the cell. You can find the same in the sample project
(OnRowSelected.aspx – OnRowSelected event)
source code:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="OnRowSelected.aspx.cs" Inherits="OnRowSelected" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>

  <script type="text/javascript">
      function RowSelected(sender, eventArgs) {
          var grid = sender;
          var MasterTable = grid.get_masterTableView();
         
          var row = MasterTable.get_dataItems()[eventArgs.get_itemIndexHierarchical()];
          var cell1 = MasterTable.getCellByColumnUniqueName(row, "Value1");
          var cell2 = MasterTable.getCellByColumnUniqueName(row, "Value2");
          var cell3 = MasterTable.getCellByColumnUniqueName(row, "Value3");
          var cell4 = MasterTable.getCellByColumnUniqueName(row, "Value4");
          var total = 0;
          var arr = [];
          var total = 0;
      
          var columnlength = grid.get_masterTableView().get_columns().length;
          for (i = 0 ; i < columnlength; i++) {
              cell = grid.get_masterTableView().get_columns()[i].get_uniqueName();
           
              var cell = MasterTable.getCellByColumnUniqueName(row, cell);
              var val = parseInt(cell.innerText);
              arr[i] = val;
             

          }
          for (i = 1; i < arr.length; i++) {

              total += arr[i];
          }

          var cell1 = MasterTable.getCellByColumnUniqueName(row, "Sum");
          cell1.innerText = total;
          cell1.eventArgs.set_cancel(true);


      }
    </script>
   <%-- var grid = $find("<%=RadGrid1.ClientID%>");
    var tableView = sender.get_masterTableView();
    var batchManager = sender.get_batchEditingManager();
    var items = tableView.get_dataItems();
    var mapValues = [];
    for (var i = 0; i < items.length; i++) {
        var mapCell = items[i].get_cell("Map");
        var mapValue = batchManager.getCellValue(mapCell);
        mapValues.push(mapValue);
    }--%>
</head>
<body>
    <form id="form1" runat="server">
         <telerik:RadScriptManager ID="RadScriptManager1" runat="server"></telerik:RadScriptManager>
         <asp:HiddenField ID="HiddenField1" runat="server" />
    <div>
    <telerik:RadGrid ID="RadGrid1" runat="server">
        <MasterTableView EditMode="Batch" BatchEditingSettings-EditType="Cell" >
        </MasterTableView>
        <ClientSettings>
            <Selecting AllowRowSelect="True" CellSelectionMode="MultiCell" />
            <ClientEvents OnRowClick="RowSelected" />
        </ClientSettings>
    </telerik:RadGrid>
    </div>
    </form>
</body>
</html>

code behind:

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

public partial class OnRowSelected : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        GetValues();
    }
    private void GetValues()
    {
        DataTable dtTable = new DataTable();
        dtTable.Columns.Add("Sum");
        dtTable.Columns.Add("Value1"); dtTable.Columns.Add("Value2");
        dtTable.Columns.Add("Value3"); dtTable.Columns.Add("Value4");

        DataRow dr = dtTable.NewRow();
        dr["Sum"] = "";
        dr["Value1"] = "1"; dr["Value2"] = "2";
        dr["Value3"] = "3"; dr["Value4"] = "4";
        dtTable.Rows.Add(dr);

        DataRow drr = dtTable.NewRow();
        drr["Sum"] = "";
        drr["Value1"] = "5"; drr["Value2"] = "6";
        drr["Value3"] = "7"; drr["Value4"] = "8";
        dtTable.Rows.Add(drr);


        RadGrid1.DataSource = dtTable;
        RadGrid1.DataBind();

    }
}
 

Angel Petrov
Telerik team
 answered on 10 Jun 2015
16 answers
1.1K+ views
Hi,

I have a webservice where i am creating the RadGrid Object dynamically. I have assigned the Dataview object as the datasource to this Grid. And now my requirement is to export this data directly to the filename which i mention in the code and it should be saved automatically i.e. i should not get the Save popup. I have tried the following code but it is not working faling in ExportToExcel saying "RadGrid must be databound before exporting telerik". Please let me know whether i would be able to save it directly to the file without rendering the grid control on the page as i have to do this in webservice method, no page is present. And why am getting the above mentioned error.

                RadGrid grid = new RadGrid(); 
                grid.ID = "radgridExportToExcel"
                grid.HeaderStyle.Font.Bold = true
                grid.DataSource = dsFileListToDelete.Tables[0].DefaultView; 
                string currentdatetime = DateTime.Now.ToString(); 
                string metadataReportName = string.Format(@"{0}\{1}_Metadata", Server.MapPath(@"~/WCCMetadataReports"), currentdatetime.Replace(" """).Replace("/""").Replace(":""")); 
                // render the DataGrid control to a file 
                grid.ExportSettings.ExportOnlyData = true
                grid.ExportSettings.IgnorePaging = true
                grid.ExportSettings.OpenInNewWindow = false
                grid.ExportSettings.FileName = metadataReportName; 
                grid.ExportSettings.Excel.Format = Telerik.Web.UI.GridExcelExportFormat.ExcelML; 
                grid.Rebind(); 
                grid.MasterTableView.ExportToExcel(); 

Kostadin
Telerik team
 answered on 10 Jun 2015
Narrow your results
Selected tags
Tags
+? more
Top users last month
Edmond
Top achievements
Rank 1
Iron
fabrizio
Top achievements
Rank 2
Iron
Veteran
RobMarz
Top achievements
Rank 2
Iron
Fakhrul
Top achievements
Rank 1
Iron
Tejas
Top achievements
Rank 2
Iron
Iron
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Edmond
Top achievements
Rank 1
Iron
fabrizio
Top achievements
Rank 2
Iron
Veteran
RobMarz
Top achievements
Rank 2
Iron
Fakhrul
Top achievements
Rank 1
Iron
Tejas
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?