I have a datagridview which has 3 columns 1st and 2nd is textbox columns and 3rd one is link column. I try to add a new row using the command.
STEPS.Rows.Add(New String() {stepNo, "This is description for step " & stepNo},"link")
But for the first time when I try to execute the above line it shows index was outside the bounds of the array
. This doesn't happen when I am trying to insert the second row. Also this does not happen when I am having all the 3 columns as TextBoxs.
Please help me.
You are trying to use step.rows.add method but steps is a gridview not a datatable. the datatable object contains a methods row.add that expect a datarow object, this example show add row into datatable , and link with a gridview.
Dim dt As New DataTable
dt.Columns.Add("field1")
dt.Columns.Add("field2")
Dim row1 As DataRow = dt.NewRow
row1.Item("field1") = "Hello"
row1.Item("field2") = "World"
Dim row2 As DataRow = dt.NewRow
row2.Item("field1") = "Hello2"
row2.Item("field2") = "World2"
dt.Rows.Add(row1)
dt.Rows.Add(row2)
GridView1.DataSource = dt
GridView1.DataBind()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.