Hi guys.. i can bind csv file to Gridview but how can i update it?
Below is my code to Bind csv file to Gridview.
HTML
<asp:GridView ID="GridView" runat="server" DataKeyNames="postcode">
</asp:GridView>
CODE BEHIND
'Upload and save the file
Dim csvPath As String = Server.MapPath("~/csv/") + "location.csv"
'Create a DataTable.
Dim DT As New DataTable()
DT.Columns.Add("Postcode")
DT.Columns.Add("City")
DT.Columns.Add("State")
'DT.Columns.AddRange(New DataColumn(2) {New DataColumn("POSTCODE", GetType(Integer)), New DataColumn("CITY", GetType(String)), New DataColumn("STATE", GetType(String))})
'Read the contents of CSV file.
Dim csvData As String = File.ReadAllText(csvPath)
'Execute a loop over the rows.
For Each row As String In csvData.Split(ControlChars.Lf)
If Not String.IsNullOrEmpty(row) Then
DT.Rows.Add()
Dim i As Integer = 0
'Execute a loop over the columns.
For Each cell As String In row.Split(","c)
DT.Rows(DT.Rows.Count - 1)(i) = cell
i += 1
Next
End If
Next
'Bind the DataTable.
Me.GridView.DataSource = DT
Me.GridView.DataBind()
Member
103 Points
796 Posts
How can update existing data in Gridview (csv file)
Jun 12, 2020 03:37 AM|kengkit|LINK
Hi guys.. i can bind csv file to Gridview but how can i update it?
Below is my code to Bind csv file to Gridview.
HTML
<asp:GridView ID="GridView" runat="server" DataKeyNames="postcode">
</asp:GridView>
CODE BEHIND