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

I have a radlistview item. On clicking of radlistview item i am generating dynamic controls as show in the code. Since dynamically generate controls not retain across post back so recreating every time. Controls are working fine but not generating in a proper order. All controls should generate one by one on clicking of list view but those are messing around, please some one suggest me how can i resolve this?
Thanks.

MARK UP:

<div id="divListView" style="overflow: auto; width: 100%;" class="sortable">
 <telerik:RadListView ID="RadListView1" runat="server" RenderMode="Lightweight" DataKeyNames="Label" ClientDataKeyNames="Label" ItemPlaceholderID="ListViewPlaceHolder1">                                 
    <LayoutTemplate>
       <div class="RadListView RadListView_Silk">
          <table id="orgcharttable" class="layoutTable" width="100%">
             <tr>
                 <td colspan="3" class="nopadding">
                    <asp:PlaceHolder ID="ListViewPlaceHolder1" runat="server"></asp:PlaceHolder>
                 </td>
             </tr>
          </table>
      </div>
  </LayoutTemplate>
 <ItemTemplate>
      <div id="divHighlight" class="ListViewStyle" onclick="SelectControl(this,event);">
          <div style="vertical-align: top; width: 100%">
              <table>
                 <tr id="tr1">
                    <td colspan="2" class="tdnormal">
                        <telerik:RadLabel ID="lbl1" runat="server" Text='<%# Bind("Label")%>' Font-Bold="true" CssClass="ItemHeaderStyle"></telerik:RadLabel>
                     </td>
                 </tr>
                 <tr id="tr2">
                     <td rowspan="2" colspan="1" style="width: 5%">
                     </td>
                 </tr>
             </table>
         </div>
      </div>
     </ItemTemplate>
  </telerik:RadListView>
 
  <asp:Table ID="Table1" runat="server" EnableViewState="false"></asp:Table>

Code Behind:

protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            RadListView1.DataSource = GetDatatable();
            RadListView1.DataBind();
        }
        else
        {
            RecreateControls("rtb", "RadTextBox");
            RecreateControls("rcb", "RadComboBox");              
        }
    }
    public DataTable GetDatatable()
    {
        DataTable dt = new DataTable();
        dt.Columns.Add("Label");
        dt.Rows.Add("RadTextBox");
        dt.Rows.Add("RadComboBox");
        return dt;
    }
protected void RadAjaxManager1_AjaxRequest(object sender, Telerik.Web.UI.AjaxRequestEventArgs e)
    {
        string commandText = e.Argument.ToString().Trim();
        string[] splitdata = commandText.Split('&');
        commandText = splitdata[0];
        string controlName = splitdata[1];
        switch (controlName)
        {
            case "RadTextBox":
                int cnt1 = FindOccurence("rtb") + 1;
                DynamicControls dcTextBox = new DynamicControls();
                TableCell txtlblRad = dcTextBox.Controlscreation("RadLabel", "", cnt1, cnt1, "Text Box:", "", 0);
                TableCell txtRad = dcTextBox.Controlscreation("RadTextBox", "", cnt1, cnt1, "", "", 0);
                TableRow txtRow = new TableRow();
                txtRow.Cells.Add(txtlblRad);
                txtRow.Cells.Add(txtRad);
                Table1.Rows.Add(txtRow);
                break;
            case "RadComboBox":
                int cnt2 = FindOccurence("rcb") + 1;
                DynamicControls dcComboBox = new DynamicControls();
                TableCell combolblRad = dcComboBox.Controlscreation("RadLabel", "", cnt2, cnt2, "Combo box:", "", 0);
                TableCell comboRad = dcComboBox.Controlscreation("RadComboBox", "", cnt2, cnt2, "", "", 0);
                TableRow comboRow = new TableRow();
                comboRow.Cells.Add(combolblRad);
                comboRow.Cells.Add(comboRad);
                Table1.Rows.Add(comboRow);
                break;
        }
}
private void RecreateControls(string ctrlPrefix, string ctrlType)
    {
        string[] ctrls = Request.Form.ToString().Split('&');
        int cnt = FindOccurence(ctrlPrefix);
        if (cnt > 0)
        {
            for (int k = 1; k <= cnt; k++)
            {
                for (int i = 0; i < ctrls.Length; i++)
                {
                    if (ctrls[i].Contains(ctrlPrefix + "_" + k.ToString()))
                    {
                        if (ctrlType == "RadTextBox")
                        {
                            DynamicControls dcTextBox = new DynamicControls();
                            TableCell txtlblRad = dcTextBox.Controlscreation("RadLabel", "", k, k, "TextBox:", "", 0);
                            TableCell txtRad = dcTextBox.Controlscreation("RadTextBox", "", k, k, "", "", 0);
                            TableRow txtRow = new TableRow();
                            txtRow.Cells.Add(txtlblRad);
                            txtRow.Cells.Add(txtRad);
                            Table1.Rows.Add(txtRow);
                        }
                        if (ctrlType == "RadComboBox")
                        {
                            DynamicControls dcComboBox = new DynamicControls();
                            TableCell combolblRad = dcComboBox.Controlscreation("RadLabel", "", k, k, "Combo box:", "", 0);
                            TableCell comboRad = dcComboBox.Controlscreation("RadComboBox", "", k, k, "", "", 0);
                            TableRow comboRow = new TableRow();
                            comboRow.Cells.Add(combolblRad);
                            comboRow.Cells.Add(comboRad);
                            Table1.Rows.Add(comboRow);
                        }
                     }
                 }
              }
           }
        }
