Telerik Forums
UI for ASP.NET AJAX Forum
2 answers
91 views
When calculating width of the cell for export I was surprised when I discovered the following:
the handling of controls must be different when exporting to PDF and Excel

protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
 
            if (IsExport)
            {
                const int charWidth = 10;
                var gridWidth = 0;
 
                foreach (GridColumn column in MasterTableView.Columns)
                {
                    if (column is GridEditableColumn)
                    {
                        var columnWidth = 0;
                        var currentlyExportingTypes = column.CurrentFilterValue.GetTypesFromSeparatedString<DSExportType>();
 
                        if (currentlyExportingTypes.Count > 0 && !currentlyExportingTypes.Contains(_currentlyExportingType.Value) ||
                            column.HeaderText == "#" || column.UniqueName == "checker")
                        {
                            column.Visible = false;
                        }
 
                        if (column.Visible)
                        {
                            var alignmentCssClassPattern = new Regex("\\b(?<alignment>ca|la|ra)\\b");
                            var alignmentCssClassPatternMatch = alignmentCssClassPattern.Match(column.HeaderStyle.CssClass);
 
                            foreach (GridDataItem dataItem in MasterTableView.Items)
                            {
                                var currentColumnWidth = 0;
                                if (column is GridTemplateColumn)
                                {
                                    int labelLengths;
                                    switch (_currentlyExportingType)
                                    {
                                        case DSExportType.Excel:
                                            labelLengths =
                                                (from label in dataItem[column.UniqueName].Controls.OfType<LiteralControl>().Where(label => !label.Text.StartsWith("\r\n"))
                                                 select label.Text.Length).Sum();
                                            currentColumnWidth = labelLengths * charWidth;
                                            break;
                                        case DSExportType.Pdf:
                                            labelLengths =
                                                (from label in dataItem[column.UniqueName].Controls.OfType<WebControl>().OfType<Label>()
                                                 select label.Text.Length).Sum();
                                            var hyperLinkLengths =
                                                (from hyperLink in dataItem[column.UniqueName].Controls.OfType<WebControl>().OfType<HyperLink>()
                                                 select hyperLink.Text.Length).Sum();
                                            var imageWidths =
                                                (from image in dataItem[column.UniqueName].Controls.OfType<WebControl>().OfType<Image>()
                                                 select image.Width.Value).Sum();
                                            currentColumnWidth = labelLengths * charWidth + hyperLinkLengths * charWidth + Convert.ToInt32(imageWidths);
                                            break;
                                    }
                                }
                                else
                                {
                                    // Only for text types, should be check the type more carefully in common case!
                                    currentColumnWidth = dataItem[column.UniqueName].Text.Length * charWidth;
                                }
                                if (columnWidth < currentColumnWidth)
                                {
                                    columnWidth = currentColumnWidth;
                                }
                                if (alignmentCssClassPatternMatch.Success)
                                {
                                    switch (alignmentCssClassPatternMatch.Groups["alignment"].Value)
                                    {
                                        case "ca":
                                            dataItem[column.UniqueName].Style["text-align"] = "center";
                                            break;
                                        case "ra":
                                            dataItem[column.UniqueName].Style["text-align"] = "right";
                                            break;
                                        default:
                                            dataItem[column.UniqueName].Style["text-align"] = "left";
                                            break;
                                    }
                                }
                                dataItem[column.UniqueName].Style.Add("white-space", "nowrap");
                            }
                            foreach (GridHeaderItem headerItem in MasterTableView.GetItems(GridItemType.Header))
                            {
                                if (alignmentCssClassPatternMatch.Success)
                                {
                                    switch (alignmentCssClassPatternMatch.Groups["alignment"].Value)
                                    {
                                        case "ca":
                                            headerItem[column.UniqueName].Style["text-align"] = "center";
                                            break;
                                        case "ra":
                                            headerItem[column.UniqueName].Style["text-align"] = "right";
                                            break;
                                        default:
                                            headerItem[column.UniqueName].Style["text-align"] = "left";
                                            break;
                                    }
                                }
                            }
                            var finalColumnWidth = Math.Max(columnWidth, column.HeaderText.Length * charWidth);
                            column.HeaderStyle.Width = Unit.Pixel(finalColumnWidth);
                            gridWidth += finalColumnWidth;
                        }
                    }
                }
                ExportSettings.Pdf.PageWidth = Unit.Pixel(gridWidth + 2 * PdfGridPadding);
                _currentlyExportingType = null;
            }
        }
