views:

330

answers:

1

I have created a gridview in code behind (as in its not physically present on the page). I want to know how to call it's rowdatabound event - as data is being bound to it. There happens to be a Gv.RowDataBound function, but how do I use it?

(I want the same functionality as what the asp:gridview control has for its onrowdatabind attribute...)


GridView Gv = new GridView(); Gv.AutoGenerateColumns = false;

BoundField one = new BoundField(); one.DataField = "one"; one.HeaderText = "One"; Gv.Columns.Add(one);

BoundField two = new BoundField(); one.DataField = "two"; one.HeaderText = "Two"; Gv.Columns.Add(two);

//dt is a datatable with some data

Gv.DataSource = (dt); Gv.DataBind();


+2  A: 

Set the eventhandler for the gridview using:

 Gv.RowDataBound += new GridViewRowEventHandler(Gv_RowDataBound);

Then create its own eventhandler

 void Gv_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        //Do whatever you want in here.
    }
madatanic
Thank you very much!
n0chi
You're welcome!
madatanic