Telerik Forums
UI for ASP.NET AJAX Forum
1 answer
64 views

So, first off, I am very new to programming and just started a position, but I have been working on an item for a bit now and am struggling to get it to work correctly.  I get stuck on a spceific line of code and I am not sure how to handle it as they are not text boxes. The errors I get are as follows: 

System.InvalidCastException: 'Unable to cast object of type 'Telerik.Web.UI.GridTextBoxColumnEditor' to type 'System.IConvertible'.' 

For this line: 

cmd.Parameters.Add("@Fill_Qty", SqlDbType.Int).Value = System.Convert.ToInt32(fillQtyEditor)

I also believe this will effect the maint_date and active_indicator cmds as well and would like any feedback. Additionally, the cmd that I am using for sql the values are null so seems to be bypassing that as well. I have scoured this site and documentation which has helped somewhat but nothing specific to this. 

 

Protected Sub RadGrid1_ItemCreated(sender As Object, e As Telerik.Web.UI.GridItemEventArgs) If e.Item.IsInEditMode Then Dim item As Telerik.Web.UI.GridEditableItem = TryCast(e.Item, Telerik.Web.UI.GridEditableItem) ' Add validator for PortalID (Non-nullable) Dim portalIDEditor As Telerik.Web.UI.GridTextBoxColumnEditor = CType(item.EditManager.GetColumnEditor("PortalID"), Telerik.Web.UI.GridTextBoxColumnEditor) AddRequiredFieldValidator(portalIDEditor.TextBoxControl, "PortalID") ' Add validator for asset_sn (Non-nullable) Dim assetSNEditor As Telerik.Web.UI.GridTextBoxColumnEditor = CType(item.EditManager.GetColumnEditor("asset_SN"), Telerik.Web.UI.GridTextBoxColumnEditor) AddRequiredFieldValidator(assetSNEditor.TextBoxControl, "Asset Serial Number") ' Add validator for asset_model (Nullable) Dim assetModelEditor As Telerik.Web.UI.GridTextBoxColumnEditor = CType(item.EditManager.GetColumnEditor("asset_model"), Telerik.Web.UI.GridTextBoxColumnEditor) AddRequiredFieldValidator(assetModelEditor.TextBoxControl, "Asset Model") ' Add validator for asset_location (Nullable) Dim assetLocEditor As Telerik.Web.UI.GridTextBoxColumnEditor = CType(item.EditManager.GetColumnEditor("asset_location"), Telerik.Web.UI.GridTextBoxColumnEditor) AddRequiredFieldValidator(assetLocEditor.TextBoxControl, "Location") ' Add validator for Fill_qty (Nullable but must be numeric if provided) Dim fillQtyEditor As Telerik.Web.UI.GridTextBoxColumnEditor = CType(item.EditManager.GetColumnEditor("Fill_qty"), Telerik.Web.UI.GridTextBoxColumnEditor) AddNumericValidator(fillQtyEditor.TextBoxControl, "Fill Quantity") Dim maintEditor As Telerik.Web.UI.GridDateTimeColumnEditor = CType(item.EditManager.GetColumnEditor("maint_Date"), Telerik.Web.UI.GridDateTimeColumnEditor) Dim actIndEditor As Telerik.Web.UI.GridCheckBoxColumnEditor = CType(item.EditManager.GetColumnEditor("active_indicator"), Telerik.Web.UI.GridCheckBoxColumnEditor) Dim notesEditor As Telerik.Web.UI.GridTextBoxColumnEditor = CType(item.EditManager.GetColumnEditor("Notes"), Telerik.Web.UI.GridTextBoxColumnEditor) ' Checks to see if items if item is 'PerformInsert' else check if it is 'UpdateButton' Dim buttonName As String = If(TypeOf item Is Telerik.Web.UI.IGridInsertItem, "PerformInsertButton", "UpdateButton") TryCast(item.FindControl(buttonName), Button).ValidationGroup = "gridFormValidation" Dim objConnection As SqlConnection Dim strSQL As String objConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("DC2_Data_WarehouseConnectionString_PRODUCTION").ConnectionString) ' Insert record strSQL = "INSERT INTO [data_warehouse].[dbo].[t_d_ATracker] ([PortalID],[asset_SN],[Fill_Qty],[Maint_Date],[asset_location],[asset_model],[active_indicator],[Asset_Notes]) " & "VALUES (@PortalID, @asset_SN, @Fill_Qty, @Maint_Date, @asset_location, @asset_model, @active_indicator, @Asset_Notes);" & "SELECT CAST(scope_identity() AS int);" Dim cmd As New SqlCommand(strSQL, objConnection) ' Add parameters cmd.Parameters.Add("@PortalID", SqlDbType.VarChar, 10).Value = portalIDEditor.Text cmd.Parameters.Add("@asset_SN", SqlDbType.VarChar, 20).Value = assetSNEditor.Text cmd.Parameters.Add("@Fill_Qty", SqlDbType.Int).Value = System.Convert.ToInt32(fillQtyEditor) cmd.Parameters.Add("@Maint_Date", SqlDbType.Date).Value = maintEditor cmd.Parameters.Add("@asset_location", SqlDbType.VarChar, 20).Value = assetLocEditor.Text cmd.Parameters.Add("@asset_model", SqlDbType.VarChar, 20).Value = assetModelEditor.Text cmd.Parameters.Add("@active_indicator", SqlDbType.Bit).Value = actIndEditor cmd.Parameters.Add("@Asset_Notes", SqlDbType.VarChar, -1).Value = notesEditor.Text End If End Sub

