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

I am converting an old application that stores its images as base64strings in a SQL Server database.

I am trying to add the images to the gallery. Pointing the ImageURL to a base64 string works fine, but not the ThumbnailURL.

        public static string ImageToBase64(System.Drawing.Image image, System.Drawing.Imaging.ImageFormat format)

        {
            string returnString = "";
            System.IO.MemoryStream ms = new MemoryStream();

            image.Save(ms, format);
            byte[] imageBytes = ms.ToArray();
            returnString = "data:image;base64," + Convert.ToBase64String(imageBytes);

            return returnString;
        }

        public static Telerik.Web.UI.ImageGalleryItem ImageBase64(byte[] BlobData, string ImageTitle)
        {
            Telerik.Web.UI.ImageGalleryItem returnImage = new Telerik.Web.UI.ImageGalleryItem();

            System.Drawing.Image img = null;
            System.IO.MemoryStream mem = new MemoryStream();
            mem.Write(BlobData, 0, BlobData.Length);
            mem.Seek(0, SeekOrigin.Begin);

            img = System.Drawing.Image.FromStream(mem);

            returnImage.Title = ImageTitle;
            returnImage.ThumbnailUrl = ImageToBase64(SizedImage(img, 100, 75), System.Drawing.Imaging.ImageFormat.Jpeg);
            returnImage.ImageUrl =     ImageToBase64(SizedImage(img, 800, 600), System.Drawing.Imaging.ImageFormat.Jpeg);
            return returnImage;
        }

        returnImage.ImageUrl works perfectly fine.

 


        public static System.Drawing.Bitmap SizedImage(System.Drawing.Image img, int dispWidth, int dispHeight)
        {
            double scale = 1.0, hScale = 1.0;
            double imgWidth = img.Width;
            double imgHeight = img.Height;

            if (imgWidth > dispWidth)
                scale = dispWidth / imgWidth;
            if (imgHeight > dispHeight)
                hScale = dispHeight / imgHeight;
            if (hScale < scale)
                scale = hScale;

            int imgw = Convert.ToInt32(imgWidth * scale);
            int imgh = Convert.ToInt32(imgHeight * scale);

            return new System.Drawing.Bitmap(img, imgw, imgh);
        }

Richard
Top achievements
Rank 1
 answered on 23 Sep 2019
3 answers
1.1K+ views
I create the grid below:
<telerik:RadGrid runat="server" ID="grdImportData" RenderMode="Lightweight" AllowPaging="true" PageSize="10" OnNeedDataSource="grdImportData_NeedDataSource" OnPageIndexChanged="grdImportData_PageIndexChanged" OnUpdateCommand="grdImportData_UpdateCommand" OnDeleteCommand="grdImportData_DeleteCommand" OnItemCommand="grdImportData_ItemCommand"  OnItemDataBound="grdImportData_ItemDataBound" AllowSorting="False" AlternatingItemStyle-BackColor="#f5f5f5" ItemStyle-BackColor="#ffffff" ColumnWidth="Auto" HorizontalAlignment="Stretch" Width="100%">
        <ClientSettings>
            <Scrolling AllowScroll="True" UseStaticHeaders="True" SaveScrollPosition="true" FrozenColumnsCount="1" EnableVirtualScrollPaging="true"></Scrolling>
                <Resizing AllowColumnResize="true" ResizeGridOnColumnResize="true" EnableRealTimeResize="true" />
        </ClientSettings>
    <MasterTableView EditMode="InPlace" DataKeyNames="Id">
        <Columns>
            <telerik:GridEditCommandColumn  HeaderStyle-Width="75px" HeaderStyle-HorizontalAlign="Right" ItemStyle-HorizontalAlign="Right"/>
            <telerik:GridTemplateColumn HeaderStyle-Width="50px">
                <ItemTemplate>
                    <asp:LinkButton runat="server" CommandName="Delete"><i class="icon s7-junk grid-edit-icon"></i></asp:LinkButton>
                </ItemTemplate>
            </telerik:GridTemplateColumn>
        </Columns>
    </MasterTableView>
</telerik:RadGrid>

 

I then try to add a TemplateColumn, EditTemplateColumn and RadDropdownlist programmatically like below:

