Skip to content

Add columns in grid from textbox Ask Question

scropio gurl

Asked May 11, 2017, 9:48 PM EDT2 answers
Share
LinkedInX

I have a grid and this already have data like this

Code
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

Code
excelcol1  excelcol2    
345        abc 
  1234        abc

how do I this?

I did with this

PowerShell
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'.**

2 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    You can add those 2 new columns to your datasource and then you can use that datasource to bind the gridview.
    0
  • 0
    but i copy text in textbox and from textbox i want to add new columns in gridview ? how i do this
    0