Private Sub AddRequiredFieldValidator(textBox As TextBox, fieldName As String)
    Dim validator As New CustomValidator()
    validator.ID = "CustomValidator_" & fieldName.Replace(" ", "_")
    validator.ControlToValidate = textBox.ID
    validator.ValidateEmptyText = True
    validator.ErrorMessage = String.Format("* {0} is required", fieldName)
    validator.ForeColor = Color.OrangeRed
    validator.ClientValidationFunction = "requiredFieldValidation"
    validator.ValidationGroup = "gridFormValidation"
    AddHandler validator.ServerValidate, AddressOf RequiredField_ServerValidate
    textBox.Parent.Controls.Add(validator)
End Sub

Private Sub AddNumericValidator(textBox As TextBox, fieldName As String)
    Dim validator As New CustomValidator()
    validator.ID = "CustomValidator_" & fieldName.Replace(" ", "_")
    validator.ControlToValidate = textBox.ID
    validator.ValidateEmptyText = True
    validator.ErrorMessage = String.Format("* {0} must be a numeric value", fieldName)
    validator.ForeColor = Color.OrangeRed
    validator.ClientValidationFunction = "numericFieldValidation"
    validator.ValidationGroup = "gridFormValidation"
    AddHandler validator.ServerValidate, AddressOf NumericField_ServerValidate
    textBox.Parent.Controls.Add(validator)
End Sub

Protected Sub RequiredField_ServerValidate(source As Object, args As ServerValidateEventArgs)
    args.IsValid = Not String.IsNullOrWhiteSpace(args.Value)
End Sub

Protected Sub NumericField_ServerValidate(source As Object, args As ServerValidateEventArgs)
    Dim value As String = args.Value.Trim()
    args.IsValid = String.IsNullOrEmpty(value) OrElse IsNumeric(value)
End Sub

 


Rumen
Telerik team
 answered on 24 Jun 2024
1 answer
67 views
Is there a way to upload all files in a directory via Dropzone?
Attila Antal
Telerik team
 answered on 21 Jun 2024
1 answer
56 views

