Telerik Forums
UI for ASP.NET AJAX Forum
0 answers
111 views

Hello,

I've created a new GridColumn that inherits the Gridboudcolumn.

This new column contains a HtmlGenericControl (containing the text) and an image with some javascript on the client click event. Everything works fine excepts when I want to export the datas in Excel. The value is always empty.

As a workaround, I put an image with 0px height and 0px with as the first control of the cell and set the AlternateText property of this image, that does the trick but this is not a valid solution for us.

How can I do this in the good way ?

Best regards

Alexandre Stoppani

 

This is the code of my class:

using System;
using System.Collections.Generic;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;

using Telerik.Web.UI;

namespace Ch.Ne.Ceg.Library.Web.WebControls.Sfwk.SFWKGrid
{
    public class MailReadOnlyColumn : GridBoundColumn
    {
        #region Events

        public override void InitializeCell(TableCell cell, int columnIndex, GridItem inItem)
        {
            if (inItem is GridDataItem item)
            {
                if (cell != null && cell.Controls.Count > 0)
                {
                    cell.Controls.Clear();
                }

                if (cell != null)
                    cell.Text = "";

                var alienSpan = new HtmlGenericControl();

                var nobr = new HtmlGenericControl("nobr");
                nobr.Attributes["class"] = "MailReadOnlyColumnNoBold";

                var imageHiddenForExport = new ImageButton
                {
                    Visible = true,
                    Height = new Unit(0),
                    Width = new Unit(0),
                    CommandName = "RowClick",
                    CommandArgument = item.ItemIndex.ToString(),
                    ImageAlign = ImageAlign.Middle,
                    ImageUrl = cell?.Page.ClientScript.GetWebResourceUrl(GetType(), "Ch.Ne.Ceg.Library.Web.WebControls.Images.milieu.png")
                };

                var image = new ImageButton
                {
                    Visible = true,
                    Height = new Unit(0),
                    Width = new Unit(0),
                    CommandName = "RowClick",
                    CommandArgument = item.ItemIndex.ToString(),
                    ImageAlign = ImageAlign.Middle
                };
                image.Style.Add(HtmlTextWriterStyle.PaddingLeft, "6px");
                image.Style.Add(HtmlTextWriterStyle.Height, "9px");
                image.Style.Add(HtmlTextWriterStyle.Width, "14px");
                image.Style.Add(HtmlTextWriterStyle.PaddingTop, "8px");
                image.Style.Add(HtmlTextWriterStyle.Cursor, "default");

                nobr.Controls.Add(alienSpan);
                nobr.Controls.Add(image);

                if (cell != null)
                {
                    cell.DataBinding += cell_DataBinding;

                    cell.Controls.Add(imageHiddenForExport);

                    cell.Controls.Add(nobr);
                }
            }
            else
            {
                base.InitializeCell(cell, columnIndex, inItem);
            }
        }

        void cell_DataBinding(object sender, EventArgs e)
        {
            if (!(sender is TableCell cell))
                return;

            var parent = cell.NamingContainer as GridDataItem;

            var imageHiddenForExport = cell.Controls[0] as ImageButton;
            var lbl = cell.Controls[1].Controls[0] as HtmlGenericControl;
            var imgButton = cell.Controls[1].Controls[1] as ImageButton;

            if (parent == null)
                return;

            var t = parent.DataItem.GetType();
            var p = t.GetProperty(DataField);

            if (p == null)
                return;

            var value = (string)p.GetValue(parent.DataItem, null);

            if (lbl != null)
                lbl.InnerText = string.IsNullOrEmpty(value) ? "-" : value;

            if (imageHiddenForExport != null)
                imageHiddenForExport.AlternateText = value;
            
            if (imgButton != null)
            {
                if (string.IsNullOrEmpty(value))
                {
                    imgButton.ImageUrl = null;
                    imgButton.Enabled = false;
                    imgButton.Visible = false;
                }
                else
                {
                    imgButton.ImageUrl = ((TableCell)sender).Page.ClientScript.GetWebResourceUrl(GetType(), "Ch.Ne.Ceg.Library.Web.WebControls.Images.enveloppe.png");
                    imgButton.AlternateText = value;
                    imgButton.OnClientClick = "mywindow=window.open('mailto:" + value + "'); if(mywindow != null) mywindow.close(); return false;";
                    imgButton.Visible = true;
                    imgButton.Enabled = true;
                }
            }
        }

