问题:在asp SelectMethod 4.5中如何将参数传递给SelectMethod of gridView
描述:
我使用asp .net 4.5和(强类型模型绑定) SelectMethod将数据绑定到gridView。
SelecteMethod="BindGrid" BindGrid是用户定义的函数。
但是在绑定时,我希望将GridRow作为参数传递给函数BindGrid.。
那么,是否有任何方法将参数传递给selectMethod以进行强类型的模型绑定?
发布于 2015-03-26 21:29:12
有一个伟大的例子说明如何使用控件“过滤”从"SelectMethod“返回的数据。例如,如果您要在下拉列表中更改选定内容上的数据。你会像这样设置标记..。
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="ddlEmployee" AutoPostBack="true" runat="server">
<asp:ListItem Text="1"></asp:ListItem>
<asp:ListItem Text="2"></asp:ListItem>
</asp:DropDownList>
</div>
<div>
<asp:GridView ID="grdEmployee" runat="server" SelectMethod="GetEmployees" ItemType="WebApplication2.Employee">
</asp:GridView>
</div>
</form>然后这个方法会看起来像这样接收一个参数..。
public List<Employee> GetEmployees([Control]int? ddlEmployee)
{
List<Employee> employeeList = new List<Employee>();
for (int i = 1; i <= 5; i++)
{
employeeList.Add(new Employee {
EmployeeId=i,
FirstName=string.Format("First{0}",i),
LastName=string.Format("Last{0}",i)
});
}
return employeeList.Where(e=>e.EmployeeId==ddlEmployee).ToList();
}有不同的变化,这可以工作,根据您的情况。希望这能有所帮助!
发布于 2020-06-23 06:00:51
发布于 2021-03-19 15:09:40
public IQueryable<Category> GetCategories([Control("controlId")] int? minProductsCount)
{
var query = this.db.Categories.Include(c => c.Products);
if (minProductsCount.HasValue)
{
query = query.Where(c => c.Products.Count >= minProductsCount);
}
return query;
}https://stackoverflow.com/questions/15779358
复制相似问题