Adding OnRowDataBound to GridView in Code Behind

Posted on 2009-02-10
Last Modified: 2013-12-17
I am dynamically creating a gridview in the code behind and need to add a OnRowDataBound event, how do i do this??? i cant seem to find any example on this
Question by:Steege
    LVL 16

    Accepted Solution

    when you create the new datagrid add this
    gvCurrent.RowDataBound += new GridViewRowEventHandler(gvCurrent_RowDataBound);

    then add a  event handler like this

    protected void gvCurrent_RowDataBound(object sender, GridViewRowEventArgs e)
    LVL 16

    Expert Comment

    if you post some code i can show you where to put it
    LVL 6

    Expert Comment

    Hello Steege,

    as burakiewicz told you, if you post some code we can help you more,
    i've attached a sample code for the datarowbound below. hope it helps.


    Mohamed Allam
    Senior Application Developer
    public void grid_RowDataBound(object sender,GridViewRowEventArgs e)
         if (e.Row.RowType == DataControlRowType.DataRow)
             TextBox t = (TextBox) e.Row.FindControl("TextBox85");
             t.Text = System.DateTime.Now.ToShortDateString();

    Open in new window


    Author Closing Comment

    Do i feel stupid so i  was going to post my code then i realized i was creating a datagrid not a grid view...dooh! now i just need to figure out how to add the columns to it. Thanks for the help

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
    Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now