I want to hide the Preview column that is withing a Template column and I'm not having any luck.

                                    <telerik:RadGrid ID="RadGridMaterials" runat="server" AllowPaging="True" AllowSorting="True" GridLines="None" Width="896px" PageSize="20">
                                        <PagerStyle Mode="NextPrevNumericAndAdvanced" />
                                        <MasterTableView AutoGenerateColumns="false" TableLayout="Fixed">
                                            <NoRecordsTemplate>
                                                No Material Records Found
                                            </NoRecordsTemplate>
                                            <Columns>
                                                <telerik:GridButtonColumn ButtonType="PushButton" HeaderText="" HeaderStyle-Width="50px" UniqueName="EditItem" Text="Edit" ConfirmText="Edit Item?" CommandName="EditItem" />
                                                <telerik:GridBoundColumn  DataField="itemsku" HeaderText="ID" HeaderStyle-Width="120px" />
                                                <telerik:GridBoundColumn  DataField="itemdesc" HeaderText="Description" HeaderStyle-Width="380px" />
                                                <telerik:GridBoundColumn  DataField="itemquantity" HeaderText="Quantity" HeaderStyle-Width="50px" ItemStyle-HorizontalAlign="Right" />
                                                <telerik:GridButtonColumn ButtonType="ImageButton" HeaderText="Adjust Quantity" HeaderStyle-Width="70px" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" UniqueName="EditQty" ImageUrl="~\images\Edit-32.png" CommandName="EditQty" />
                                                <telerik:GridButtonColumn ButtonType="ImageButton" HeaderText="Rename" HeaderStyle-Width="70px" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" UniqueName="Rename" ImageUrl="~\images\Edit-32.png" CommandName="Rename" />
                                                
                                                <%--<telerik:GridButtonColumn ButtonType="ImageButton" HeaderText="Preview" HeaderStyle-Width="60px" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" UniqueName="Preview" ImageUrl="~\images\transparent.png" />--%>
                                                <telerik:GridTemplateColumn HeaderText="Preview" HeaderStyle-Width="50px">
                                                    <ItemTemplate>
                                                        <button id="Preview" type="button" data-toggle="modal" data-target="#renderingPDF" class="previewbutton">
                                                            <img src="/images/Adobe-32.png"
                                                        </button> 
                                                    </ItemTemplate>                                                
                                                </telerik:GridTemplateColumn>
                                                
                                                <telerik:GridButtonColumn ButtonType="ImageButton" HeaderText="Download" HeaderStyle-Width="60px" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" UniqueName="Download" ImageUrl="~\images\transparent.png" />
                                                <telerik:GridButtonColumn ButtonType="ImageButton" HeaderText="Delete" HeaderStyle-Width="48px" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" UniqueName="DeleteItem" ImageUrl="~\images\Garbage-Closed-32.png" ConfirmText="Delete Item?" CommandName="DeleteItem" />
                                                <telerik:GridBoundColumn  DataField="PDF" Display="false" UniqueName="PDF" />
                                                <telerik:GridBoundColumn  DataField="CartContentPk" Display="false" UniqueName="CartContentPk" />
                                                <telerik:GridBoundColumn  DataField="SavePk" Display="false" UniqueName="SavePk" />
                                                <telerik:GridBoundColumn  DataField="Type" Display="false" UniqueName="Type" />
                                                <telerik:GridBoundColumn  DataField="EventOrderItemsId" Display="false" UniqueName="EventOrderItemsId" />
                                                <telerik:GridBoundColumn  DataField="EventLinkPK" Display="false" UniqueName="EventLinkPK" />
                                            </Columns>
                                        </MasterTableView>
                                    </telerik:RadGrid>

  Private Sub RadGridMaterials_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGridMaterials.ItemDataBound
            Try
                If TypeOf e.Item Is GridDataItem Then

                    Dim dataItem As GridDataItem = TryCast(e.Item, GridDataItem)
 '----------------------------------------------------------------------------------------------

                    'Dim btnPreview As button = TryCast(dataItem("Preview").Controls(0), button)
                    Dim btnPreview As HtmlButton = New HtmlButton
                    ' Try
                    btnPreview = CType(dataItem.FindControl("Preview"), HtmlButton)
                    'Catch ex1 As Exception
                    'LogException(New Exception("Define Button Preview" & ex1.Message.ToString))
                    'End Try

                    Try
                        If dataItem("PDF").Text = "&nbsp;" Or dataItem("CartContentPk").Text = "&nbsp;" Then
                            'btnPreview.Enabled = False
                            'btnPreview.ImageUrl = "~\images\transparent.png"
                            btnPreview.Visible = False
                        Else
                            'btnPreview.ImageUrl = "~\images\Adobe-32.png" 'Stuffed_Folder.png"
                            'btnPreview.Enabled = True
                            'btnPreview.ToolTip = dataItem("ItemSKU").Text
                            btnPreview.Visible = True
                            'btnPreview.OnClientClick = "window.open('" & dataItem("PDF").Text & "','','')"
                        End If
                    Catch ex As Exception
                        LogException(ex)
                    End Try

                    '----------------------------------------------------------------------------------------------
                End If

            Catch ex As Exception
                lblErrMessage.Text = ex.ToString
            End Try
        End Sub


Vasko
Telerik team
 answered on 20 Jun 2024
2 answers
385 views

Hello,

We are not able to open hyperlinks which are in the content area of the RadEditor.  We are experiencing this behavior in our code as well as on your demo site.  Here is how to replicate the issue on the demo site.

a)  Go to the overview page on the RadEditor demo site:  http://demos.telerik.com/aspnet-ajax/editor/examples/overview/defaultcs.aspx

