我已经在后面的代码中创建了一个gridview(因为它实际上不在页面上显示)。我想知道如何将其称为rowdatabound事件-因为数据已绑定到该事件。碰巧有一个Gv.RowDataBound函数,但是我该如何使用呢?

(我想要与on:datagrid属性的asp:gridview控件具有相同的功能...)



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();

最佳答案

使用以下命令为gridview设置事件处理程序:

 Gv.RowDataBound += new GridViewRowEventHandler(Gv_RowDataBound);


然后创建自己的事件处理程序

 void Gv_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        //Do whatever you want in here.
    }

关于asp.net - Gridview RowDataBound事件背后的代码,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/2329626/

10-09 02:26