welcome Netizen

Share Your Knowledge.It is a way to achieve immortality

Friday, June 17, 2011

RowDataBound Event in Gridview using ASP.Net

In Previous article i have written about how to insert,update and edit datagridview..

Then i found usage of Rowdatabound its very interesting in grid view, Normally when binding a value in grid view we are using templatefield but another one usage was there i.e. Bound field, If we use Boundfield we can change the data at the time of binding in grid view .
For an example in an grid view had one column email .so when binding an email address you have change the column link. For this you have to use rowdatabound filed.

This Coding add in client side…
<asp:BoundField HeaderText ="Email" DataField ="email" />

Here datafield as a field databasename.
Then you have add the below coding in rowdatabound in gridview event properties.

Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
        'End If

        If e.Row.RowType = DataControlRowType.DataRow Then
            Dim email As String = e.Row.Cells(9).Text
            e.Row.Cells(9).Text = "<a href='mailto:" & email & "'>" & email & "</a>"
        End If
    End Sub
I hope this one helpful to you….


Post a Comment