1

I have a question regarding adding new rows to a datatable which is bound to a gridview in the RowDataBound event. Do you have any idea how can I do that?

  • Why would you want to do that? `RowDataBound` is triggered for **every** row in the grid which is bound to a `DataTable`(i guess). So you want to change the datasource of the `GridView` after it was already databound? – Tim Schmelter May 21 '14 at 14:31

1 Answers1

0

I would use the OnDataBound event on the gridview. That way after your rowdatabound is complete and your grid is data bound this event will be raised.

<asp:gridview id="Gridview1" runat="server" ondatabound="Gridview_DataBound" 
...
</asp:gridview>

private void GridView_DataBound(EventArgs e)
{

if(e.Row.RowType == DataControlRowType.DataRow)
{
  //add row to here

}
}
Matthew Wong
  • 274
  • 1
  • 7