scropio gurl

scropio gurl

  • NA
  • 147
  • 99.5k

add columns in grid from textbox Ask Question

May 12 2017 1:48 AM

I have a grid and this already have data like this

Column3 Column4 
123
345
1345
235

now I want to add two more columns from textbox to grid e.g if I copy this data in the textbox then want to add this data in a grid

excelcol1  excelcol2    
345
abc
1234 abc

how do I this?

I did with this

Protected Sub Paste(sender As Object, e As EventArgs) Handles textData.TextChanged     Try         gridviewss.Columns.Add(New DataColumn(1) {New DataColumn("excelcol1", GetType(Integer)), New DataColumn("excelcol2", GetType(String))}) Dim cCon As String = Request.Form(textData.UniqueID) For Each row As String In cCon.Split(ControlChars.Lf) If Not String.IsNullOrEmpty(row) Then                 gridviewss.Rows.Add() Dim i As Integer = 0 For Each cell As String In row.Split(ControlChars.Tab) If i > 1 Then                        textData.Text = "" Exit Sub Else If cell.Trim() = "" Then                             cell = "0" End If                         gridviewss.Rows(gridviewss.Rows.Count - 1)(i) = cell                         i += 1 End If Next End If Next Catch ex As Exception      End Try End Sub

but this shows an error

*Error 204 'Add' is not a member of 'System.Web.UI.WebControls.GridViewRowCollection'.

Error 205 Class 'System.Web.UI.WebControls.GridViewRow' cannot be indexed because it has no default property.

Error 203 Value of type '1-dimensional array of System.Data.DataColumn' cannot be converted to 'System.Web.UI.WebControls.DataControlField'.**


Answers (2)