private int FindOccurence(string substr)
    {
        string reqstr = Request.Form.ToString();         
        return ((reqstr.Length - reqstr.Replace(substr, "").Length) / substr.Length);
    }
}
}

Expected Result: The Controls should generate one by one in order on click of listview, but generating in a group. Textboxes are generating as one group and dropdowns are generating as one group.

 

Saifulla
Top achievements
Rank 1
 asked on 02 Jan 2019
3 answers
232 views

I have the following tag which includes a handler for onfocusout.  The handler is executed when the user clicks away from the control when the down arrow button or the text area has focus but doesn't execute when the user has selected an item (or item check box) in the item list and then navigates away from the RadComboBox control.  How is it possible to have checkNeedToSaveOpportunity(event) executed if the user focuses on a list item and then navigates to some other part of the page?

<telerik:RadComboBox RenderMode="Lightweight" ID="cmbReportTool" filter="Contains" runat="server"
EmptyMessage="Select" oWrap="false"
onfocusout="checkNeedToSaveOpportunity(event)"
OnClientItemChecking="OnCMBClientItemChecking"
class="cmb-report-tool"
CheckBoxes="true"
width="100%">
</telerik:RadComboBox>

Marin Bratanov
Telerik team
 answered on 01 Jan 2019
3 answers
181 views
I know the current editor looks and works like old Word 2003/2007. I have no problems with it but with WordPress, Wix, Squarespace, and other online editors this editor majorly behind the times in having layout functionality that end users are expecting. 
Marin Bratanov
Telerik team
 answered on 01 Jan 2019
5 answers
158 views

Hi guys,

No idea what's happening here. Been trying to fix for a week.

It was working great last week but now when a new task is clicked, the ajax loading image just keeps spinning. While it's spinning, if I refresh the page straight away, I can see that the record has gone into the database and it shows up in the chart.

I read on a couple of other posts about this scenario, but could not find a fix.

Cheers,

Jon

 

Vessy
Telerik team
 answered on 31 Dec 2018
1 answer
6.7K+ views

Currently while exporting report to PDF, only current page number is displayed at the bottom of each pages. Instead of this, we would like to show page number in 'n' of Total number of pages' format. 

Any suggestion for this? 

Thanks.

Todor
Telerik team
 answered on 28 Dec 2018
5 answers
479 views
Here is some code that I whpped together which shows how to create a pdf or xls document from a RadGrid and  attach it to an email.

I only had time to draft the basics, but you should get the idea and I thought that I would share since members like Princy helped me get here.
<telerik:RadGrid ID="RadGrid1"  
               AllowSorting="false"
               AutoGenerateColumns="false"
               AlternatingItemStyle-HorizontalAlign="center"
               AlternatingItemStyle-BackColor="#ffffff"               
               GroupingEnabled="true"
               OnExcelExportCellFormatting="RadGrid1_ExcelExportCellFormatting"
               OnGridExporting="RadGrid1_GridExporting"
               OnPdfExporting="RadGrid1_PdfExporting"
               ExportSettings-Excel-Format="Html"
               ExportSettings-ExportOnlyData="true"
               Width="100%"
               runat="server">  
               <MasterTableView  Width="99%">                
               <Columns>  ...

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.IO;
using System.Net;
using System.Net.Mail;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
using Mec.CommonLibrary.Cryptography;
using MEC.EMA.BLL;
using Microsoft.Security.Application;
using Telerik.Web.UI;
 
 
public class EmailRadGridAttachment
{
 
    List<Person> _userList = new List<Person>();
    UserBLL _userBLL = new UserBLL();
 
    protected void Page_Load(object sender, EventArgs e)
    {
        BindGrid();
    }
 
    protected void BindGrid()
    {
        _userList = _userListBLL.GetUserById(_userId);
        RadGrid1.DataSource = _userList;
    }
 