The given method works, but the question is

why in the case of Excel export there is only LiteralControl within dataItem[column.UniqueName].Controls? Where is the image, for instance? I need different types of controls to properly calculate cell width.

But when I am on image column - dataItem[image_column_unique_name].Controls also returns me only LiteralControls and no any reference to the used image:

<telerik:GridTemplateColumn HeaderStyle-CssClass='GridHeaderGreen ra' ItemStyle-CssClass='ra' UniqueName="image_column_unique_name">
    <ItemTemplate><asp:image runat="server" ImageUrl="~/images/something.png" /></ItemTemplate>
</telerik:GridTemplateColumn>


Alexander
Top achievements
Rank 1
 answered on 19 Jul 2011
7 answers
180 views
Hi All

I have two buttons inside a Grid Edit form,
I can see the text on the buttons but the skins are not rendering?
I have used this method before and it worked fine, the only difference is a am using Ajax Manager on this occasions and i used a panel before,
I have also found that on few few occasions the Datepicker's have not rendered properly, they have rendered as a frame,
the button error is constant though.

<EditFormSettings EditFormType="Template">
<FormTemplate>
   <table style="width: 100%;">
       <tr>
           <td align="left" width="25%">
               <asp:Label ID="MadeDteLabel" runat="server" Font-Bold="True" Font-Names="Arial" Font-Size="X-Small"
                   Text="Agreement Made:"></asp:Label>
           </td>
           <td align="left" width="25%">
               <telerik:RadDatePicker ID="MadeDatePicker" runat="server" Skin="Web20">
                   <Calendar runat="server" UseRowHeadersAsSelectors="False" UseColumnHeadersAsSelectors="False" ViewSelectorText="x"
                       Skin="Web20">
                   </Calendar>
                   <DateInput runat="server" DisplayDateFormat="dd/MM/yyyy" DateFormat="dd/MM/yyyy">
                   </DateInput>
                   <DatePopupButton ImageUrl="" HoverImageUrl=""></DatePopupButton>
               </telerik:RadDatePicker>
           </td>
           <td align="left" width="25%">
               <asp:Label ID="Label2" runat="server" Font-Bold="True" Font-Names="Arial" Font-Size="X-Small"
                   Text="RebateType:"></asp:Label>
           </td>
           <td align="left" colspan="2" width="25%">
               <telerik:RadComboBox ID="RebTypComboBox" runat="server" DataTextField="rebateType"
                   DataValueField="rebateTypeID" Skin="Web20" Width="150px">
                   <Items>
                       <telerik:RadComboBoxItem runat="server" Text="--" Value="0" Selected="true" />                   </Items>
               </telerik:RadComboBox>
           </td>
       </tr>
       <tr>
           <td align="left" width="25%">
               <asp:Label ID="RevDteLabel" runat="server" Font-Bold="True" Font-Names="Arial" Font-Size="X-Small"
                   Text="Rebate Revision Date:"></asp:Label>
           </td>
           <td align="left" width="25%">
               <telerik:RadDatePicker ID="RevDatePicker" runat="server" Skin="Web20">
                   <Calendar runat="server" UseRowHeadersAsSelectors="False" UseColumnHeadersAsSelectors="False" ViewSelectorText="x"
                       Skin="Web20">
                   </Calendar>
                   <DateInput runat="server" DisplayDateFormat="dd/MM/yyyy" DateFormat="dd/MM/yyyy">
                   </DateInput>
                   <DatePopupButton ImageUrl="" HoverImageUrl=""></DatePopupButton>
               </telerik:RadDatePicker>
           </td>
           <td align="left" width="25%">
               <asp:Label ID="Label1" runat="server" Font-Bold="True" Font-Names="Arial" Font-Size="X-Small"
                   Text="Rebate Amount:"></asp:Label>
           </td>
           <td align="left" colspan="2" width="25%">
               <telerik:RadNumericTextBox ID="RebateAmt" runat="server" Text='<%# Bind("rebate_amount") %>'
                   Skin="Web20" Width="70px">
               </telerik:RadNumericTextBox>
           </td>
       </tr>
       <tr>
           <td align="left" width="25%">
                  
           </td>
           <td align="left" width="25%">
               <asp:CheckBox ID="AgentRebApplyAllCB" runat="server" AutoPostBack="true" Font-Names="Arial"
                   Font-Size="X-Small" OnCheckedChanged="AgentRebApplyAllCB_CheckedChanged" Text="Apply To All Ports" />
           </td>
           <td align="left" width="25%">
                  
           </td>
           <td align="left" colspan="2" width="25%">
               <asp:Label ID="RebORLabel0" runat="server" Font-Bold="True" Font-Names="Arial" Font-Size="X-Small"
                   Text="Rate Terms:"></asp:Label>
           </td>
       </tr>
       <tr>
           <td align="left" width="25%">
               <asp:Label ID="RebAPLabel" runat="server" Font-Bold="True" Font-Names="Arial" Font-Size="X-Small"
                   Text="Applicable Port:"></asp:Label>
           </td>
           <td align="left" width="25%">
               <telerik:RadComboBox ID="RebAppPortComboBox" runat="server" Skin="Web20">
               </telerik:RadComboBox>
           </td>
           <td align="left" width="25%">
                  
           </td>
           <td align="left" colspan="2" width="25%">
               <telerik:RadComboBox ID="RebTermComboBox" runat="server" DataTextField="term_type"
                   DataValueField="termID" Skin="Web20" Width="150px">
                   <Items>
                       <telerik:RadComboBoxItem runat="server" Text="--" Value="0" Selected="true" />
                       <telerik:RadComboBoxItem runat="server" Text="Weekly" Value="1" />
                       <telerik:RadComboBoxItem runat="server" Text="Monthly" Value="2" />
                       <telerik:RadComboBoxItem runat="server" Text="Quaterly" Value="3" />
                       <telerik:RadComboBoxItem runat="server" Text="Half Year" Value="4" />
                       <telerik:RadComboBoxItem runat="server" Text="Yearly" Value="5" />
                   </Items>
               </telerik:RadComboBox>
           </td>
       </tr>
       <tr>
           <td align="left" width="25%">
                  
           </td>
           <td align="left" width="25%">
                  
           </td>
           <td align="left" width="25%">
                  
           </td>
           <td align="left" colspan="2" width="25%">
                  
           </td>
       </tr>
       <tr>
           <td align="left" width="25%">
                  
           </td>
           <td align="left" width="25%">
                  
           </td>
           <td align="left" width="25%">
                  
           </td>
           <td align="left" style="width: 12.5%" width="12.5%">
               <telerik:RadButton ID="btnUpdate" CommandName='<%#  Iif (TypeOf Container is GridEditFormInsertItem, "PerformInsert", "Update") %>'
                   runat="server" Skin="Web20" Text='<%#  Iif (TypeOf Container is GridEditFormInsertItem, "Insert", "Update") %>'>
               </telerik:RadButton>
           </td>
           <td align="left" style="width: 12.5%" width="12.5%">
               <telerik:RadButton ID="btnCancel" runat="server" Skin="Web20" CausesValidation="false"
                   CommandName="Cancel" Text="Cancel">
               </telerik:RadButton>
           </td>
       </tr>
   </table>
