views:

28

answers:

3

I need to use ASP.Net gridview and do operations like sorting paging and selecting checkboxes in my asp.net mvc content view. I dont what to do. I've written something like this:

<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>

but it is not shwoing me any thing in my rendered view. Am blank now. Please help

A: 

Although you can, I don' recommend using web controls in MVC. I would recommend utilizing a client side grid, or creating a HTML helper that achieves similar functionality.

If you want a FREE, elegant, and easy to implement grid for MVC you can check out Telerik. There grid is world class, IMO.

Dustin Laine
A: 

If you're not adversed to downloading ASP.NET MVC 3 Beta, there is a new control/helper called WebGrid which will do exactly what you want.

Writeup/usage on it here.

RPM1984
A: 

If you want something very powerful and even lightweight give a look to the grid Helper contained in the MVCContrib project at codeplex

Here you will find some good blog post on the argument

  1. ASP.NET MVC Paging/Sorting/Filtering using the MVCContrib Grid and Pager
  2. Looking for an MVC Grid Control? Try MVC Contrib!
  3. Use MVCContrib grid for editing
  4. Walkthrough: full example of using MvcContrib grid with jQuery datatable
Lorenzo