    // aspx page with a button that fires this event for Excel
    protected void ButtonExcel_Click(object sender, EventArgs e)
    {
        ConfigureExport();
        RadGrid Grid1 = (RadGrid)Page.Master.FindControl("Main").FindControl("RadGrid1");
        Grid1.MasterTableView.ExportToExcel();
    }
 
    // aspx page with a button that fires this even for PDF
    protected void ButtonPdf_Click(object sender, System.EventArgs e)
    {
        ConfigureExport();
        RadGrid Grid1 = (RadGrid)Page.Master.FindControl("Main").FindControl("RadGrid1");
        Grid1.ExportSettings.Pdf.AllowPrinting = true;
        Grid1.ExportSettings.Pdf.AllowModify = true;
        Grid1.ExportSettings.Pdf.AllowCopy = true;
        Grid1.ExportSettings.Pdf.AllowAdd = true;
        // I found that if I don't use postscript fonts the data does not make it to the attachment
        Grid1.ExportSettings.Pdf.DefaultFontFamily = "Helvetica";
        Grid1.ExportSettings.Pdf.PageLeftMargin = new Unit(2, UnitType.Mm);
        Grid1.ExportSettings.Pdf.PageRightMargin = new Unit(2, UnitType.Mm);
        Grid1.ExportSettings.Pdf.PageHeaderMargin = new Unit(0, UnitType.Mm);
        Grid1.ExportSettings.Pdf.PaperSize = GridPaperSize.Legal;
        // to get lanscape orientation     
        Grid1.ExportSettings.Pdf.PageHeight = Unit.Parse("210mm");
        // Width based on TOU and NON-TOU Columns and the smaller parse the more room for data
        Grid1.ExportSettings.Pdf.PageWidth = Unit.Parse("420mm");
 
        foreach (GridColumn col in RadGrid1.MasterTableView.RenderColumns)
        {
            // We have the ability to control the width of columns in the export here
            if (col.UniqueName != "MiddleInitial")
            {
                col.HeaderStyle.Width = Unit.Pixel(50);
            }
        }
        Grid1.MasterTableView.ExportToPdf();
    }
 
    protected void RadGrid1_PdfExporting(object sender, GridPdfExportingArgs e)
    {
        // I have added some more information that will be included in the PDF above the RadGrid here
        StringBuilder customHTML = new StringBuilder();
        customHTML.Append("<p style='color: red; font-weight: bold; font-size: 10pt;'>Title Page</p>");
        customHTML.Append("<table style='font-family:Helvetica;font-size:9pt;width:500px;'>");
        // Very Important to make sure you have a colgroup and the same number of "<col>" as "<td>"
        customHTML.Append("<colgroup><col style='width: 200px; white-space:nowrap;' /><col style='text-align:left;' /></colgroup>");
        // ColGroup = Number of <td> in a row is needed for Telerik export to PDF
        customHTML.Append("<tr><td>Customer: " + CustomerName.Text + "</td><td>Date: " + LabelDate.Text + " </td></tr>");
        customHTML.Append("<tr><td>Address: " + LabelAddress.Text + "</td><td>Email: " + LabelEmail.Text + " </td></tr>");
        customHTML.Append("<tr><td>City: " + LabelCity.Text + "</td><td>Phone: " + LabelPhone.Text + " </td></tr>");
        customHTML.Append("<tr><td>State: " + LabelState.Text + "</td><td>Zip: " + LabelZipCode.Text + " </td></tr>");
        customHTML.Append("</table>");      
        e.RawHTML = customHTML + e.RawHTML;
    }
       
 
   
 
    public void ConfigureExport()
    {
        RadGrid Grid1 = (RadGrid)Page.Master.FindControl("Main").FindControl("RadGrid1");
        Grid1.ExportSettings.ExportOnlyData = true;
        Grid1.ExportSettings.IgnorePaging = true;
        // We don't want the Open, Save or Cancel prompt to open for a new window when calling this page
        Grid1.ExportSettings.OpenInNewWindow = false;
    }
 
    protected void RadGrid1_GridExporting(object source, GridExportingArgs e)
    {             
        StringBuilder customHTML = new StringBuilder();
        MemoryStream gridMemoryStream = new MemoryStream(new ASCIIEncoding().GetBytes(e.ExportOutput));
        if (e.ExportType == ExportType.Excel)
        {
            SendEMailWithAttachment(gridMemoryStream, "attachment.xls");          
        }
        // Stuff the Grid in a memory stream and pass it to the email method
        if (e.ExportType == ExportType.Pdf)
        {
            SendEMailWithAttachment(gridMemoryStream, "attachment.pdf");          
        }
        gridMemoryStream.Close();
        // Redirect to the same page so the alert does not pop-up
        Response.Redirect(Request.Url.AbsoluteUri);
    }
 
