Search code examples
asp.nettemplatesgridviewtextbox

How to assign a value to texbox inside a gridview as itemTemplate


i have a gridview with a item Template with a textbox, so i create a datatable in memory and assign to the gridview, but the values doesn't assign to the textbox in the item template.

How i assign a value of my datatable to the control inside grid.

grdNotas.Rows(numero).Cells(2).FindControl("txtf1")

doesn't put the property of text.

Dim tbnotasAlumnos As New DataTable

    For Each fila As DataRow In tbAlumnnoCurso.Rows
        tbnotasAlumnos = conexion.consultaNotaMateriaAQP(tbAlumnnoCurso.Rows(numero)(0).ToString, ddlmaterias.SelectedValue, txtQuimestre.Text, txtparcial.Text)
        'fill the textboxes
        grdNotas.Rows(numero).Cells(2).FindControl("txtf1")
        numero = numero + 1
    Next

how i can do it?


Solution

  • You need not only to find the control, but also to cast it to specific type. That will give you an access to textbox's properties

    Dim txt As TextBox = CType(grdNotas.Rows(numero).Cells(2).FindControl("txtf1"), TextBox)
    txt.Text = "value"