asp.net 4.5在formview中绑定用户控件的模型

时间:2012-10-10 12:03:36

标签: model-binding formview asp.net-4.5

如何在formview中绑定usercontrol。如果我不使用usercontrol everythings工作正常,当我移动到usercontrol模型绑定中的输入不起作用。

1 个答案:

答案 0 :(得分:0)

你可以尝试将此作为ascx控件吗?

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="MyGridView1.ascx.cs" Inherits="MyGridView1" %>

<asp:GridView ID="MyGridView" runat="server" SelectMethod="GetCustomers" PagerSettings-Position="Bottom"
    AllowSorting="true" AllowPaging="true" PageSize="5" PagerSettings-Visible="true"
    PagerSettings-Mode="NumericFirstLast" AutoGenerateDeleteButton="true" Caption="MyGridViewControl"
    CellPadding="4" GridLines="None" ForeColor="#333333">
    <AlternatingRowStyle BackColor="White"></AlternatingRowStyle>
</asp:GridView>
<asp:ValidationSummary ID="ValidationSummary1" runat="server" ShowModelStateErrors="true"
    ShowValidationErrors="true" />`


并在控件后面的代码中添加SelectMethod。注册<%@ Register Src="~/MyGridView1.ascx" TagPrefix="uc1" TagName="MyGridView1" %>并将此控件用作<uc1:mygridview1 runat="server" id="MyGridView1" />