protected void grdImportData_ItemDataBound(object sender, GridItemEventArgs e)
{
    if(ImportType == "CLEARGISTIX_ASSETS")
    {
        if (e.Item is GridDataItem)
        {
            string templateColumnName = "AssetTypeName";
            GridTemplateColumn templateColumn = new GridTemplateColumn();
            templateColumn.ItemTemplate = new MyTemplate(templateColumnName);
            templateColumn.EditItemTemplate = new MyEditTemplate();
            templateColumn.HeaderText = templateColumnName;
            templateColumn.DataField = "AssetTypeName";
 
            if (e.Item.IsInEditMode)
            {
                RadDropDownList rddl = new RadDropDownList();
                PortalView.LookupListBO list = LookupListBA.LookupList_GetByKey(DB_Context, "SITE_ASSETTYPE_LIST", UtilityBA.IsActiveChoice.Active);
                List<PortalView.LookupListItemBO> oList = LookupListBA.LookupListItem_GetList_ByLookupListId(DB_Context, list.LookupListId, (Guid)Current.Employee.SiteId);
                rddl.ID = "dropdownlist1";
                rddl.DataSource = oList;
                rddl.DataTextField = "Name";
                rddl.DataValueField = "LookupListItemId";
            }
            grdImportData.MasterTableView.Columns.Add(templateColumn);
        }
    }
}
public class MyTemplate : ITemplate
{
    private string colname;
    protected Label lControl;
    public MyTemplate(string cName)
    {
        colname = cName;
    }
    public void InstantiateIn(System.Web.UI.Control container)
    {
        lControl = new Label();
        lControl.ID = "lControl";
        lControl.DataBinding += new EventHandler(lControl_DataBinding);
        container.Controls.Add(lControl);
    }
 
    public void lControl_DataBinding(object sender, EventArgs e)
    {
        Label l = (Label)sender;
        GridDataItem container = (GridDataItem)l.NamingContainer;
        l.Text = ((DataRowView)container.DataItem)[colname].ToString() + "<br />";
    }
}
 
public class MyEditTemplate : IBindableTemplate
{
    public void InstantiateIn(Control container)
    {
        GridEditFormItem item = ((GridEditFormItem)(container.NamingContainer));
        RadDropDownList drop = new RadDropDownList();
        drop.ID = "dropdownlist1";
 
        container.Controls.Add(drop);
    }
    public System.Collections.Specialized.IOrderedDictionary ExtractValues(System.Web.UI.Control container)
    {
        OrderedDictionary od = new OrderedDictionary();
        od.Add("LookupListItemId", ((RadDropDownList)(((GridEditFormItem)(container)).FindControl("dropdownlist1"))).DataValueField);
        return od;
    }
}

 

When I click on the edit button, I error: 'Unable to cast object of type 'Telerik.Web.UI.GridDataItem' to type 'Telerik.Web.UI.GridEditFormItem'.' on this line:

od.Add("LookupListItemId", ((RadDropDownList)(((GridEditFormItem)(container)).FindControl("dropdownlist1"))).DataValueField);

I notice that it never his the InstaniateIn code at all.

Any assistance is greatly appreciated.

Attila Antal
Telerik team
 answered on 23 Sep 2019
4 answers
464 views
Dears,
I have two comboboxes in page with RadAjaxManager, in the page Load event I hide one of them. I add the following:

<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
       <AjaxSettings>
           <telerik:AjaxSetting AjaxControlID="RadAjaxManager1">
               <UpdatedControls>
                   <telerik:AjaxUpdatedControl ControlID="cmbHR_DOCS_ID_START" UpdatePanelRenderMode="Inline" />
                   <telerik:AjaxUpdatedControl ControlID="cmbHR_DOCS_ID" UpdatePanelRenderMode="Inline" />
               </UpdatedControls>
           </telerik:AjaxSetting>
       </AjaxSettings>
   </telerik:RadAjaxManager>

When user add a new value two one of the comboes (in a RadWindow) I refresh the data in them by calling:
$find("<%= RadAjaxManager1.ClientID %>").ajaxRequest(x);

Because one of the combos is invisible I got an ajax error (I think you know).
I know that I can't add two RadAjaxManager in one page so I tried to add AjaxUpdatedControl to the RadAjaxManager at runtime in the Page Load event but it didn't work.

Could you please help in?
Best Regards
Eyup
Telerik team
 answered on 23 Sep 2019
12 answers
1.9K+ views
I want to add Rad Grid Dynamically using Code Behind.with Dynamic Columns 1 Columns should be Drop Down , 1 Column Should be Date picker, 1 Column Should be Text field.these Dynamic Columns should be Shown in Edit mode when Edit button is Clicked.while Showing Data just Data should be shown like data in label.
how can it be possible.
Attila Antal
Telerik team
 answered on 23 Sep 2019
6 answers
1.0K+ views
Hi All,

My question for client side code only using JavaScript.
I have a RadDropDownTree in my Form. In that DropDown I have some some data.
Suppose.
Central
    Middle Central
            Chicago
    Texoma
