buenas tardes acudo a solicitarle ayuda ya que tengo ratos de estar queriendo adicionar datos de un select aun gridview
estoy utilizando el siguiente codigo que me permite adicionar y quitar filas al gridview
Private Sub FirstGridViewRow()
Dim dt As New DataTable()
Dim dr As DataRow = Nothing
dt.Columns.Add(New DataColumn("RowNumber", GetType(String)))
dt.Columns.Add(New DataColumn("ACCESLOTE", GetType(String)))
dt.Columns.Add(New DataColumn("CODILOTE", GetType(String)))
dt.Columns.Add(New DataColumn("NOMBLOTE", GetType(String)))
dt.Columns.Add(New DataColumn("AREA", GetType(String)))
dt.Columns.Add(New DataColumn("TONELADAS", GetType(String)))
dt.Columns.Add(New DataColumn("TOTAL_TC", GetType(String)))
dt.Columns.Add(New DataColumn("EDAD_LOTE", GetType(String)))
dt.Columns.Add(New DataColumn("CODIVARIEDA", GetType(String)))
dt.Columns.Add(New DataColumn("NOM_VARIEDAD", GetType(String)))
dt.Columns.Add(New DataColumn("CODIUBICACION", GetType(String)))
dt.Columns.Add(New DataColumn("CANTON", GetType(String)))
dt.Columns.Add(New DataColumn("ZONA", GetType(String)))
dr = dt.NewRow()
dr("RowNumber") = 1
dr("ACCESLOTE") = String.Empty
dr("CODILOTE") = String.Empty
dr("NOMBLOTE") = String.Empty
dr("AREA") = String.Empty
dr("TONELADAS") = String.Empty
dr("TOTAL_TC") = String.Empty
dr("EDAD_LOTE") = String.Empty
dr("CODIVARIEDA") = String.Empty
dr("NOM_VARIEDAD") = String.Empty
dr("CODIUBICACION") = String.Empty
dr("CANTON") = String.Empty
dr("ZONA") = String.Empty
dt.Rows.Add(dr)
ViewState("CurrentTable") = dt
grvStudentDetails.DataSource = dt
grvStudentDetails.DataBind()
Dim txn As TextBox = DirectCast(grvStudentDetails.Rows(0).Cells(2).FindControl("txt_CODILOTE"), TextBox)
txn.Focus()
Dim btnAdd As Button = DirectCast(grvStudentDetails.FooterRow.Cells(2).FindControl("ButtonAdd"), Button)
Page.Form.DefaultFocus = btnAdd.ClientID
End Sub
Private Sub AddNewRow()
Dim rowIndex As Integer = 0
If ViewState("CurrentTable") IsNot Nothing Then
Dim dtCurrentTable As DataTable = DirectCast(ViewState("CurrentTable"), DataTable)
Dim drCurrentRow As DataRow = Nothing
If dtCurrentTable.Rows.Count > 0 Then
For i As Integer = 1 To dtCurrentTable.Rows.Count
Dim ACCESLOTE As TextBox = DirectCast(grvStudentDetails.Rows(rowIndex).Cells(1).FindControl("txt_ACCESLOTE"), TextBox)
Dim CODILOTE As TextBox = DirectCast(grvStudentDetails.Rows(rowIndex).Cells(2).FindControl("txt_CODILOTE"), TextBox)
Dim NOMBLOTE As TextBox = DirectCast(grvStudentDetails.Rows(rowIndex).Cells(3).FindControl("txt_NOMBLOTE"), TextBox)
Dim AREA As TextBox = DirectCast(grvStudentDetails.Rows(rowIndex).Cells(4).FindControl("txt_AREA"), TextBox)
Dim TONELADAS As TextBox = DirectCast(grvStudentDetails.Rows(rowIndex).Cells(5).FindControl("txt_TONELADAS"), TextBox)
Dim TOTAL_TC As TextBox = DirectCast(grvStudentDetails.Rows(rowIndex).Cells(6).FindControl("txt_TOTAL_TC"), TextBox)
Dim EDAD_LOTE As TextBox = DirectCast(grvStudentDetails.Rows(rowIndex).Cells(7).FindControl("txt_EDAD_LOTE"), TextBox)
Dim CODIVARIEDA As TextBox = DirectCast(grvStudentDetails.Rows(rowIndex).Cells(8).FindControl("txt_CODIVARIEDA"), TextBox)
Dim NOM_VARIEDAD As TextBox = DirectCast(grvStudentDetails.Rows(rowIndex).Cells(9).FindControl("txt_NOM_VARIEDAD"), TextBox)
Dim CODIUBICACION As TextBox = DirectCast(grvStudentDetails.Rows(rowIndex).Cells(10).FindControl("txt_CODIUBICACION"), TextBox)
Dim CANTON As TextBox = DirectCast(grvStudentDetails.Rows(rowIndex).Cells(11).FindControl("txt_CANTON"), TextBox)
Dim ZONA As TextBox = DirectCast(grvStudentDetails.Rows(rowIndex).Cells(12).FindControl("txt_ZONA"), TextBox)
drCurrentRow = dtCurrentTable.NewRow()
drCurrentRow("RowNumber") = i + 1
dtCurrentTable.Rows(i - 1)("ACCESLOTE") = ACCESLOTE.Text
dtCurrentTable.Rows(i - 1)("CODILOTE") = CODILOTE.Text
dtCurrentTable.Rows(i - 1)("NOMBLOTE") = NOMBLOTE.Text
dtCurrentTable.Rows(i - 1)("AREA") = AREA.Text
dtCurrentTable.Rows(i - 1)("TONELADAS") = TONELADAS.Text
dtCurrentTable.Rows(i - 1)("TOTAL_TC") = TOTAL_TC.Text
dtCurrentTable.Rows(i - 1)("EDAD_LOTE") = EDAD_LOTE.Text
dtCurrentTable.Rows(i - 1)("CODIVARIEDA") = CODIVARIEDA.Text
dtCurrentTable.Rows(i - 1)("NOM_VARIEDAD") = NOM_VARIEDAD.Text
dtCurrentTable.Rows(i - 1)("CODIUBICACION") = CODIUBICACION.Text
dtCurrentTable.Rows(i - 1)("CANTON") = CANTON.Text
dtCurrentTable.Rows(i - 1)("ZONA") = ZONA.Text
rowIndex += 1
Next
dtCurrentTable.Rows.Add(drCurrentRow)
ViewState("CurrentTable") = dtCurrentTable
grvStudentDetails.DataSource = dtCurrentTable
grvStudentDetails.DataBind()
Dim txn As TextBox = DirectCast(grvStudentDetails.Rows(rowIndex).Cells(2).FindControl("txt_CODILOTE"), TextBox)
' txn.Focus;
txn.Focus()
End If
Else
Response.Write("ViewState is null")
End If
SetPreviousData()
End Sub
Private Sub SetPreviousData()
Dim rowIndex As Integer = 0
If ViewState("CurrentTable") IsNot Nothing Then
Dim dt As DataTable = DirectCast(ViewState("CurrentTable"), DataTable)
If dt.Rows.Count > 0 Then
For i As Integer = 0 To dt.Rows.Count - 1
Dim ACCESLOTE As TextBox = DirectCast(grvStudentDetails.Rows(rowIndex).Cells(1).FindControl("txt_ACCESLOTE"), TextBox)
Dim CODILOTE As TextBox = DirectCast(grvStudentDetails.Rows(rowIndex).Cells(2).FindControl("txt_CODILOTE"), TextBox)
Dim NOMBLOTE As TextBox = DirectCast(grvStudentDetails.Rows(rowIndex).Cells(3).FindControl("txt_NOMBLOTE"), TextBox)
Dim AREA As TextBox = DirectCast(grvStudentDetails.Rows(rowIndex).Cells(4).FindControl("txt_AREA"), TextBox)
Dim TONELADAS As TextBox = DirectCast(grvStudentDetails.Rows(rowIndex).Cells(5).FindControl("txt_TONELADAS"), TextBox)
Dim TOTAL_TC As TextBox = DirectCast(grvStudentDetails.Rows(rowIndex).Cells(6).FindControl("txt_TOTAL_TC"), TextBox)
Dim EDAD_LOTE As TextBox = DirectCast(grvStudentDetails.Rows(rowIndex).Cells(7).FindControl("txt_EDAD_LOTE"), TextBox)
Dim CODIVARIEDA As TextBox = DirectCast(grvStudentDetails.Rows(rowIndex).Cells(8).FindControl("txt_CODIVARIEDA"), TextBox)
Dim NOM_VARIEDAD As TextBox = DirectCast(grvStudentDetails.Rows(rowIndex).Cells(9).FindControl("txt_NOM_VARIEDAD"), TextBox)
Dim CODIUBICACION As TextBox = DirectCast(grvStudentDetails.Rows(rowIndex).Cells(10).FindControl("txt_CODIUBICACION"), TextBox)
Dim CANTON As TextBox = DirectCast(grvStudentDetails.Rows(rowIndex).Cells(11).FindControl("txt_CANTON"), TextBox)
Dim ZONA As TextBox = DirectCast(grvStudentDetails.Rows(rowIndex).Cells(12).FindControl("txt_ZONA"), TextBox)
' drCurrentRow["RowNumber"] = i + 1;
grvStudentDetails.Rows(i).Cells(1).Text = Convert.ToString(i + 1)
ACCESLOTE.Text = dt.Rows(i)("ACCESLOTE").ToString
CODILOTE.Text = dt.Rows(i)("CODILOTE").ToString()
NOMBLOTE.Text = dt.Rows(i)("NOMBLOTE").ToString()
AREA.Text = dt.Rows(i)("AREA").ToString()
TONELADAS.Text = dt.Rows(i)("TONELADAS").ToString()
TOTAL_TC.Text = dt.Rows(i)("TOTAL_TC").ToString()
EDAD_LOTE.Text = dt.Rows(i)("EDAD_LOTE").ToString()
CODIVARIEDA.Text = dt.Rows(i)("CODIVARIEDA").ToString()
NOM_VARIEDAD.Text = dt.Rows(i)("NOM_VARIEDAD").ToString()
CODIUBICACION.Text = dt.Rows(i)("CODIUBICACION").ToString()
CANTON.Text = dt.Rows(i)("CANTON").ToString()
ZONA.Text = dt.Rows(i)("ZONA").ToString()
rowIndex += 1
Next
End If
End If
End Sub
Private Sub SetRowData()
Dim rowIndex As Integer = 0
If ViewState("CurrentTable") IsNot Nothing Then
Dim dtCurrentTable As DataTable = DirectCast(ViewState("CurrentTable"), DataTable)
Dim drCurrentRow As DataRow = Nothing
If dtCurrentTable.Rows.Count > 0 Then
For i As Integer = 1 To dtCurrentTable.Rows.Count
Dim ACCESLOTE As TextBox = DirectCast(grvStudentDetails.Rows(rowIndex).Cells(1).FindControl("txt_ACCESLOTE"), TextBox)
Dim CODILOTE As TextBox = DirectCast(grvStudentDetails.Rows(rowIndex).Cells(2).FindControl("txt_CODILOTE"), TextBox)
Dim NOMBLOTE As TextBox = DirectCast(grvStudentDetails.Rows(rowIndex).Cells(3).FindControl("txt_NOMBLOTE"), TextBox)
Dim AREA As TextBox = DirectCast(grvStudentDetails.Rows(rowIndex).Cells(4).FindControl("txt_AREA"), TextBox)
Dim TONELADAS As TextBox = DirectCast(grvStudentDetails.Rows(rowIndex).Cells(5).FindControl("txt_TONELADAS"), TextBox)
Dim TOTAL_TC As TextBox = DirectCast(grvStudentDetails.Rows(rowIndex).Cells(6).FindControl("txt_TOTAL_TC"), TextBox)
Dim EDAD_LOTE As TextBox = DirectCast(grvStudentDetails.Rows(rowIndex).Cells(7).FindControl("txt_EDAD_LOTE"), TextBox)
Dim CODIVARIEDA As TextBox = DirectCast(grvStudentDetails.Rows(rowIndex).Cells(8).FindControl("txt_CODIVARIEDA"), TextBox)
Dim NOM_VARIEDAD As TextBox = DirectCast(grvStudentDetails.Rows(rowIndex).Cells(9).FindControl("txt_NOM_VARIEDAD"), TextBox)
Dim CODIUBICACION As TextBox = DirectCast(grvStudentDetails.Rows(rowIndex).Cells(10).FindControl("txt_CODIUBICACION"), TextBox)
Dim CANTON As TextBox = DirectCast(grvStudentDetails.Rows(rowIndex).Cells(11).FindControl("txt_CANTON"), TextBox)
Dim ZONA As TextBox = DirectCast(grvStudentDetails.Rows(rowIndex).Cells(12).FindControl("txt_ZONA"), TextBox)
drCurrentRow = dtCurrentTable.NewRow()
drCurrentRow("RowNumber") = i + 1
dtCurrentTable.Rows(i - 1)("ACCESLOTE") = ACCESLOTE.Text
dtCurrentTable.Rows(i - 1)("CODILOTE") = CODILOTE.Text
dtCurrentTable.Rows(i - 1)("NOMBLOTE") = NOMBLOTE.Text
dtCurrentTable.Rows(i - 1)("AREA") = AREA.Text
dtCurrentTable.Rows(i - 1)("TONELADAS") = TONELADAS.Text
dtCurrentTable.Rows(i - 1)("TOTAL_TC") = TOTAL_TC.Text
dtCurrentTable.Rows(i - 1)("EDAD_LOTE") = EDAD_LOTE.Text
dtCurrentTable.Rows(i - 1)("CODIVARIEDA") = CODIVARIEDA.Text
dtCurrentTable.Rows(i - 1)("NOM_VARIEDAD") = NOM_VARIEDAD.Text
dtCurrentTable.Rows(i - 1)("CODIUBICACION") = CODIUBICACION.Text
dtCurrentTable.Rows(i - 1)("CANTON") = CANTON.Text
dtCurrentTable.Rows(i - 1)("ZONA") = ZONA.Text
rowIndex += 1
Next
'grvStudentDetails.DataSource = dtCurrentTable;
'grvStudentDetails.DataBind();
ViewState("CurrentTable") = dtCurrentTable
End If
Else
Response.Write("ViewState is null")
End If
'SetPreviousData();
End Sub
de esta forma estado queriendo adicionar los datos del select
en los mensajes toma todos los datos del select pero al final solo me agrega el ultimo registro del select
Private Sub llenar()
Dim rowIndex As Integer = 0
Dim ACCESLOTE As New TextBox
Dim CODILOTE As New TextBox
Dim NOMBLOTE As New TextBox
Dim AREA As New TextBox
Dim TONELADAS As New TextBox
Dim TOTAL_TC As New TextBox
Dim EDAD_LOTE As New TextBox
Dim CODIVARIEDA As New TextBox
Dim NOM_VARIEDAD As New TextBox
Dim CODIUBICACION As New TextBox
Dim CANTON As New TextBox
Dim ZONA As New TextBox
Dim dtCurrentTable As New DataTable
If ViewState("CurrentTable") IsNot Nothing Then
dtCurrentTable = DirectCast(ViewState("CurrentTable"), DataTable)
Dim drCurrentRow As DataRow = Nothing
If dtCurrentTable.Rows.Count > 0 Then
For i As Integer = 1 To dtCurrentTable.Rows.Count
cn.Close()
cn.Open()
Dim Dadapter As SqlDataReader
Dim lotes = New SqlCommand("Sp_lotes_contrato", cn)
lotes.CommandType = CommandType.StoredProcedure
lotes.Parameters.AddWithValue("@CODIPROVEEDOR", txt_proveedor.Text + cod_socio)
lotes.Parameters.AddWithValue("@ANIOZAFRA", "2013/2014")
lotes.Parameters.AddWithValue("@ZONA", cb_zona.Text)
Dadapter = lotes.ExecuteReader
While Dadapter.Read
ACCESLOTE.Text = cb_zafra.Text + txt_proveedor.Text + cod_socio + Dadapter("CODILOTE").ToString
CODILOTE.Text = Dadapter("CODILOTE").ToString
MsgBox(Dadapter("CODILOTE").ToString)
NOMBLOTE.Text = Dadapter("NOMBLOTE").ToString
AREA.Text = Dadapter("AREA").ToString
TONELADAS.Text = String.Empty
TOTAL_TC.Text = String.Empty
EDAD_LOTE.Text = String.Empty
CODIVARIEDA.Text = Dadapter("CODIVARIEDA").ToString
NOM_VARIEDAD.Text = Dadapter("NOM_VARIEDAD").ToString
CODIUBICACION.Text = Dadapter("CODIUBICACION").ToString
CANTON.Text = Dadapter("CANTON").ToString
ZONA.Text = Dadapter("ZONA").ToString
drCurrentRow = dtCurrentTable.NewRow()
drCurrentRow("RowNumber") = i + 1
dtCurrentTable.Rows(i - 1)("ACCESLOTE") = ACCESLOTE.Text
dtCurrentTable.Rows(i - 1)("CODILOTE") = CODILOTE.Text
MsgBox(dtCurrentTable.Rows(i - 1)("CODILOTE") + "grid")
dtCurrentTable.Rows(i - 1)("NOMBLOTE") = NOMBLOTE.Text
MsgBox(dtCurrentTable.Rows(i - 1)("NOMBLOTE") + "grid")
dtCurrentTable.Rows(i - 1)("AREA") = AREA.Text
dtCurrentTable.Rows(i - 1)("TONELADAS") = TONELADAS.Text
dtCurrentTable.Rows(i - 1)("TOTAL_TC") = TOTAL_TC.Text
dtCurrentTable.Rows(i - 1)("EDAD_LOTE") = EDAD_LOTE.Text
dtCurrentTable.Rows(i - 1)("CODIVARIEDA") = CODIVARIEDA.Text
dtCurrentTable.Rows(i - 1)("NOM_VARIEDAD") = NOM_VARIEDAD.Text
dtCurrentTable.Rows(i - 1)("CODIUBICACION") = CODIUBICACION.Text
dtCurrentTable.Rows(i - 1)("CANTON") = CANTON.Text
dtCurrentTable.Rows(i - 1)("ZONA") = ZONA.Text
rowIndex += 1
End While
Dadapter.Close()
cn.Close()
Next
dtCurrentTable.Rows.Add(drCurrentRow)
ViewState("CurrentTable") = dtCurrentTable
End If
Else
Response.Write("ViewState is null")
End If
grvStudentDetails.DataSource = dtCurrentTable
grvStudentDetails.DataBind()
SetPreviousData()
End Sub