Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get textbox value from datagrid problems

Status
Not open for further replies.

stfarm

Programmer
May 31, 2001
179
CA
Hi, could you please tell me what is wrong with this piece of code.
I have a DataGrid, and I would like to know the value of a textbox field, and it never returns anything.

Code:
 Dim item As DataGridItem
        If Not IsPostBack Then

            For Each item In DataGrid1.Items
                Dim tb As TextBox = CType(item.FindControl("txtInput"), TextBox)
                ListBox1.Items.Add(tb.Text)
            Next
        End If

Thank you.
Steve
 
Where are you calling this code? In the Page Load Event? I would try looking at the ItemDataBound Event instead.

Code:
    Private Sub dg_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dg.ItemDataBound
        If e.Item.ItemType <> ListItemType.Header And e.Item.ItemType <> ListItemType.Footer Then
            Dim strIn As String = e.Item.Cells(5).Text
            ListBox1.Items.Add(strIn)            
        End If
    End Sub

Hope this helps.

Hope everyone is having a great day!

Thanks - Jennifer
 
Thank you, but I need to call it from a button click to update a stored proc. Any other ideas?

Thank you for your help,

Steve
 
Ok, I guess I need more information. Is this when you update the row or are you changing the whole grid and trying to update all rows?

Hope everyone is having a great day!

Thanks - Jennifer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top