        #endregion
    }
}

Alexandre
Top achievements
Rank 1
 asked on 19 Feb 2019
7 answers
707 views
Hi,

if I have designed a search page using Telerik controls and show this page using IE10/11 each input field (TextBox, ComboBox) has a clear (X) button inside. When I 've entered some text and click onto "Search" the page postback and my code behnd is working. After the postback was finished, the value I have entered will be shown in my search field. When I click the IE10 clear (X) button, the search field will be cleared. But when I click "Search" again, after the postback the value will be shown. Why? Does Telerik controls not support the IE clear button?
And if not, how to hide this button.

::-ms-clear { display: none; } is not working if document mode was fixed to IE8 for specific reason.

Any help?

Regards,
Ralf
Peter Milchev
Telerik team
 answered on 19 Feb 2019
0 answers
98 views

I have a that lists fax numbers and have it formatted to look like a table.  I would like when they click on the delete.png it would delete out of the database they clicked on.  Should it be done via code behind or via the SQL connection?  Not sure of how to go about this.  

 

        <telerik:RadComboBox runat="server" ID="_Phone1" Height="100px" Width="450px" DataTextField="FaxNum" DataValueField="FaxNum"
            DataSourceID="DataSource1" EnableLoadOnDemand="false"  DropDownCssClass="exampleRadComboBox" AllowCustomText="true" OnClientLoad="attachPaste" ValidationGroup="Group1"
            Filter="StartsWith" EmptyMessage="Enter fax number or search favorites">
        <HeaderTemplate>
            <ul>
                <li class="col1">Description</li>
                <li class="col2">Fax #</li>
                <li class="col3">Last Sent</li>
            </ul>
        </HeaderTemplate>
        <ItemTemplate>
            <ul>
                <li class="col1">
                    <%# DataBinder.Eval(Container.DataItem, "Description") %></li>
                <li class="col2">
                    <%# DataBinder.Eval(Container.DataItem, "FaxNum") %></li>
                <li class="col3">
                    <%# DataBinder.Eval(Container.DataItem, "LastSent") %></li>
                <li class="col4"><img runat="server" src="~/images/Delete.png" />
                    <%# DataBinder.Eval(Container.DataItem, "FaxFavID") %></li>
            </ul>
        </ItemTemplate>
    </telerik:RadComboBox>
<asp:SqlDataSource ID="DataSource1" runat="server"
    ConnectionString="<%$ ConnectionStrings:FMS_Conn %>" SelectCommandType="StoredProcedure" SelectCommand="Modules.sp_getFaxFav">
    <SelectParameters>
        <asp:SessionParameter Name="iUser_Id" SessionField="user_id" Type="String" />
    </SelectParameters>
</asp:SqlDataSource>
Kurt Kluth
Top achievements
Rank 1
 asked on 18 Feb 2019
0 answers
49 views

I have ShowFooter property set to true and in code ShowFullTime= true

In UI  bydefault its showing 24 hours format and on footer its showing Show Business hours. when clicked on ShowBusinessHours Its showing 12 hours format and on footer its showing button with label show 24 hours but ,when clicked on show 24 hours its not happening.Do I need to make any code change to show 24 hours.

One more help.In Left side ruler I want show time 24 hours like 12:00pm,01:00pm now its showing 12pm,1pm how to make changes for ASP.net webapplication.

When searched on forum i got we need to make change using RulerPrimitive and FormatStrings But this is for Windows forms how i can i make change for asp.net ajax

 

 

Renuka
Top achievements
Rank 1
 asked on 18 Feb 2019
1 answer
164 views

HI All,

I am working on asp.net application. Have added multiple radgrid and multiple radhtmlchart programmatically to div. when I try exporting the div (which has multiple radgrid and multiple radhtmlchart) using RadClientExportManager I get only radgrids downloaded as pdf but not radhtmlchart. I googling I found this link  https://feedback.telerik.com/aspnet-ajax/1377381-radclientexportmanager-does-not-export-htmlchart-in-multi-page-export-scenarios.
My requirement is exporting multiple radgrid and multiple radhtmlchart in div to pdf.

Can anyone please help me in implementing this requirement?

I have tried using itextsharp and Telerik radclientexportmanager both fail to export to pdf.

Peter Milchev
Telerik team
 answered on 18 Feb 2019
