asp.net mvc2中的Gridview

时间:2010-10-30 21:44:16

标签: asp.net-mvc gridview asp.net-mvc-2 servercontrols

我需要使用ASP.Net gridview并执行操作,例如在我的asp.net mvc内容视图中对分页进行排序和选择复选框。我不该做什么。我写过这样的话:

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <table runat="server" id="tbldealData" style="width: auto; height: auto">
                <tr>
                    <td>
                    <cc1:ExtendedGridView ID="ExtendedGridView1" runat="server" AutoGenerateColumns="false"
                            AllowFiltering="true">
                            <Columns>
                            <asp:TemplateField HeaderText="Wait For Payment From SAP">
                                <EditItemTemplate>
                                    <asp:CheckBox ID="chkWaitForSAP" runat="server" />
                                </EditItemTemplate>
                                <ItemTemplate>
                                    <asp:CheckBox runat="server" ID="chkWaitForSAP" Checked="true" AutoPostBack="true"/>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Deal Number" SortExpression="DealNumber">
                                <EditItemTemplate>
                                    <asp:TextBox ID="TextBox2" runat="server" Text='<%= Html.LabelFor(model => model.DealNumber) %>'></asp:TextBox>
                                </EditItemTemplate>
                                <ItemTemplate>
                                    <asp:Label ID="Label2" runat="server" Text='<%= Html.LabelFor(model => model.DealNumber) %>'></asp:Label>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Cost Number" SortExpression="CostNumber">
                                <EditItemTemplate>
                                    <asp:TextBox ID="TextBox5" runat="server" Text='<%= Html.LabelFor(model => model.CostNumber) %>'></asp:TextBox>
                                </EditItemTemplate>
                                <ItemTemplate>
                                    <asp:Label ID="Label5" runat="server" Text='<%= Html.LabelFor(model => model.CostNumber) %>'></asp:Label>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Source System" SortExpression="SourceSystemName">
                                <EditItemTemplate>
                                    <asp:TextBox ID="TextBox6" runat="server" Text='<%= Html.LabelFor(model => model.SourceSystemName) %>'></asp:TextBox>
                                </EditItemTemplate>
                                <ItemTemplate>
                                    <asp:Label ID="Label6" runat="server" Text='<%= Html.LabelFor(model => model.SourceSystemName) %>'></asp:Label>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="CounterParty" SortExpression="CounterpartyName">
                                <EditItemTemplate>
                                    <asp:TextBox ID="TextBox7" runat="server" Text='<%= Html.LabelFor(model => model.CounterpartyName) %>'></asp:TextBox>
                                </EditItemTemplate>
                                <ItemTemplate>
                                    <asp:Label ID="Label7" runat="server" Text='<%= Html.LabelFor(model => model.CounterpartyName) %>'></asp:Label>
                                </ItemTemplate>
                            </asp:TemplateField>
                     </Columns>
                        <AlternatingRowStyle BackColor="#E5E5E5" />
                        <PagerStyle ForeColor="Blue" />
                        <PagerTemplate>
                            <asp:LinkButton CommandName="Page" CommandArgument="First" ID="LinkButton1" runat="server"
                                Style="color: Blue">  
                                « First</asp:LinkButton>
                            <asp:LinkButton CommandName="Page" CommandArgument="Prev" ID="LinkButton2" runat="server"
                                Style="color: Blue"> < Prev</asp:LinkButton>
                            [<%= ExtendedGridView1.PageIndex * ExtendedGridView1.PageSize%>-<%= ExtendedGridView1.PageIndex * ExtendedGridView1.PageSize + ExtendedGridView1.PageSize - 1%>]
                            <asp:LinkButton CommandName="Page" CommandArgument="Next" ID="LinkButton3" runat="server"
                                Style="color: Blue">  
                                Next ></asp:LinkButton>
                            <asp:LinkButton CommandName="Page" CommandArgument="Last" ID="LinkButton4" runat="server"
                                Style="color: Blue">  
                                Last »</asp:LinkButton>
                        </PagerTemplate>
                        </cc1:ExtendedGridView>
                         </td>
                </tr>
                <tr>
                    <td>
                        <input type="submit" value="Save" />
                        <input type="reset" value="Cancel" />
                    </td>
                </tr>
            </table>
        </ContentTemplate>
    </asp:UpdatePanel>
</asp:Content>

但是在我渲染的视图中它并没有让我感到震惊。现在空白了。请帮忙

3 个答案:

答案 0 :(得分:0)

虽然你可以,但我不建议在MVC中使用网页控件。我建议使用客户端网格,或创建实现类似功能的HTML帮助程序。

如果您想为MVC提供免费,优雅且易于实现的网格,您可以查看Telerik。网格是世界级的,IMO。

答案 1 :(得分:0)

如果您不习惯下载ASP.NET MVC 3 Beta,则会有一个名为 WebGrid 的新控件/帮助器,它可以完全按照您的需要进行操作。

上面的{/ 3}}。

答案 2 :(得分:0)