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.
精彩评论