Accessing dynamically added control from GridView Footer row

Posted by harold-sota on Stack Overflow See other posts from Stack Overflow or by harold-sota
Published on 2010-05-11T14:48:31Z Indexed on 2010/05/11 20:24 UTC
Read the original article Hit count: 377

Filed under:
|
|

Hi, I have GridView control in my asp.net page with auto generated fields there is only footer template is present under asp:TemplateField.

I can bind this gridview with any of databae table as depend on user selection. Now want to add new record in database so I have added text boxes on footer template cells at runtime depend on number of columns on table. But when I accessing these text boxes from footer template on gridview_RowCommand event its not retriving textbox control.

this is the code

   SGridView.ShowFooter = True
    For i As Integer = 0 To ctrList.Count
        Dim ctr As Control = CType(ctrList.Item(i), Control)
        SGridView.FooterRow.Cells(i + 1).Controls.Add(ctr)
    Next

the ctrList contain Controls textBox, checkbox dropdowlist ect.

there is all ok

but when i wont to get the text or value or checked value of controls i cant cast the controls in rowcommand event

Here is the code:

Protected Sub SGridView_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles SGridView.RowCommand

    If e.CommandName = "Add" Then

        Dim ctrList As ControlCollection = SGridView.FooterRow.Controls

        For Each ctr As Control In ctrList

            If TypeOf ctr Is TextBox Then
                Dim name As TextBox = CType(ctr, TextBox)
                Dim val As String = name.Text
            End If


        Next

    End If

this excample is for the textBox control.

Plese suggest me how can I get footer control textboxes. So that I can save data in database.

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about gridview