2 answers
1.2K+ views
Hi,
i have a rad grid that for some reason will not show the scrollbars when the grid is full size.
The grid is nested inside a pageview which is 500px wide.
the grid itself is 493px wide.

now if i reduce the grid size down to 350px then the scrollbar shows up. however anything over that it disappears.
I've tried changing all the values of the pageview size and grid size etc but nothing seem to work.

Anyone know how to fix this?

Tuhiram
Top achievements
Rank 1
 answered on 16 Feb 2019
7 answers
381 views
I have telerik:2RadTimePicker controls with in grid and I want to get the time using javascript. 

one is Start Time other one is  End Time i have to check the Validation  is Start Time Could be > End Time .

Is there any possibility to do this one on when user enter the End Time it will check the validation and throw a error with alert message,

and how to get time form time picker using javascript and do the validations and i want to show the timepicker with redcolor where the time validation is false 


Any Suggestions.,

Regards 

SR.
Attila Antal
Telerik team
 answered on 15 Feb 2019
4 answers
169 views

Hi,
    I have a weird issue with rad listbox filtering. I tried to attach that, but the post didn't allowed me to. I will write the code here.

<form id="form1" runat="server">
    <div>
        <telerik:RadScriptManager ID="script1" runat="server"></telerik:RadScriptManager>
        <asp:Panel ID="pnlMainFields" runat="server">
                <table>
                    <tr>
                        <td>
                            <table>
                                <tr>
                                    <td>
                                        <h3>Available Fields</h3>
                                        <table>
                                            <tr>
                                                <td>
                                                    <asp:CheckBox ID="chkShowAdvanced" runat="server" Text="Show advanced columns" AutoPostBack="true" />
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    <telerik:RadTextBox ID="tbAvailableFilter" runat="server"
                                                        Width="187px"
                                                        EmptyMessage="Search ..."
                                                        autocomplete="off"
                                                        onkeyup="filterList();" />
                                                    <telerik:RadButton ID="rbtnClear" runat="server"
                                                        Width="22px"
                                                        AutoPostBack="false"
                                                        OnClientClicking="rbtnClear_OnClientClicking">
                                                        <Icon PrimaryIconCssClass="rbClear" />
                                                    </telerik:RadButton>
                                                </td>
                                            </tr>
                                        </table>
                                             
 
                                    </td>
                                    <td></td>
                                    <td>
                                        <h3>Selected Fields</h3>
                                    </td>
                                </tr>
                                <tr>
                                    <td style="vertical-align:top">
                                        <telerik:RadListBox ID="lstAvailable" runat="server"
                                                        Height="250px"
                                                        Width="250px"
                                                        AllowTransfer="true"
                                                        AllowTransferOnDoubleClick="true"
                                                        TransferToID="lstSelected"
                                                        EnableDragAndDrop="true"
                                                        OnClientTransferring="lstAvailable_OnClientTransferring"
                                                        ButtonSettings-ShowTransferAll="false" SelectionMode="Multiple" />
                                    </td>
                                    <td style="vertical-align: middle">
                                        <asp:ImageButton ID="btnMoveToSelected" runat="server" ImageUrl="/images/app/Button-Add.jpg" Visible="false" /><br />
                                        <asp:ImageButton ID="btnMoveToAvailable" runat="server" ImageUrl="/images/app/Button-Remove.jpg" Visible="false" />
                                    </td>
                                    <td>
                                        <telerik:RadListBox ID="lstSelected" runat="server"
                                            Height="250px"
                                            Width="250px"
                                            EnableDragAndDrop="true"
                                            AllowReorder="true" />
                                     </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                    <tr>
                        <td></td>
                    </tr>
                    <tr>
                        <td></td>
                    </tr>
                </table>
            </asp:Panel>
    </div>
    <telerik:RadCodeBlock runat="server">
    <script type="text/javascript">
 
        function filterList() {
            var listbox = $find("<%= lstAvailable.ClientID%>");
            var textbox = $find('<%= tbAvailableFilter.ClientID %>');
 
            clearListEmphasis(listbox);
            createMatchingList(listbox, textbox.get_textBoxValue());
        }
 
        // Remove emphasis from matching text in ListBox
        function clearListEmphasis(listbox) {
            var re = new RegExp("</{0,1}em>", "gi");
            var items = listbox.get_items();
            var itemText;
 
            items.forEach
            (
                function (item) {
                    itemText = item.get_text();
                    item.set_text(itemText.replace(re, ""));
                }
            )
        }
 
        // Emphasize matching text in ListBox and hide non-matching items
        function createMatchingList(listbox, filterText) {
            if (filterText != "") {
                filterText = escapeRegExCharacters(filterText);
 
                var items = listbox.get_items();
                var re = new RegExp(filterText, "i");
 
                items.forEach
                (
                    function (item) {
                        var itemText = item.get_text();
 
                        if (itemText.match(re)) {
                            item.set_text(itemText.replace(re, "<em>" + itemText.match(re) + "</em>"));
                            item.set_visible(true);
                        }
                        else {
                            item.set_visible(false);
                        }
                    }
                )
            }
            else {
                var items = listbox.get_items();
 
                items.forEach
                (
                    function (item) {
                        item.set_visible(true);
                    }
                )
            }
        }
 
        function lstAvailable_OnClientTransferring(sender, eventArgs) {
            // Transferred items retain the emphasized text, so it needs to be cleared.
            clearListEmphasis(sender);
            // Clear the list. Optional, but prevents follow up situation.
            clearFilterText();
            createMatchingList(sender, "");
        }
 
        function rbtnClear_OnClientClicking(sender, eventArgs) {
            clearFilterText();
 
            var listbox = $find("<%= lstAvailable.ClientID %>");
 
            clearListEmphasis(listbox);
            createMatchingList(listbox, "");
        }
 
        // Clears the text from the filter.
        function clearFilterText() {
            var textbox = $find('<%= tbAvailableFilter.ClientID %>');
            textbox.clear();
        }
 
        // Escapes RegEx character classes and shorthand characters
        function escapeRegExCharacters(text) {
            return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
        }
 
    </script>