</FormTemplate>
</EditFormSettin



Any advice "As Always" would be appriciated.

Best Regards

Cush
    
Radoslav
Telerik team
 answered on 19 Jul 2011
7 answers
481 views
Hi,

I'm just playing around with the newest Version of the Rad Controls because I want to upgrade. But I can not get the async Upload working on the Server. Locally and if the browser is on the server itselve everything is working fine. But as soon as I acces the Page from outside the following Unhandled Exception is logged into the eventlog:

- Windows Server 2008
- The appPool is running in integrated mode as Networkservice.
- Networkservice has full control to the App_Data folder.
- In the Temporary Folder the full file is saved correctly
- I Switched on and off silverlight an flash AddOns on the client without a difference
- Happens in all browser (IE9 FF chrome safari) and works on all if started directly on the server...???

Any suggestions what I could have missed?

Kind regards from Germany,
Markus

Event code: 3005
Event message: An unhandled exception has occurred.
Event time: 03.07.2011 16:33:44
Event time (UTC): 03.07.2011 14:33:44
Event ID: 761ad93a40cc4dc4ab5767e64af73d63
Event sequence: 1937
Event occurrence: 6
Event detail code: 0
 
Application information:
    Application domain: /LM/W3SVC/16/ROOT-6-129541759904615022
    Trust level: Full
    Application Virtual Path: /
    Application Path: D:\inetpub\wwwroot\mytgaOffline.mahop.net\
    Machine name: KM35925
 