b)  Clear all content in the RadEditor

c)  Click on the <html> tab for the RadEditor

d)  Enter the following hyperlink into the content area:  <a href="http://www.w3schools.com/html/">Visit our HTML tutorial</a>

e)  Click on the Preview tab of the RadEditor

f)  Click on the hyperlink for d) above.  This will not take the browser to the hyperlink which was added into the content area

This behavior is consistent between Google Chrome, Firefox, Edge, Safari and IE

Please advise.

Mark
Top achievements
Rank 1
Iron
 answered on 19 Jun 2024
2 answers
430 views

Hi!

I have a RadEditor on a page and links do not work when clicked.  I read in other posts that the links won't work due to it being rendered in an IFRAME, and try some JavaScript workarounds:

https://www.telerik.com/forums/radeditor-hyperlinks-not-working

 

I tried both of the workarounds mentioned there:

http://docs.telerik.com/devtools/aspnet-ajax/controls/editor/how-to/open-link-in-a-new-window-when-clicked
http://docs.telerik.com/devtools/aspnet-ajax/controls/editor/how-to/open-link-in-a-new-window-on-double-click

But neither was able to open a new page.  I set ContentFilters to "None", and still the same issue so it's not related to that.

Thanks!

Mark
Top achievements
Rank 1
Iron
 answered on 19 Jun 2024
1 answer
75 views

Hi all,

