Telerik Forums
UI for ASP.NET AJAX Forum
9 answers
2.7K+ views

I am using RadBinaryImage control with SqlDataSource. If the VarBinary field contains a NULL value I am getting this error:  “Unable to cast object of type 'System.DBNull' to type 'System.Byte[]' “.

My understanding is that a NULL field should be cast to  a null or empty byte[].

Can someone please show me how check if the supplied value is of type DBNull and how to change it to appropriate empty byte array or null in C#?


Thanks,
Thomas
syeada sanjida
Top achievements
Rank 1
 answered on 29 Jan 2015
4 answers
151 views
Hi, I'm having two issues and I suspect at least one of them is dead-simple and caused by me making a simple mistake with me AutoCompleteBox in the EditItemTemplate of a GridTemplateColumn.

First problem; When I enter edit mode for a grid row, the AutoCompleteBox is empty rather than displaying the value that showed in that column before it entered edit mode. (I can "<%#DataBinder.Eval(Container.DataItem, "PartNumber")%>" in the EditItemTemplate to get the text to show up under/over the but that's not a solution.

Second problem; The AutoCompleteBox (set to single selection mode and text input) was appending a semicolon to the selected value. So I tried setting Delimiter="" which got rid of the unwanted character, but then it messed up the auto-complete functionality. Once that change was made, the drop-down options would appear if I paste a string into the box all at once, but not ever if I just typed the same string in. So, either: what's the right way to eliminate the semicolon, or how do I make the autocomplete function work right with delimiter set to an empty string? (I could theoretically trim the semicolon when I'm setting the value of the parameter before updating the DB, but that's a terrible solution since I might theoretically want semicolons in the PartNumber at some future date.)

                        <telerik:GridTemplateColumn UniqueName="PartNumber" HeaderText="Part Number" ItemStyle-CssClass="editWidth" 
                                FilterControlAltText="Filter PartNumber column" FilterControlWidth="85%">
                            <ItemTemplate><%#DataBinder.Eval(Container.DataItem, "PartNumber")%></ItemTemplate>
                            <EditItemTemplate>
                                <telerik:RadAutoCompleteBox runat="server" ID="racbPN" DataSourceID="ItemIdSource" DataTextField="IMA_ItemID" 
                                    HighlightFirstMatch="true" InputType="Text" TextSettings-SelectionMode="Single" MaxResultCount="200" MinFilterLength="4" 
                                     Delimiter="" DropDownHeight="300px" DropDownWidth="200px">
                                </telerik:RadAutoCompleteBox>
                            </EditItemTemplate>
                            <HeaderStyle Width="190px"></HeaderStyle>
                        </telerik:GridTemplateColumn>

Thanks for your time!
Nencho
Telerik team
 answered on 29 Jan 2015
5 answers
63 views
I am using the telerik ajax controls with an asp.net 4.0 website.  The default page is using the radajaxmanager control.  The page also has two radcombobox controls.  Server side OnItemsRequested events are used to populate the rad combo box controls.  A rad multipage control is also on the page.  Each page in the rad multi page displays rad grids based on the selections for the two rad combo box controls.  Session state is used to store the selections from the two radcombobox controls.  Object datasources use these session variables to populate the grids.

The problem is that a user can leave the website without closing the browser and then return to the website using a back button or favorite item.  The combo boxes to not show the previous selections.  However, the grids use the session variables to display the data.  I have been unable to set the radcombobox values.  It appears that th page load event does not fire.

I cannot remove the rad ajax manager because a tab strip control is also used.  The page needs javascript methods to control the tabs.

Do you have any suggestions?
Nencho
Telerik team
 answered on 29 Jan 2015
1 answer
208 views
I would like to create the diagram that
  • User can drag & drop the item (Image) into the diagram.
  • User can create the connection to link each item.
  • User can save the diagram into JSON.
  • User can load the diagram from JSON

Now, I can archive the first, second and third requirements. However, I have the problem when I try to load data from JSON. The Images are missing, and the connections also lost. I try to solve the problem by using 'visualTemplate' by setting '<ShapeDefaultsSettings Visual="visualTemplate" />', but it breaks my diagram instead. I have attached my code below.

This is my drag & drop event
function setDropTargetOnDiagram(element) {
     $telerik.$(element).kendoDropTarget({
          drop: function (e) {
               var draggable = e.draggable,
                    element = e.dropTarget,
                    diagram = element.getKendoDiagram();
 
               if (draggable && draggable.hint) {
                    var item = draggable.hint.data("data"),
                         offset = draggable.hintOffset,
                         point = new kendo.dataviz.diagram.Point(offset.left, offset.top),
                         transformed = diagram.documentToModel(point);
 
               item.id += "_" + generateUUID();
               item.x = transformed.x;
               item.y = transformed.y;
 
               var shape = createCustomShape(item);                               
             diagram.addShape(shape);
               }
          }
     });
}
 
function createCustomShape(item) {
     var shape = new kendo.dataviz.diagram.Shape(item);
     var image = new kendo.dataviz.diagram.Image({
          source: "../Images/Diagram/" + item.content.ImageName,
          x: 0,
          y: 0,
          width: item.width,
          height: item.height,
          stroke: {
               width: 0
          }
     });
     var textBlock = new kendo.dataviz.diagram.TextBlock({
          text: item.content.CustomText,
               color: "#000",
               fontSize: 12,
               x: item.content.TextX,
               y: item.content.TextY
     });
 
     shape.visual.append(image);
     shape.visual.append(textBlock);
 
     return shape;
}

This is my dragItem
<div class="dragItem" data-data='{"id": "StartProcess", "content": {"CustomText":"Start", "TextX":"18", "TextY":"70", "ImageName":"64Play.png"}, "width":"64", "height":"64"}'>
     <asp:Image ID="imgPersonal" runat="server" ImageUrl="~/Images/Diagram/64Play.png" />
</div>

This is the code for Save and Load JSON
function saveJSON() {
     var json = diagram.save();
     var jsonStr = Sys.Serialization.JavaScriptSerializer.serialize(json);
      
     var txtDiagramSave= document.getElementById("txtDiagramSave");
     txtDiagramSave.value = js_beautify(jsonStr);
}
 
function loadJSON() {
     var txtDiagramSave= document.getElementById("txtDiagramSave");
     diagram.load(Sys.Serialization.JavaScriptSerializer.deserialize(txtDiagramSave.value));
}

This is my saved JSON
{
    "shapes": [{
        "id": "StartProcess_1242084a-6aa2-4320-8b89-accf2cd22f25",
        "hover": {},
        "cursor": "pointer",
        "content": {
            "align": "center middle",
            "text": "",
            "CustomText": "Start",
            "TextX": "18",
            "TextY": "70",
            "ImageName": "64Play.png"
        },
        "selectable": true,
        "serializable": true,
        "enable": true,
        "type": "rectangle",
        "path": "",
        "autoSize": true,
        "visual": null,
        "x": 134,
        "y": 104,
        "minWidth": 20,
        "minHeight": 20,
        "width": 65,
        "height": 65,
        "editable": {
            "connect": true
        },
        "connectors": [{
            "name": "Top",
            "description": "Top Connector"
        }, {
            "name": "Right",
            "description": "Right Connector"
        }, {
            "name": "Bottom",
            "description": "Bottom Connector"
        }, {
            "name": "Left",
            "Description": "Left Connector"
        }, {
            "name": "Auto",
            "Description": "Auto Connector"
        }],
        "rotation": {
            "angle": 0
        },
        "undoable": false
    }, {
        "id": "Personal_3993f4ff-956e-4d46-a939-18c84fcb4162",
        "hover": {},
        "cursor": "pointer",
        "content": {
            "align": "center middle",
            "text": "",
            "CustomText": "Personal",
            "TextX": "8",
            "TextY": "70",
            "ImageName": "64ManPencil.png"
        },
        "selectable": true,
        "serializable": true,
        "enable": true,
        "type": "rectangle",
        "path": "",
        "autoSize": true,
        "visual": null,
        "x": 295,
        "y": 99,
        "minWidth": 20,
        "minHeight": 20,
        "width": 65,
        "height": 65,
        "editable": {
            "connect": true
        },
        "connectors": [{
            "name": "Top",
            "description": "Top Connector"
        }, {
            "name": "Right",
            "description": "Right Connector"
        }, {
            "name": "Bottom",
            "description": "Bottom Connector"
        }, {
            "name": "Left",
            "Description": "Left Connector"
        }, {
            "name": "Auto",
            "Description": "Auto Connector"
        }],
        "rotation": {
            "angle": 0
        },
        "undoable": false
    }],
    "connections": [{
        "from": {
            "id": "StartProcess_1242084a-6aa2-4320-8b89-accf2cd22f25"
        },
        "to": {
            "id": "Personal_3993f4ff-956e-4d46-a939-18c84fcb4162"
        },
        "id": "h4upyHsjPm",
        "hover": {
            "stroke": {}
        },
        "cursor": "pointer",
        "content": {
            "align": "center middle",
            "text": "",
            "color": "#444444"
        },
        "selectable": true,
        "serializable": true,
        "enable": true,
        "startCap": "none",
        "endCap": "ArrowEnd",
        "points": [],
        "stroke": {
            "width": 2,
            "color": "#6c6c6c"
        },
        "selection": {
            "handles": {
                "width": 8,
                "height": 8,
                "fill": {
                    "color": "white"
                },
                "stroke": {
                    "color": "#444444"
                }
            }
        }
    }]
}

However, after I loaded the saved JSON, it was changed to be like this. (I lost the showing images, and connection is blank)
{
    "shapes": [{
        "id": "StartProcess_1242084a-6aa2-4320-8b89-accf2cd22f25",
        "hover": {
            "opacity": 0.2
        },
        "cursor": "pointer",
        "content": {
            "align": "center middle",
            "text": "",
            "color": "#444444",
            "CustomText": "Start",
            "TextX": "18",
            "TextY": "70",
            "ImageName": "64Play.png"
        },
        "selectable": true,
        "serializable": true,
        "enable": true,
        "type": "rectangle",
        "path": "",
        "autoSize": true,
        "visual": null,
        "x": 134,
        "y": 104,
        "minWidth": 20,
        "minHeight": 20,
        "width": 65,
        "height": 65,
        "editable": {
            "connect": true
        },
        "connectors": [{
            "name": "Top",
            "description": "Top Connector"
        }, {
            "name": "Right",
            "description": "Right Connector"
        }, {
            "name": "Bottom",
            "description": "Bottom Connector"
        }, {
            "name": "Left",
            "Description": "Left Connector"
        }, {
            "name": "Auto",
            "Description": "Auto Connector"
        }],
        "rotation": {
            "angle": 0
        },
        "stroke": {
            "width": 0
        },
        "fill": {
            "color": "#4cc5da"
        },
        "connectorDefaults": {
            "fill": {
                "color": "#444444"
            },
            "stroke": {
                "color": "white"
            },
            "hover": {
                "fill": {
                    "color": "white"
                },
                "stroke": {
                    "color": "#444444"
                }
            }
        },
        "undoable": false
    }, {
        "id": "Personal_3993f4ff-956e-4d46-a939-18c84fcb4162",
        "hover": {
            "opacity": 0.2
        },
        "cursor": "pointer",
        "content": {
            "align": "center middle",
            "text": "",
            "color": "#444444",
            "CustomText": "Personal",
            "TextX": "8",
            "TextY": "70",
            "ImageName": "64ManPencil.png"
        },
        "selectable": true,
        "serializable": true,
        "enable": true,
        "type": "rectangle",
        "path": "",
        "autoSize": true,
        "visual": null,
        "x": 295,
        "y": 99,
        "minWidth": 20,
        "minHeight": 20,
        "width": 65,
        "height": 65,
        "editable": {
            "connect": true
        },
        "connectors": [{
            "name": "Top",
            "description": "Top Connector"
        }, {
            "name": "Right",
            "description": "Right Connector"
        }, {
            "name": "Bottom",
            "description": "Bottom Connector"
        }, {
            "name": "Left",
            "Description": "Left Connector"
        }, {
            "name": "Auto",
            "Description": "Auto Connector"
        }],
        "rotation": {
            "angle": 0
        },
        "stroke": {
            "width": 0
        },
        "fill": {
            "color": "#4cc5da"
        },
        "connectorDefaults": {
            "fill": {
                "color": "#444444"
            },
            "stroke": {
                "color": "white"
            },
            "hover": {
                "fill": {
                    "color": "white"
                },
                "stroke": {
                    "color": "#444444"
                }
            }
        },
        "undoable": false
    }],
    "connections": []
}

I try to solve the load JSON problem by using "visualTemplate" like this, but it breaks the diagram
function visualTemplate(options) {
     var diagram = kendo.dataviz.diagram;
     var g = new diagram.Group();
     var dataItem = options.dataItem;
 
     g.append(createCustomShape(dataItem));
     return g;
};


Slav
Telerik team
 answered on 29 Jan 2015
3 answers
120 views
Hello,

I'm using a Masterpage with .NET 4.0 and a RadSkinManager. Without obviously changing anything in the masterpage, I'm getting a NRE in one of my 3 content pages. The question is why is this only happening in one page and how to get RadSkinManager applied continously to all content pages?
My masterpage head is the following:
<head id="Head1" runat="server">
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title></title>
  <telerik:RadSkinManager ID="rsm" runat="server" Skin="WebBlue"></telerik:RadSkinManager>
  <link href="~/Styles/Site.css" rel="stylesheet" type="text/css" />
  <asp:ContentPlaceHolder ID="HeadContent" runat="server"></asp:ContentPlaceHolder>
</head>

The error:
[NullReferenceException: Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.]
   Telerik.Web.UI.RadSkinManager.Page_PreRender(Object sender, EventArgs e) +67
   System.EventHandler.Invoke(Object sender, EventArgs e) +0
   System.Web.UI.Control.OnPreRender(EventArgs e) +92
   System.Web.UI.Control.PreRenderRecursiveInternal() +83
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +974
Peter Filipov
Telerik team
 answered on 29 Jan 2015
1 answer
119 views
Hi all,

I am dynamically generating a RadGrid from code behind, which was perfectly working of retrieving the RadGrid Item data for hidden columns.

But, now I need to upgrade telerik version from "2011.1.413.35" to "2014.3.1209.35".

After doing this upgrade, the above method of retrieving the RadGrid Item data for hidden columns is not working, in other ways I am getting &nbsp; in place of the value.

Here is my sample code to create grid:
I am putting xmldatasource to fill the RadGrid.

radGrid.MasterTableView.Columns.Add(_CreateColumn("ID", "", Unit.Percentage(0), false));

private GridBoundColumn _CreateColumn(string dataField, string text, Unit width, Boolean readOnly)
    {
        GridBoundColumn boundColumn = new GridBoundColumn();

        boundColumn.DataField           = dataField;
        boundColumn.HeaderText          = text;
        boundColumn.SortExpression      = boundColumn.DataField;
        boundColumn.HeaderStyle.Width   = width;
        boundColumn.ReadOnly            = readOnly;
        boundColumn.Visible             = (width.Value == 0 ? false : true);

        return boundColumn;
    }.

Sample code to retrieve item value:
RadGrid radGrid = (RadGrid)control;
foreach (GridDataItem grdItem in radGrid.Items)
{
     string ID = grdItem["ID"].Text;
}

But the ID = &nbsp;   which should be some value which I filled though xmldatasource.

Please provide some bunch of code or any kind of help will be appreciated.

Maria Ilieva
Telerik team
 answered on 29 Jan 2015
2 answers
91 views
Hi,

I am using a RadTreeList control and I want to set the selected property (checkbox) of a row, depending on a value from the datasource.
This is my code:

<telerik:RadTreeList ID="lstAanbod" runat="server" CssClass="_radgrid" OnNeedDataSource="lstAanbod_NeedDataSource" DataKeyNames="NR" ParentDataKeyNames="PARENT_NR" ClientDataKeyNames="DOSSIER_ID, PROFIEL_ID, GESELECTEERD"  EnableEmbeddedSkins="false" BorderStyle="None" GridLines="None" ShowFooter="true" AutoGenerateColumns="false" AllowMultiItemSelection="true">
    <ItemStyle HorizontalAlign="Left"></ItemStyle>
    <Columns>
        <telerik:TreeListSelectColumn HeaderStyle-Width="38px" UniqueName="SelectColumn"></telerik:TreeListSelectColumn>                   
        <telerik:TreeListBoundColumn HeaderStyle-Width="10%" DataField="CODE" HeaderText="Code"></telerik:TreeListBoundColumn>
        <telerik:TreeListBoundColumn HeaderStyle-Width="60%" DataField="TITEL" HeaderText="Titel"></telerik:TreeListBoundColumn>
        <telerik:TreeListBoundColumn HeaderStyle-Width="10%" DataField="NIVEAU" HeaderText="Niveau"></telerik:TreeListBoundColumn>
        <telerik:TreeListBoundColumn HeaderStyle-Width="10%" DataField="DOSSIER_ID" HeaderText="Niveau" Visible="false"></telerik:TreeListBoundColumn>
        <telerik:TreeListBoundColumn HeaderStyle-Width="10%" DataField="PROFIEL_ID" HeaderText="Niveau" Visible="false"></telerik:TreeListBoundColumn>     
    </Columns>         
    <ClientSettings Selecting-AllowItemSelection="true" Selecting-UseSelectColumnOnly="true" Selecting-AllowToggleSelection="true" ClientEvents-OnItemSelected="OnClientNodeSelected" ClientEvents-OnTreeListCreated="treeListCreated"></ClientSettings>     
</telerik:RadTreeList>


function UpdateAllChildren(currNode, nodes, nodecount, checked) {           
    var i;
    for (i = 0; i < nodecount; i++) {
        if (checked) {
            nodes[i].set_selected(true);
        }
        else {
            nodes[i].set_selected(false);
        }
    }
}
 
function treeListCreated(sender, args) {
    var items = sender.get_dataItems();
     
    for (var i = 0; i < items.length; i++) {
        var item = items[i];               
        if (item.get_dataKeyValue("GESELECTEERD") == "True") {                   
            item.set_selected(true);
        }
    }
}

However, when I run my page, I get an error on the line 'item_set_selected(true)' :

Unhandled exception at line 808, column 27 in http://localhost:11488/ScriptResource.axd? ...
0x800a138f - Runtime-fout JavaScript: Unable to get property '_selectedIndexes' of undefined or null referenced

What am I doing wrong?
Kostadin
Telerik team
 answered on 29 Jan 2015
1 answer
141 views
Hey !

I want to create a filter Template in Code Behind, but it's hard for me, can you help me ?

I would like to be able to filter the names of technicians with a combobox !

This is my code :

protected void Page_Load(object sender, EventArgs e)
{
    GetGestionDoc();
}

{
    if (Session["NumStation"] != null)
    {
        int numStation = Convert.ToInt32(Session["NumStation"]);
        document = entities.V_RAPPORTSVALIDES.Where(p => p.ID_STATION == numStation).ToList();
 
        List<DocumentObject> newList = new List<DocumentObject>();
 
        foreach (var item in document)
        {
            DocumentObject o = new DocumentObject(item.TYPE_VISITE, item.TYPE_DOCUMENT, Convert.ToDateTime(item.DATE_DOCUMENT), Convert.ToInt16(item.ANNEE_RAPPORTANNUEL), item.NOM_TECHNICIEN);
            newList.Add(o);
        }
 
        RadCommentGrid.DataSource = newList;
        RadCommentGrid.DataBind();
 
        ChangeHeaderName();
    }
}

private void ChangeHeaderName()
{
    foreach (GridColumn column in RadCommentGrid.MasterTableView.AutoGeneratedColumns)
    {
        switch (column.OrderIndex)
        {
            case 2:
                column.HeaderText = "Date du document";
                break;
            case 3:
                column.HeaderText = "Type de document";
                break;
            case 4:
                column.HeaderText = "Nom du technicien";
                break;
            case 5:
                column.HeaderText = "Type de visite";
                break;
            case 6:
                column.HeaderText = "Année du rapport annuel";
                break;
        }
    }
 
    GridColumn columnDateDoc = RadCommentGrid.MasterTableView.AutoGeneratedColumns.Where(p => p.UniqueName == "DATE_DOCUMENT").FirstOrDefault();
    columnDateDoc.OrderIndex = 1;
 
    GridColumn columnTypeDoc = RadCommentGrid.MasterTableView.AutoGeneratedColumns.Where(p => p.UniqueName == "TYPE_DOCUMENT").FirstOrDefault();
    columnTypeDoc.OrderIndex = 2;
 
    GridColumn columnTechnicien = RadCommentGrid.MasterTableView.AutoGeneratedColumns.Where(p => p.UniqueName == "NOM_TECHNICIEN").FirstOrDefault();
    columnTechnicien.OrderIndex = 3;
 
    GridColumn columnVisite = RadCommentGrid.MasterTableView.AutoGeneratedColumns.Where(p => p.UniqueName == "TYPE_VISITE").FirstOrDefault();
    columnVisite.OrderIndex = 4;
 
    GridColumn columnAnnee = RadCommentGrid.MasterTableView.AutoGeneratedColumns.Where(p => p.UniqueName == "ANNEE_RAPPORTANNEE").FirstOrDefault();
    columnAnnee.OrderIndex = 5;
}


I see in your demo, you can create a filter with a radcombobox but its in XML :

<telerik:RadComboBox
     
    ID="RadComboBoxTitle"
     
    DataSourceID="SqlDataSource2"
     
    DataTextField="ContactTitle"
     
    DataValueField="ContactTitle"
     
    Height="200px"
     
    AppendDataBoundItems="true"
     
    SelectedValue='<%# ((GridItem)Container).OwnerTableView.GetColumn("ContactTitle").CurrentFilterValue %>'
     
    runat="server"
     
    OnClientSelectedIndexChanged="TitleIndexChanged">
     
    <Items>
        <telerik:RadComboBoxItem Text="All" />
    </Items>
     
</telerik:RadComboBox>

Eyup
Telerik team
 answered on 29 Jan 2015
1 answer
455 views
I have a gridview with column name "Domain"

BY default it shows a single filter att one time but i want multiple filter in one time in single column

My RadGrid Structure is this

DOMAIN
@yahoo.com
@gmail.com
@india.com


I want to filter domain other than @yahoo.com and @gmail.com

How to do that in RadGrid Filter ??
 
 
Eyup
Telerik team
 answered on 29 Jan 2015
1 answer
60 views
Hi,

is it possible or a planned feature to mark certain days as holidays inside the calender for planning the different tasks?
Thank you.

Regards,
Felix
Bozhidar
Telerik team
 answered on 29 Jan 2015
Narrow your results
Selected tags
Tags
+? more
Top users last month
Jay
Top achievements
Rank 3
Bronze
Iron
Iron
yw
Top achievements
Rank 2
Iron
Iron
Stefan
Top achievements
Rank 2
Iron
Iron
Iron
Kao Hung
Top achievements
Rank 1
Iron
Bohdan
Top achievements
Rank 2
Iron
Iron
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Jay
Top achievements
Rank 3
Bronze
Iron
Iron
yw
Top achievements
Rank 2
Iron
Iron
Stefan
Top achievements
Rank 2
Iron
Iron
Iron
Kao Hung
Top achievements
Rank 1
Iron
Bohdan
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?