..
.
.
above mention is same data.

Now What I want is when User Select Chicago then Select text in client area of that dropdown should be anything like 'ABCD' or anything. I just want to set the
Selected text of that DropDownTree. I tried below mention code but is not working, In my RadDropDownTree, it still showing emptymessage.

var combo = $find("<%= RadDropDownLocations.ClientID %>");
combo._selectedText = "Davolio" + ";" + "Leverling";

Can someone guide me how can I set the text in DropDownTree
 Let me know in case of any more information

Vijay
David
Top achievements
Rank 1
Iron
Iron
Veteran
 answered on 20 Sep 2019
2 answers
188 views

In my project, on one of the page, the HTML rendered by RadGrid contains three HTML tables (one for header, one for data, and one for footer).

But on another page, the HTML rendered contains only one HTML table.

I can't figure out what settings are affecting the different rendering layout. Please advise.

Thanks!

Sheng
Top achievements
Rank 1
Iron
Iron
 answered on 20 Sep 2019
1 answer
122 views

We are using Telerik grid filters to display configuration dashboard for release management status. I have few Columns i.e Application, environment, location. I want to retain columns parameters after I refresh the browser.

 

Is there way I can retain the parameters which are coming from the database?

-

Attila Antal
Telerik team
 answered on 20 Sep 2019
1 answer
458 views

Hi Team,

 

I have a got paging enabled on a Radgrid, and this grid is in a web user control, this grid usercontrol is also in another user control.

when I drop the user control on an ASPX page, it works fine. but when I put grid usercontrol in another usercontrol, initial it was doing a postback and refreshing the whole page, but I bypassed that by add a RadAjaxManagerProxy which handled the AjaxUpdatedControl.

But my issue now, is that once I click on a paging page, it shows the paging page, but it it stops clicking and can't navigate to the rest of the paging page.

Any help would be appreciated 

Thanks in Advance.

Attila Antal
Telerik team
 answered on 20 Sep 2019
1 answer
436 views

Hi from France !

In my project i've got problem with this situation :

I've got a radgrid, x columns.

My first column is used for generate my rowSpan.
<telerik:GridBoundColumn UniqueName="idMaille" DataField="idMaille" Display="false"></telerik:GridBoundColumn>    

while idMaille is the same, Merge my gridTemplate column : "M0" 

i've set Freezecolumn to 2

HTML generate is like this :

Row 1 :
<tr>
 <td>FirstColumn(idMaille) not displayed</td>
 <td rowspan="2">My Text rowspanned </td>
 <td> next column </td>
</tr>

Row 2 :
<tr>
 <td>FirstColumn(idMaille) not displayed</td>
 <td> next column </td>
</tr>

But because rowspan is set in my 2nd row, my 2nd column is in reality the third !
and when i move scrollbar, javascript set "display:none"

i think this problem can it resolved if we can specify fixed columns (id/property) and generate a css class for reference for javascript.
i'm remember in old project with infragistics, we specify columns who want freeze.

 

<ClientSettings><Scrolling AllowScroll="true" FrozenColumnsCount="2" UseStaticHeaders="true" /></ClientSettings>
<MasterTableView HeaderStyle-HorizontalAlign="Center" ShowHeadersWhenNoRecords="False" >
  <Columns>        
<telerik:GridBoundColumn UniqueName="idMaille" DataField="idMaille" Display="false"></telerik:GridBoundColumn>               
                <telerik:GridTemplateColumn UniqueName="M0">
                    <ItemTemplate>
                        <div class="rw0">
                                test                              
                        </div>
                    </ItemTemplate>   
                </telerik:GridTemplateColumn>
  <telerik:GridTemplateColumn UniqueName="M1">
                    <ItemTemplate>
                        <div class="rw1">
                                test 1
                        </div>
                    </ItemTemplate>   
                </telerik:GridTemplateColumn>
  </Columns>        
</MasterTableView>

 

Attila Antal
Telerik team
 answered on 20 Sep 2019
1 answer
177 views

Hi,

Does anyone experience an issue with the menu not triggering the itemclick event.

I have recently had a forced windows 10 major update on my local development PC, but when I started to work on debugging a code, it looks like the item click event is no longer triggering.

I have the below code

AddHandler MainMenu.ItemClick, AddressOf MenuItemSelected

Then have the following eventhandler

Private Sub MenuItemSelected(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadMenuEventArgs)

But on putting a breakpoint, the eventhandler function never get triggered when I clicked on the menu, 

Please let me know if I am missing something because this seems to be quite a simple code.

 

Thank you

Peter Milchev
Telerik team
 answered on 19 Sep 2019
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?