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

i used findcontrol method for finding gridview inside datalist...now 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()
        da.Fill(ds)
        GridView.DataSource = ds
        GridView.DataBind()
    End Sub
 
 
    Protected Sub DataList1_ItemDataBound(ByVal sender As Object, ByVal e As DataListItemEventArgs)
        Dim GridView1 As GridView = DirectCast(e.Item.FindControl("GridView1"), GridView)       
        BindGrid(GridView1)
    End Sub
 
<asp:DataList ID="DataList1"  runat="server"  OnItemDataBound="DataList1_ItemDataBound" Width="350px">
<ItemTemplate>
<asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None" AutoGenerateColumns="False"  Width="100%">
<Columns>
 <asp:TemplateField HeaderText="Pay Status">
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox1" Text="Not available" runat="server"></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label1"  runat="server"></asp:Label>
                    </ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ItemTemplate>
</asp:DataList>

Open in new window

LVL 18
Rajar AhmedConsultantAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Muhammad Ousama GhazaliSolution 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

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.