</telerik:RadCodeBlock>
</form>

 

The code to populate data is

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
 
       If Not Page.IsPostBack Then
           ListAvailableFields()
       End If
   End Sub
 
   Private Sub ListAvailableFields()
 
       lstAvailable.Items.Clear()
       For temp As Integer = 1 To 10
           Dim name As String = $"Enabled {temp}"
           lstAvailable.Items.Add(New Telerik.Web.UI.RadListBoxItem(name, name))
 
           name = $"Disabled {temp}"
           lstAvailable.Items.Add(New Telerik.Web.UI.RadListBoxItem(name, name))
 
 
       Next
 
   End Sub

 

     Now, type something in the list. For example, type "Enabled" so that it filters all enabled columns.

     Once filtered , Click on first search result, HOLD down the shift key and Click on the last item in the grid to select ALL values in the listbox.

     Click on the right arrow and it should Copy all the selected values to the right grid.

      However, you will notice that it copied over Enabled xx as well as Disabled xx which was not in the search result.

    That is a problem, I filtered only "Enabled" but it moved "Disabled" as well.

     It seems list is hiding the items only, but when you select multiple using SHIFT key, it includes them. Selecting as many items as you can, using one at a time, will not be an issue.

 

      Any thoughts on this should be appreciated.

      Thank you

Sameers
Top achievements
Rank 1
 answered on 15 Feb 2019
3 answers
69 views

I have a usercontrol as my edit form, and a property called DataItem that gets bound, one item of which is called ItemID and is bound to a HiddenField. 

<asp:HiddenField ID="itemID" runat="server" Visible="false" Value='<%# DataBinder.Eval(Container, "DataItem.ItemID") %>' />

Everything seems good, form renders. I have two controls I call by button click, and in those handlers I can get the value of the HiddenField ItemID to pass its value along in a url.

"&ItemID=" & itemID.Value.ToString() &

 

The problem comes in when in Page_Load, I want to restrict whether to show these controls or not by the value of ItemID.  In Page_Load, itemID.Value is empty, presumably because the page hasn't loaded yet, and while _dataItem seems to exist, it has no fields yet.  Is there an event I can tie into to say 'run this after _dataItem has been bound'? There is OnDataBound, but the note on the documentation page says only useful with client side data binding and my solution uses NeedsDataSource.

Attila Antal
Telerik team
 answered on 15 Feb 2019
12 answers
406 views
When I try tabbing though my radgrid, it goes to the header, then the footer, then the actual body of the grid. I believe that this is happening because the tfoot tag is rendered before tbody. Is there any way to change that?
Rumen
Telerik team
 answered on 14 Feb 2019
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?