Process information:
    Process ID: 4132
    Process name: w3wp.exe
    Account name: NT-AUTORITÄT\NETZWERKDIENST
 
Exception information:
    Exception type: NullReferenceException
    Exception message: Object reference not set to an instance of an object.
   at System.Object.GetType()
   at Telerik.Web.UI.RadCompression.Compress(HttpApplication application)
   at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

 
 
Request information:
    Request URL: http://mytgaoffline.mahop.net/?RadUrid=d2bc3ea4-e58a-42b3-9cff-a8e1b81dcdbe
    Request path: /
    User host address: 88.217.25.192
    User:  
    Is authenticated: False
    Authentication Type:  
    Thread account name: NT-AUTORITÄT\NETZWERKDIENST
 
Thread information:
    Thread ID: 18
    Thread account name: NT-AUTORITÄT\NETZWERKDIENST
    Is impersonating: False
    Stack trace:    at System.Object.GetType()
   at Telerik.Web.UI.RadCompression.Compress(HttpApplication application)
   at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
 
 
Custom event details:

Genady Sergeev
Telerik team
 answered on 19 Jul 2011
5 answers
164 views
I have a RadGrid with a Nested table both of which have the same columns.

Currently when the expand column is clicked on an item of the MasterDetailView, the DetailTable is expanded but it is indented to the right.

Would that be possible to remove this indentation so that the DetailTable gets expanded on the same column?

I checked the generated html using FireFox and I saw that when a DetailTable is expanded a new row (<tr>) is inserted after the selected row. This new row has 2 columns and the detail table appear in its second column. The first column is just empty.

So, now what I'd need is to make the new row to have only 1 column rather than 2 columns.

Is my explanation understandable? 

Thanks
Pooya
Top achievements
Rank 1
 answered on 19 Jul 2011
1 answer
77 views
Hi,
     I am using SPRadEditor. When I open Image Manager/Media Manager the embedded video(in design mode) is visible on top of the Media Manager even thought the page behind the media manger lost focus. Anyone faced this issue?
Rumen
Telerik team
 answered on 19 Jul 2011
3 answers
123 views

We have a radgrid that gets bound in 2 different ways. This depends on what action has been performed on the page..e.g

1. select comboboxA - will bind radgrid via server side binding using NeedDataSource event
2. select comboboxB - will bind radgrid via page method + client side binding . Below are are the the main 2 javascript functions in use .

