parameters - 如何在asp .net 4.5中将参数传递给gridView的SelectMethod

标签 parameters asp.net-4.5

问题:如何将参数传递给asp .net 4.5中gridView的SelectMethod

描述:

我正在使用 asp .net 4.5 并使用(强类型模型绑定(bind))SelectMethod 将数据绑定(bind)到 gridView。

SelecteMethod="BindGrid" BindGrid 是用户定义的函数。

但是在绑定(bind)时我想将 GridRow 作为参数传递给函数 BindGrid。

那么有什么方法可以将参数传递给 selectMethod 来进行强类型模型绑定(bind)吗?

最佳答案

有一个great example说明如何使用控件“过滤”从“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();
    }

根据您的具体情况,此方法有多种变体。希望这有帮助!

关于parameters - 如何在asp .net 4.5中将参数传递给gridView的SelectMethod,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15779358/

相关文章:

java - JMH 静态最终字段作为参数

jQuery - 有没有办法重用参数来减少代码重复?

c# - 预加载 Azure 网站以增加首次访问加载时间

c# - 完全非阻塞 HTTP 请求 C# ASP.NET

c# - 在 IIS 7.5 中托管时的自定义 WCF 登录页面

spring-mvc - Spring MVC Redirect 显示 applicationinfo.properties 中的参数如何删除它们

amazon-web-services - 使用替换的顶级参数的类型

c# - 元素不存在时返回空字符串

javascript - 如何在 JavaScript 中获取字符串表示的参数数组

c# - RC 更新后的 ASP.NET WebAPI XML 序列化