开发者

Pass Key of Grid to Business Class via Object Data Source

开发者 https://www.devze.com 2023-02-06 05:51 出处:网络
In ASP.NET Webforms have an ASP.NET GridView connected to a C# class via an object data source I have an ID set up as a DataKeyName in the grid. How do I pass this to the C# 开发者_Go百科class when I

In ASP.NET Webforms have an ASP.NET GridView connected to a C# class via an object data source

I have an ID set up as a DataKeyName in the grid. How do I pass this to the C# 开发者_Go百科class when I update the grid?


Can pick up the grids data key name for the current row in the grids row updating event

  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");
  }

Then pass it to C# class using object data sources updating event

 protected void odsHauliers_Updating(object sender, ObjectDataSourceMethodEventArgs e)
  {

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


Actually data key names are passed automatically by the datagrid to the object data source.

0

精彩评论

暂无评论...
验证码 换一张
取 消