function GetDataForGrid() {     PageMethods.GetDataForGrid(GetDataForGridBy_Result, GetDataForGridByHeader_Failed);}

  

function GetDataForGrid_Result(result) { 

    var tableView = $find("<%=RadGrid.ClientID %>").get_masterTableView(); 

    tableView.set_dataSource(result.Value);

    tableView.dataBind();

}

 

The problem is, after the client side binding, if the user clicks on a certain row we need to do some processing in a server side event -  RadGrid_ItemCommand(object sender, GridCommandEventArgs e) ...
However when we obtain the datakey within this server side event, it is  always wrong....  

 

 

 

 

Tsvetoslav
Telerik team
 answered on 19 Jul 2011
3 answers
188 views
I am looking to replace a Standard Asp.net Listbox with a telerik RadListBox but there is inconsistent behavior between the two that is stopping me from achieving this.

I have an existing asp.net Listbox with AutoPostBack Set to true, which is used for navigation.  Focus is set on this control on page load and users can use the keyboard up and down arrow keys to navigate up and down this Listbox.  Because autopostback is set on this Listbox this causes a postback and the page is refreshed....

I swapped this control out for a RadListBox control and it works find Apart from:
Pressing up and down arrows on the keyboard doesnt cause a postback when autopostback is set.

This means I cant swap the control out as it doesn't match the functionality of the old fashioned listbox control.

Two Questions:
1. Am I doing anything wrong, can autopostback be set and can the RADListbox postback on keyboard arrow up and arrow down
2. If not can this bug be fixed to match standard functionality of the standard Listbox control

Thanks
Genady Sergeev
Telerik team
 answered on 19 Jul 2011
10 answers
180 views
Hi,

Do we have Property Grid Control for Windows Forms?

Thanks,
Albert
Nikolay
Telerik team
 answered on 19 Jul 2011
4 answers
150 views
Hi,

I'm currently trying to open a radWindow on a parent page from a click on a button on a toolBar inside a grid (I get the idea from this demo), but it doesn't work well. The only thing I can do is to open the new window behind the current window and the modal/title attribute don't work at all (but the size it correct). If I try to open the window from a standard button, it works just fine. Is it anyone who know why this doesn't work ?

Thank you
David

Here is my code :

Default.aspx :

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<head runat="server">
    <title></title>
    <telerik:RadStyleSheetManager id="RadStyleSheetManager1" runat="server" />
</head>
<body>
    <form id="form1" runat="server">
    <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
        <Scripts>
            <%--Needed for JavaScript IntelliSense in VS2010--%>
            <%--For VS2008 replace RadScriptManager with ScriptManager--%>
            <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>
    </telerik:RadScriptManager>
    <script type="text/javascript">
        function yo(sender, e) {
            radopen("test.aspx", null);
        }
    </script>
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
    </telerik:RadAjaxManager>
     
    <telerik:RadWindowManager ID="RadWindowManager1" runat="server"
            EnableShadow="true" RestrictionZoneID="RestrictionZone"
            ShowContentDuringLoad="False">
        <Windows>
            <telerik:RadWindow ID="win1" runat="server" VisibleStatusbar="false" Behaviors="Close,Move" Width="750px" Height="400px" Modal="true" Title="I'm not working" />
        </Windows>
    </telerik:RadWindowManager>
     
    <div>
        <telerik:RadButton ID="yo" runat="server" Text="yo" AutoPostBack="false" OnClientClicked="yo">
        </telerik:RadButton>
    </div>
    </form>
</body>
</html>


