0

I am creating a dynamic gridview and there is a part that I create a new event handler for edits. I also create a new method for doing the actual edit, but I need to pass it a datatable name as one of the parameters so i can rebind it. I can't figure out where to add that parameter:

        GridView gridData = new GridView();
        gridData.ID = "test";
        gridData.AutoGenerateEditButton = true;
        gridData.RowEditing += new GridViewEditEventHandler(grid_RowEditing);
        gridData.DataSource = tbl;
        gridData.DataBind();


protected void grid_RowEditing(object sender, GridViewEditEventArgs e)
    {
        ((GridView)sender).EditIndex = e.NewEditIndex;

        // I don't know how to pass the datasource name to this method, or if its even possible, because i won't ever know the actual gridview name because its dynamically created
        //((GridView)sender).DataSource =  ;
        ((GridView)sender).DataBind();
4

1 回答 1

0

如果您不需要解开事件处理程序,最简单的方法是使用 lambda 表达式

string dataSourceName = ...;
gridData.RowEditing += (sender, e) => grid_RowEditing(gridData, dataSourceName, e);
        gridData.DataSource = tbl;
        gridData.DataBind();


void grid_RowEditing(GridView gridData, string dataSourceName, GridViewEventArgs e) {
  ...
}
于 2013-08-26T17:09:48.707 回答