    public void SendEMailWithAttachment(Stream attachmentStream, string fileName)
    {
        //settings from the web.config
        SmtpClient smtpClient = new SmtpClient(Convert.ToString(ConfigurationManager.AppSettings["SERVER_EMAIL"]));
        string authType = "Basic";
        MailMessage email = new MailMessage();
        StringBuilder body = new StringBuilder();
        string emaURL = Convert.ToString(ConfigurationManager.AppSettings["BASE_URL"]);
        email.From = new MailAddress("From@gmail.com");
        email.To.Add("To@gmail.com");
        email.Subject = "This is the subject";
        body.Append("<table style='font-family:Helvetica;font-size:9pt;width:600px;'>");
        body.Append("<tr><td>You can put in whatever you want here</td></tr>");
        body.Append("</table>");
        // Attachment goes here
        email.Attachments.Add(new Attachment(attachmentStream, fileName));
        email.Body = body.ToString();
        email.IsBodyHtml = true;
        NetworkCredential nc = new NetworkCredential(Convert.ToString(ConfigurationManager.AppSettings["CredentialU"]), Convert.ToString(ConfigurationManager.AppSettings["CredentialP"]));
        smtpClient.Credentials = nc.GetCredential(Convert.ToString(smtpClient), 25, authType);
        smtpClient.Send(email);
    }
}

Marin Bratanov
Telerik team
 answered on 28 Dec 2018
1 answer
187 views

I was trying to create a User Control for standardizing the Grid Control across all the forms. Surely all the forms will have different columns but the layout is the same across except for few properties here and there. How do I expose the Column Collection?

My Code would be:

<telerik:RadGrid ID="grid" runat="server" AllowCustomPaging="false" AllowPaging="False" AllowSorting="False" AutoGenerateColumns="False" CellPadding="0" CellSpacing="0" CssClass="gridCandidate" Height="100%" Width="100%">
        <ClientSettings EnableAlternatingItems="false" EnableRowHoverStyle="true">
            <Scrolling AllowScroll="true" UseStaticHeaders="true" />
            <Selecting AllowRowSelect="True" />
            <ClientEvents OnRowDataBound="function() {}" OnCommand="function(){}" />
        </ClientSettings>
        <MasterTableView AllowFilteringByColumn="False" AllowNaturalSort="false" ClientDataKeyNames="ID" DataKeyNames="ID" EnableColumnsViewState="False" EnableViewState="False" HierarchyLoadMode="Client"
            NoMasterRecordsText="<div class='noRec'>No records to display.</div>" TableLayout="Auto">
            <Columns></Columns>
<HeaderStyle Height="0px" />
            <PagerStyle Visible="False" />
        </MasterTableView>
    </telerik:RadGrid>

 

 

[MergableProperty(false), DefaultValue((string)null),
PersistenceMode(PersistenceMode.InnerProperty)]
public GridColumnCollection Columns
{
    get
    {
        return grid.Columns;
    }
    set
    {
        foreach (GridColumn column in value)
        {
            grid.MasterTableView.Columns.Add(column);
        }
        //grid.MasterTableView.Columns.Add()
    }
}

 

Any idea how to expose the Columns property?

Marin Bratanov
Telerik team
 answered on 27 Dec 2018
8 answers
551 views
Hi.

I have a project thats contain RadColorPicker. I need to change text color according the chosen one. inspect shows me the wrong color. Process steps;

     1)Choose color and close the RadColorPicker,

     2)Inspect still shows me the previous color that i chosen,

     3)Inspect has been updated when i clicked second time to RadColorPicker.

I don't know why is happening and need your help.

Thanks a lot.
Caner
Top achievements
Rank 1
 answered on 27 Dec 2018
12 answers
881 views
I just wanted to open document in RADEditor through C# code, instead of navigating File->Open link in RADEditor. If this is possible, I'll display the document link in my web application to open the respective document in RADEditor.So that, can edit the word document in RADEditor and save it on the server which is hosted. Let me know the case is possible.
Eyup
Telerik team
 answered on 27 Dec 2018
3 answers
124 views
No formatting is being stripped when the user is using IE11.  Works fine on other browsers.

Does anyone know the fix?

thanks!
baojian
Top achievements
Rank 1
 answered on 25 Dec 2018
Narrow your results
Selected tags
Tags
+? more
Top users last month
Tien
Top achievements
Rank 1
Iron
Krasimir
Top achievements
Rank 3
Bronze
Iron
Iron
Cedar
Top achievements
Rank 1
Iron
Emil
Top achievements
Rank 1
Iron
Kyle Watson
Top achievements
Rank 1
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Tien
Top achievements
Rank 1
Iron
Krasimir
Top achievements
Rank 3
Bronze
Iron
Iron
Cedar
Top achievements
Rank 1
Iron
Emil
Top achievements
Rank 1
Iron
Kyle Watson
Top achievements
Rank 1
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?