test.aspx:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<head runat="server">
    <title></title>
 
    <script type="text/javascript">
        function here(sender, e) {
            var win = GetRadWindow().BrowserWindow;
            win.radopen(null, "win1"); // Open a window that is define in the radWindowManager of the parentPage
        }
 
        // Donne la référence d'une fenêtre radWindow
        function GetRadWindow() {
            var oWindow = null;
            if (window.radWindow)
                oWindow = window.radWindow;
            else if (window.frameElement.radWindow)
                oWindow = window.frameElement.radWindow;
            return oWindow;
        }
    </script>
 
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <telerik:RadButton ID="but1" runat="server" AutoPostBack="false" Text="Click here Dude!"
            OnClientClicked="here">
        </telerik:RadButton>
 
        <telerik:RadScriptManager runat="server"></telerik:RadScriptManager>
 
        <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" OnNeedDataSource="RadGrid1_needDS">
            <MasterTableView AutoGenerateColumns="false" Name="test" CommandItemDisplay="Top"
                    DataKeyNames="Id">
                <CommandItemTemplate>
                    <telerik:RadToolBar ID="RadToolBarGrid" runat="server" OnClientButtonClicking="here">
                        <Items>
                            <telerik:RadToolBarButton Text="Add new" ImageUrl="~/Images/Add.png">
                            </telerik:RadToolBarButton>
                        </Items>
                    </telerik:RadToolBar>
                </CommandItemTemplate>
                <Columns>
                    <telerik:GridBoundColumn DataField="Id" HeaderText="Id" UniqueName="Id">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="Title" HeaderText="Title" UniqueName="Title">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="Style" HeaderText="Style" UniqueName="Style">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="Rating" HeaderText="Rating" UniqueName="Rating">
                    </telerik:GridBoundColumn>
                </Columns>
            </MasterTableView>
        </telerik:RadGrid>   
    </div>
    </form>
</body>
</html>


test.aspx.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
 
namespace RadControlsWebApp5
{
    public partial class test : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
 
        }
 
        protected void RadGrid1_needDS(object sender, EventArgs e)
        {
            List<movie> movies = new List<movie>();
 
            movies.Add(new movie(1, "King Kong", "Action", "4/5"));
            movies.Add(new movie(2, "The Black Knight", "Action", "4.5/5"));
            movies.Add(new movie(3, "Harry Potter and the deadly hallow", "Fantasy", "4/5"));
            movies.Add(new movie(4, "Inception", "Sc-fiction", "5/5"));
            movies.Add(new movie(5, "Transformer : The revenge of the fallen", "Action, Sc-Fiction", "3/5"));
 
            RadGrid1.DataSource = movies;
        }
    }
 
    public class movie
    {
        public movie(int id, string title, string style, string rating)
        {
            Id = id;
            Title = title;
            Style = style;
            Rating = rating;
        }
 
        public int Id { get; private set; }
        public string Title { get; private set; }
        public string Style { get; private set; }
        public string Rating { get; private set; }
    }
}


EDIT :

Sorry, I notice that the title just work fine in this example. In fact, I realize that if I set a title in the <title></title> in the head of a aspx page, this title come over the title of the window setting.  
David
Top achievements
Rank 1
 answered on 19 Jul 2011
2 answers
251 views
Hi all,

I am using GridDateTimeColumn, there is little bit confused about its filters.
In the "EqualTo", it requires user to input exactly date and time.
Are there anyways to ignore the time?
For example, "07/15/11" for the result of that day, no need "07/15/11 3:13"

Thanks.

Andy.
Jayesh Goyani
Top achievements
Rank 2
 answered on 19 Jul 2011
Narrow your results
Selected tags
Tags
+? more
Top users last month
Rob
Top achievements
Rank 3
Bronze
Bronze
Iron
Sergii
Top achievements
Rank 1
Iron
Iron
Dedalus
Top achievements
Rank 1
Iron
Iron
Lan
Top achievements
Rank 1
Iron
Doug
Top achievements
Rank 1
Want to show your ninja superpower to fellow developers?
Top users last month
Rob
Top achievements
Rank 3
Bronze
Bronze
Iron
Sergii
Top achievements
Rank 1
Iron
Iron
Dedalus
Top achievements
Rank 1
Iron
Iron
Lan
Top achievements
Rank 1
Iron
Doug
Top achievements
Rank 1
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?