I have tried to use the samples shown in this post ( https://www.telerik.com/forums/determine-column-series-color ) but cannot get it to apply for a pie chart. I have several dark & light coloured pie segments (eg: black & yellow) and cannot set a single colour across the board.

My current function looks like this:

function Chart1SeriesHover(e) { setTimeout(function () { switch (e.category) { case'Not Done': $telerik.$('.k-tooltip')[0].style.color = "white"; //black pie segment break; default: break;

} }, 10); }


but I keep getting the following error in DevTools:

Uncaught TypeError: Cannot read properties of undefined (reading 'style')

Any help would be greatly appreciated.

Vasko
Telerik team
 answered on 19 Jun 2024
1 answer
89 views

I have a RadGrid that required two separate Edit Buttons used for InPlace EditMode. I have created two GridButtonColumns each with a unique CommandName. I am capturing these button presses in the RadGrid.ItemCommand method. What I need, however, is some way of displaying a Confirm and a Cancel button while in Edit Mode for each of these edit buttons.  How can I achieve this?

Thanks!

Vasko
Telerik team
 answered on 12 Jun 2024
1 answer
135 views

If I set the background color of dates in a raddatepicker the background color will show when I hover over the date but not before I do.

If I set the render mode to lightweight the background color does show upon the raddatepicker showing.

Does anyone else have this problem?

Here is the control

<telerik:RadDatePicker ID="rdpPickUpDate" runat="server"  >
   <Calendar OnDayRender="Calendar_OnDayRender" ></Calendar>
</telerik:RadDatePicker>

 

Here is the code to set the background color to red for Mondays

        protected void Calendar_OnDayRender(object sender, Telerik.Web.UI.Calendar.DayRenderEventArgs e)
        {
            if (e.Day.Date.DayOfWeek == DayOfWeek.Monday)
            {
                RadCalendarDay calendarDay = new RadCalendarDay();
                calendarDay.Date = e.Day.Date;

                calendarDay.ItemStyle.BackColor = System.Drawing.Color.Red;


                calendarDay.Repeatable = Telerik.Web.UI.Calendar.RecurringEvents.DayAndMonth;

                rdpPickUpDate.Calendar.SpecialDays.Add(calendarDay);
            }
        }

 

Does anyone have any ideas

Vasko
Telerik team
 answered on 10 Jun 2024
4 answers
632 views
When I click "Get latest" the 2024.2.513 version is downloaded but does not appear in the dropdownlist so I cannot apply the update to my projects.
Rumen
Telerik team
 answered on 10 Jun 2024
1 answer
154 views

We have the RadImageGallery implemented on page. The code behind loads up one or more images by reading in an array of bytes from each file.  Occasionally, an exception is thrown when one of those images is invalid (corrupt or some other issue).  OK, that's fine, but we would like to trap the exception and handle the error in a particular way.  But... we don't seem to be able to trap it other than in our last-chance global exception handler.

The binary data is created in the NeedDataSource event, and that returns successfully.  I've added other events and set breakpoints in each of them, and they all return ok.  So, is there an event we can handle that would be appropriate for a simple try/catch block?

Pretty simple markup for the RadImageGallery control (note, all the events after the OnNeedDataSource were added simply to test out if there was a place we could try/catch the exception, but no exception was thrown in those events):

    <telerik:RadImageGallery ID="galleryImages" runat="server" RenderMode="Lightweight"
        DisplayAreaMode="Image" LoopItems="true" DataImageField="ImageBytes" DataDescriptionField="Description" DataTitleField="Title"
        OnNeedDataSource="galleryImages_NeedDataSource"
        OnDataBinding="galleryImages_DataBinding"
        OnImageRequested="galleryImages_ImageRequested" 
        OnItemCreated="galleryImages_ItemCreated" 
        OnPreRender="galleryImages_PreRender">
    </telerik:RadImageGallery>

 

Code behind for NeedDataSource (which returns successfully):

    protected void galleryImages_NeedDataSource(object sender, Telerik.Web.UI.ImageGalleryNeedDataSourceEventArgs e)
    {
        galleryImages.Visible = false;

        FileManager fileManager = new FileManager ();
        DataTable dt = fileManager.GetFileList();
        var imageFiles = fileManager.GetGalleryImages(dt);

        if (imageFiles.Count() == 0)
        {
            txtNotes.Text = "There are no image files to display.";
            return;
        }

        try
        {
            galleryImages.DataSource = imageFiles;
            galleryImages.Visible = true;
        }
        catch (Exception ex)
        {
            LogException(ex);
            ErrorMessage("An unexpected occurred while reading one or more the image files");
        }

        if (fileManager.HasErrors)
        {
            txtErrors.Text = "The following errors were encountered:<br/><ul>" + String.Join("<li>", fileManager.ErrorList) + "</ul>";
        }
    }

 

Library code that reads image files into byte arrays (also return successfully):

        public List<GalleryImage> GetGalleryImages(DataTable srcDataTable)
        {

            //...


            foreach (DataRow dr in query)
            {
                CustomImageFile f = new CustomImageFile(dr);                

                try
                {
                    byte[] byteArray = File.ReadAllBytes(f.FullFileName);
                    GalleryImage img = new GalleryImage
                    {
                        ImageBytes = byteArray,
                        Description = $"{f.Description}", // [{f.Name}]
                    };
                    imageList.Add(img);
                }
                catch (Exception ex)
                {
                    Errors.Add($"{f.Name} could not be read");
                    LogException(ex);                    
                }
            }
            return imageList;
        }

 

Yet when there is an invalid file encountered, we get this:

[ArgumentException: Parameter is not valid.]
   System.Drawing.Image.FromStream(Stream stream, Boolean useEmbeddedColorManagement, Boolean validateImageData) +1162080
   Telerik.Web.UI.BinaryImageFormatHelper.CreateImgFromBytes(Byte[] data) +69

[ArgumentException: The provided binary data may not be valid image or may contains unknown header]
   Telerik.Web.UI.BinaryImageFormatHelper.CreateImgFromBytes(Byte[] data) +120
   Telerik.Web.UI.BinaryImageTransformationFilter.ProcessImageInternal(Byte[] image) +44
   Telerik.Web.UI.BinaryImageTransformationFilter.ProcessImage(Byte[] image) +20
   Telerik.Web.UI.BinaryImageFilterProcessor.ProcessFilters(Byte[] imageData) +112
   Telerik.Web.UI.RadBinaryImage.ProcessImageData() +57
   Telerik.Web.UI.RadBinaryImage.OnPreRender(EventArgs e) +20
   System.Web.UI.Control.PreRenderRecursiveInternal() +90
   System.Web.UI.Control.PreRenderRecursiveInternal() +163

 

Attila Antal
Telerik team
 answered on 07 Jun 2024
Narrow your results
Selected tags
Tags
+? more
Top users last month
Anislav
Top achievements
Rank 6
Silver
Bronze
Bronze
Jianxian
Top achievements
Rank 1
Iron
Marco
Top achievements
Rank 3
Iron
Iron
Iron
Jim
Top achievements
Rank 2
Iron
Iron
Nurik
Top achievements
Rank 2
Iron
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Anislav
Top achievements
Rank 6
Silver
Bronze
Bronze
Jianxian
Top achievements
Rank 1
Iron
Marco
Top achievements
Rank 3
Iron
Iron
Iron
Jim
Top achievements
Rank 2
Iron
Iron
Nurik
Top achievements
Rank 2
Iron
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?