Appending CSV to RadGrid

2 posts, 0 answers
  1. Jonathan
    Jonathan avatar
    5 posts
    Member since:
    Sep 2016

    Posted 19 Oct 2016 Link to this post


        I have a radGrid which i'd like to append a csv to the rows in the radGrid. How would I go about doing this? I have an upload function in my code but when it run it replaces all data in grid with data from the chosen CSV.



    Imports System.Data
    Imports Telerik.Web.UI
    Imports System.IO
    Imports System.Data.SqlClient
    Imports System.Configuration

    Partial Class JPTest
        Inherits System.Web.UI.Page

        Sub Page_Load(ByVal Sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            If Not IsPostBack Then
            End If
        End Sub
        Private Sub LoadAtrributeDropDown()
            'AttributeTypeBox.DataSource = GetDataTable("SELECT TOP 10000 lkct.CategoryLabel, lkct.CategoryID  FROM dbo.LkupCategories lkct ORDER BY lkct.CategoryLabel")

            Dim ConnString As [String] = ConfigurationManager.ConnectionStrings("eCommerceClassification").ConnectionString
            Dim adapt As New SqlDataAdapter()
            Dim CategoryDataTable As New DataTable()
            Using conn As New SqlConnection(ConnString)

                adapt.SelectCommand = New SqlCommand("SELECT TOP 10000 lkct.CategoryLabel, lkct.CategoryID  FROM dbo.LkupCategories lkct ORDER BY lkct.CategoryLabel", conn)
            End Using
            AttributeTypeBox.DataTextField = "CategoryLabel"
            AttributeTypeBox.DataValueField = "CategoryID"
            AttributeTypeBox.DataSource = CategoryDataTable

            AttributeTypeBox.Items.Insert(0, "----SELECT----")

        End Sub

        'Protected Sub RadGrid1_NeedDataSource(ByVal source As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles ReceiptGrid.NeedDataSource

        'End Sub

        Public Function GetDataTable(ByVal query As String) As DataTable
            Dim ConnString As [String] = ConfigurationManager.ConnectionStrings("eCommerceClassification").ConnectionString
            Dim adapter As New SqlDataAdapter()
            Dim myDataTable As New DataTable()
            Using conn As New SqlConnection(ConnString)
                adapter.SelectCommand = New SqlCommand(query, conn)
            End Using
            Return myDataTable
        End Function
        Protected Sub AttributeTypeBox_SelectedIndexChanged(sender As Object, e As RadComboBoxSelectedIndexChangedEventArgs)
            ReceiptGrid.DataSource = GetDataTable("SELECT TOP 5000 ah.CategoryID, lkct.CategoryLabel, lka.AttributeLabel, lkat.AttributeTypeLabel FROM dbo.AttributeHierarchy ah INNER JOIN dbo.LkupCategories lkct WITH (NOLOCK) ON ah.CategoryID = lkct.CategoryID INNER JOIN dbo.LkupAttributes lka WITH (NOLOCK) ON ah.AttributeTypeID = lka.AttributeTypeID INNER JOIN dbo.LkupAttributeTypes lkat WITH (NOLOCK) ON lkat.AttributeTypeID = ah.AttributeTypeID WHERE lkct.CategoryID = '" & AttributeTypeBox.SelectedItem.Value & "' ORDER BY ah.DateActivated DESC")
        End Sub

        Public Function Upload(sender As Object, e As EventArgs) As DataTable
            'Upload and Import TabDelimited CSV
            Dim csvPath As String = Server.MapPath("~/File") + Path.GetFileName(FileUpload1.PostedFile.FileName)

            Dim dt As New DataTable()
            dt.Columns.AddRange(New DataColumn(3) {New DataColumn("CategoryID", GetType(String)), New DataColumn("CategoryLabel", GetType(String)), New DataColumn("AttributeLabel", GetType(String)), New DataColumn("AttributeTypeLabel", GetType(String))})

            Dim csvData As String = File.ReadAllText(csvPath)
            For Each row As String In csvData.Split(Environment.NewLine) 'How to split csv?'
                If Not String.IsNullOrEmpty(row) Then
                    Dim i As Integer = 0
                    For Each cell As String In row.Split(","c)
                        dt.Rows(dt.Rows.Count - 1)(i) = cell
                        i += 1
                End If
            ReceiptGrid.DataSource = dt
        End Function
    End Class





  2. Marin Bratanov
    Marin Bratanov avatar
    3626 posts

    Posted 24 Oct 2016 Link to this post

    Hi Jonathan,

    Your other thread with the same question is already answered and I suggest you refer to it: In general, posting only one thread with all the information yields better responses and keeps the information in one place, easy to track.


    Marin Bratanov
    Telerik by Progress
    Check out the new UI for ASP.NET Core, the most complete UI suite for ASP.NET Core development on the market, with 60+ tried-and-tested widgets, based on Kendo UI.
Back to Top