i used Grid view and here is the code i wrote:
[code=vbnet]
Protected Sub ButtonAddFile_C lick(ByVal sender As Object, ByVal e As EventArgs)
Dim gv As New GridView
gv.Style.Add("p osition", "absolute")
gv.Style.Add("l eft", "575px")
gv.Style.Add("t op", "220px")
gv.EnableViewSt ate = False
form1.Controls. Add(gv)
gv.DataSource = GetDataTable()
gv.DataBind()
Dim lbl As New Label
lbl.Style.Add(" position", "absolute")
lbl.Style.Add(" left", "575px")
lbl.Style.Add(" top", "20px")
End Sub
Private Function GetDataTable() As DataTable
Dim doc As New DataTable("Docu ment")
Dim id As New DataColumn("Doc ument")
id.DataType = GetType(String)
id.Unique = True
id.AllowDBNull = False
id.Caption = "Document"
doc.Columns.Add (id)
Dim filing As New DataColumn("Typ e")
filing.DataType = GetType(String)
'filing.MaxLeng th = 35
filing.AllowDBN ull = False
doc.Columns.Add (filing)
doc.PrimaryKey = New DataColumn() {id}
'add data to data table
Dim newdoc As DataRow = doc.NewRow()
newdoc("Documen t") = FileToUpload.Po stedFile.FileNa me
newdoc("Type") = listDocType.Sel ectedValue
doc.Rows.Add(ne wdoc)
Return doc
End Function
[/code]
1. But it adds only one row everytime i click the AddFile button and overrides the previous row, it doesnt add on after another, whats going wrong here?
2. Also If I have to add a delete button of GridView , what code should i write so that it deletes that particular row every time i click delete
[code=vbnet]
Protected Sub ButtonAddFile_C lick(ByVal sender As Object, ByVal e As EventArgs)
Dim gv As New GridView
gv.Style.Add("p osition", "absolute")
gv.Style.Add("l eft", "575px")
gv.Style.Add("t op", "220px")
gv.EnableViewSt ate = False
form1.Controls. Add(gv)
gv.DataSource = GetDataTable()
gv.DataBind()
Dim lbl As New Label
lbl.Style.Add(" position", "absolute")
lbl.Style.Add(" left", "575px")
lbl.Style.Add(" top", "20px")
End Sub
Private Function GetDataTable() As DataTable
Dim doc As New DataTable("Docu ment")
Dim id As New DataColumn("Doc ument")
id.DataType = GetType(String)
id.Unique = True
id.AllowDBNull = False
id.Caption = "Document"
doc.Columns.Add (id)
Dim filing As New DataColumn("Typ e")
filing.DataType = GetType(String)
'filing.MaxLeng th = 35
filing.AllowDBN ull = False
doc.Columns.Add (filing)
doc.PrimaryKey = New DataColumn() {id}
'add data to data table
Dim newdoc As DataRow = doc.NewRow()
newdoc("Documen t") = FileToUpload.Po stedFile.FileNa me
newdoc("Type") = listDocType.Sel ectedValue
doc.Rows.Add(ne wdoc)
Return doc
End Function
[/code]
1. But it adds only one row everytime i click the AddFile button and overrides the previous row, it doesnt add on after another, whats going wrong here?
2. Also If I have to add a delete button of GridView , what code should i write so that it deletes that particular row every time i click delete
Comment