Click here to Skip to main content
15,886,075 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to show the result in gridview as like Datalist.
I achieved this by using Datalist as given below. I need to do that task in Gridview.
Help me. Give me an idea. One of my friend told, by using Partitioning we can do this task. How to do this task using Partition concept in sqlserver?

XML
<div>
        <asp:DataList ID="GV_Product" runat="server" CellSpacing="3" CellPadding="2" RepeatColumns="2" Width="200px" Height="200px">

       <ItemTemplate>

            <table>

            <tr>
                <td class="auto-style2" colspan="3" style="text-align: center; font-size: large">Product</td>
            </tr>
                <tr>
                    <td class="auto-style1" colspan="3" style="text-align: center; font-size:small" >
                        <asp:CheckBox ID="chk" runat="server" /></td>
                </tr>
            <tr>
                <td>Product Name </td>
                <td>
                    <asp:Label ID="lblPrdName" runat="server" Text='<%#Bind("P_Name") %>'></asp:Label></td>
                <td>&nbsp;</td>
            </tr>
            <tr>
                <td>Product Price </td>
                <td>
                    <asp:Label ID="lblPrdPrice" runat="server" Text='<%#Bind("P_Price") %>'></asp:Label></td>
            </tr>
            <tr>
                <td>Quantity               </td>
                <td>
                    <asp:TextBox ID="txt_Qty" runat="server" Enabled="false" AutoPostBack="true" ></asp:TextBox></td>
                <asp:RegularExpressionValidator ID="REV_Qty" runat="server" ErrorMessage="Provide the Qty in Correct Format" ControlToValidate="txt_Qty" ValidationExpression="^[0-9]+$"></asp:RegularExpressionValidator>

                <td>Total Quantity
                    <asp:Label ID="lblTotQty" runat="server" Text=""></asp:Label></td>
            </tr>
            <tr>
                <td>Amount</td>
                <td>
                    <asp:Label ID="lblTotal" runat="server" Text=""></asp:Label></td>
                <td>Total Amount
                    <asp:Label ID="lblTotAmt" runat="server" Text=""></asp:Label>
                </td>
            </tr>


                </table>
           </ItemTemplate>
             </asp:DataList>


    </div>
Posted
Updated 3-Jan-15 9:58am
v2
Comments
Suvendu Shekhar Giri 3-Jan-15 16:00pm    
What is the problem in this code? What kind of result you want and how current result differs from that?
ZurdoDev 3-Jan-15 16:24pm    
It looks like all you have in your datalist is a table which is what the gridview will do. Where are you stuck?

If it works, why change it?
deepakdynamite 4-Jan-15 23:07pm    
Can you show sample data format you are looking for ?

1 solution

Question is not Clear.
Any Way Try this!..

C#
<asp:gridview id="GridView1" runat="server" showfooter="True" xmlns:asp="#unknown">
            AutoGenerateColumns="False">
<columns>
 <asp:templatefield>
<table>
 
            <tr>
                <td class="auto-style2" colspan="3" style="text-align: center; font-size: large">Product</td>
            </tr>
                <tr>
                    <td class="auto-style1" colspan="3" style="text-align: center; font-size:small">
                        <asp:checkbox id="chk" runat="server" /></td>
                </tr>
            <tr>
                <td>Product Name </td>
                <td>
                    <asp:label id="lblPrdName" runat="server" text="<%#Bind("P_Name") %>"></asp:label></td>
                <td> </td>
            </tr>
            <tr>
                <td>Product Price </td>
                <td>
                    <asp:label id="lblPrdPrice" runat="server" text="<%#Bind("P_Price") %>"></asp:label></td>
            </tr>
            <tr>
                <td>Quantity               </td>
                <td>
                    <asp:textbox id="txt_Qty" runat="server" enabled="false" autopostback="true"></asp:textbox></td>
                <asp:regularexpressionvalidator id="REV_Qty" runat="server" errormessage="Provide the Qty in Correct Format" controltovalidate="txt_Qty" validationexpression="^[0-9]+$"></asp:regularexpressionvalidator>
 
                <td>Total Quantity
                    <asp:label id="lblTotQty" runat="server" text=""></asp:label></td>
            </tr>
            <tr>
                <td>Amount</td>
                <td>
                    <asp:label id="lblTotal" runat="server" text=""></asp:label></td>
                <td>Total Amount
                    <asp:label id="lblTotAmt" runat="server" text=""></asp:label>
                </td>
            </tr>
 

                </table>

</asp:templatefield>
</columns>
</asp:gridview>


then bind your dataset into Gridview

C#
GridView1.DataSource = ds;
GridView1.DataBind();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900