我有公司课程:
public class Company
{
public int CompanyId { get; set; }
public string Name { get; set; }
public string Description { get; set; }
//this retrieves all of the rows from database
public List<Company> RetrieveMany(Company entity)
{
var command = new SqlCommand { CommandText = "RetrieveCompanys", CommandType = CommandType.StoredProcedure };
command.Parameters.AddWithValue("@CompanyId", entity.CompanyId).Direction = ParameterDirection.Input;
command.Parameters.AddWithValue("@Name", entity.Name).Direction = ParameterDirection.Input;
DataTable dt = SqlHelper.GetData(command);
var items = new List<Company>();
if (dt.Rows.Count <= 0) return items;
foreach (DataRow row in dt.Rows)
{
var item = new Company();
item.CompanyId = row["CompanyId"].GetInt();
item.Name = row["Name"].GetString();
item.Description = row["Description"].GetString();
items.Add(item);
}
return items;
}
}
然后我使用objectdatasource在gridview中显示它。我使用了RetrieveMany方法。但是我的方法使用object作为参数。
通常我会这样做
Company compObj = new Company();
compObj.Name = NameTextBox.Text;
List<Company> comps = RetrieveMany(compObj);
但我不知道如何在ObjectDataSource中执行此操作。