通过对象数据源将网格键传递给业务类

时间:2011-01-21 20:16:52

标签: asp.net gridview objectdatasource

在ASP.NET中,Webforms有一个ASP.NET GridView通过对象数据源连接到C#类

我在网格中将ID设置为DataKeyName。在更新网格时如何将其传递给C#类?

2 个答案:

答案 0 :(得分:0)

可以在网格行更新事件

中获取当前行的网格数据键名称
  protected void gvSearchResults_RowUpdating(object sender, GridViewUpdateEventArgs e)
  {
    //get handle on current grid row
    DataKey keys = gvSearchResults.DataKeys[e.RowIndex];
   customerId= GeneralUtils.GetIntegerKeyValue(keys, "customerID");
  }

然后使用对象数据源更新事件

将其传递给C#类
 protected void odsHauliers_Updating(object sender, ObjectDataSourceMethodEventArgs e)
  {

    e.InputParameters["customerID"] = this.customerID;
  }

答案 1 :(得分:0)

实际上,数据键名由数据网格自动传递给对象数据源。

相关问题