how to write rowdatabound event for a grdview which is inside datalist template ...??

i used findcontrol method for finding gridview inside how to write rowdatabound for dat gridview..and also to find Label1 in that gridview .....??
Private Sub BindGrid(ByVal GridView As GridView, ByVal trid As String, ByVal trainername As Label)
        Dim con As SqlConnection
        con = New SqlConnection(ConfigurationSettings.AppSettings("con"))
        Dim Sql1 As String = "Select * from tbl1"
        Dim da As New SqlDataAdapter(Sql1, con)
        Dim ds As New DataSet()
        GridView.DataSource = ds
    End Sub
    Protected Sub DataList1_ItemDataBound(ByVal sender As Object, ByVal e As DataListItemEventArgs)
        Dim GridView1 As GridView = DirectCast(e.Item.FindControl("GridView1"), GridView)       
    End Sub
<asp:DataList ID="DataList1"  runat="server"  OnItemDataBound="DataList1_ItemDataBound" Width="350px">
<asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None" AutoGenerateColumns="False"  Width="100%">
 <asp:TemplateField HeaderText="Pay Status">
                        <asp:TextBox ID="TextBox1" Text="Not available" runat="server"></asp:TextBox>
                        <asp:Label ID="Label1"  runat="server"></asp:Label>

Open in new window

LVL 18
Rajar AhmedConsultantAsked:
Who is Participating?
Muhammad Ousama GhazaliConnect With a Mentor Solution Analyst & ArchitectCommented:
Check the following sample code and try using AddHandler statement after line 15.
'Use this line to hook GridView for RowDataBound event, use similar technique for other events such as RowEditing, RowCommand, RowUpdating, etc
AddHandler GridView1.RowDataBound, AddressOf GridView1_RowDataBound
Private Sub GridView_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) 
  'Use this to get handle of GridView
  Dim GridView1 As GridView = CType(sender, GridView)
  'Code here as per your requirements
End Sub

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.