We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

Adding OnRowDataBound to GridView in Code Behind

Steege
Steege asked
on
Medium Priority
1,553 Views
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
Comment
Watch Question

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)
        {
}

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
if you post some code i can show you where to put it

Commented:
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.

Regards,

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

Commented:
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
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.