How to work in asp.net with rowdata bound with grid view


How to work in asp.net grid view Rowdatabound:



In this Post i want describe about few tips and tricks in rowdatabound event which is available in asp.net gridview control and these tips will provide the solution for all possible requirements when working with rowdatabound event in gridview control.

Gridview control:

Gridview control is most common control in all asp.net applications to display the data and it’s very powerful control and lot of built in features. In this article, i will explore some tips and tricks in rowdatabound event in gridvew control, Actually RowDatabound event will occur when data row is bound to the control in the gridview control.


RowDatabound Event of Gridview Control:


First we take an ASP.NET GRID Control
<asp:GridView ID="GRDSample" runat="server" AutoGenerateColumns="false" OnRowDataBound="GRDSample_RowDataBound">
            <Columns>
                <asp:TemplateField HeaderText="Userprofile">
                    <ItemTemplate>
                     
                        <asp:Label ID="lblText" runat="server" Text='<%# Eval("catgryName") %>'
></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>

In this we take  lable control in grid control.

Know we want to create event by C# code on .aspx.cs page

protected void GRDSample_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            DataRowView drview = e.Row.DataItem as DataRowView;
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                Label lblText       = e.Row.FindControl("lblText") as Label;
}
}
}


We can able to do formatting a specific row in a gridview based on some conditions. For this view next post.RowDataBound event in a GridView to highlight the rows by condition


Grid view Related Other Post :


Comments

Popular posts from this blog