Click here to Skip to main content
15,904,638 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
on button click value show in gride view but i allow pageing only 10 value show at a time but when i click on next the data do not show in gride view in asp.net
i use these code

C#
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
   {
       try
       {
           GridView1.PageIndex = e.NewPageIndex;
           GridView1.DataSource = ds;
           GridView1.DataBind();
       }
       catch (Exception ex)
       {
           Response.Write(ex.Message);
       }

   }



ASP.NET
<asp:GridView ID="GridView1" runat="server"  
  AutoGenerateColumns="False"  Height="50px" 
            CellPadding="4" ForeColor="Black" GridLines="None" Width="588px"  
                    ShowHeader="False"  Font-Bold="False" Font-Size="Small" Font-Strikeout="False" 
            onselectedindexchanged="GridView1_SelectedIndexChanged" AllowPaging="True" 
                    onpageindexchanged="GridView1_PageIndexChanged" 
                    onpageindexchanging="GridView1_PageIndexChanging">
                    <rowstyle backcolor="#EFF3FB" />
            <columns>
         
                <asp:TemplateField>
                
                    <itemtemplate>
                    <table>
                     <tr>
                        <td rowspan="4">
                            <asp:Image ID="Image1" runat="server"  
                                Width="75px" ImageUrl="images/Image/image0.png" /> </td>
                        <td>
                            <asp:Label ID="Label1" runat="server" Text='<%# Bind("Name") %>'></td>
                        <td rowspan="4">Address:-
                            <asp:Label ID="Label2" runat="server" Text='<%# Bind("Address") %>'></td>
                    </tr>
                    <tr>
                        <td>Contact:-
                             <asp:Label ID="Label3" runat="server" Text='<%# Bind("Contact") %>'></td>
                    </tr>
                    <tr>
                        <td>Class:-
                             <asp:Label ID="Label4" runat="server" Text='<%# Bind("ClassName") %>'></td>
                    </tr>
                    <tr>
                        <td>City:-
                             <asp:Label ID="Label5" runat="server" Text='<%# Bind("City") %>'></td>
                    </tr>
                       
                       </table>
                    </itemtemplate>
                
               
            </columns>
            <footerstyle backcolor="#507CD1" font-bold="True" forecolor="White" />
            <pagerstyle backcolor="#2461BF" forecolor="White">
                HorizontalAlign="Center" />
            <SelectedRowStyle BackColor="#D1DDF1" ForeColor="#333333" Font-Bold="True" />
            <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                    <editrowstyle backcolor="#2461BF" />
            <alternatingrowstyle backcolor="White" />



Paging" gride view does not work. It shows the first 5 rows, but does not show the number of paging in asp.net but the code is not working in a proper way
Posted
Updated 8-Nov-12 0:17am
v3
Comments
jim lahey 8-Nov-12 5:56am    
Please show the code for the GridView also
M@anish 8-Nov-12 6:12am    
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False" Height="50px"
CellPadding="4" ForeColor="Black" GridLines="None" Width="588px"
ShowHeader="False" Font-Bold="False" Font-Size="Small" Font-Strikeout="False"
onselectedindexchanged="GridView1_SelectedIndexChanged" AllowPaging="True"
onpageindexchanged="GridView1_PageIndexChanged"
onpageindexchanging="GridView1_PageIndexChanging">
<rowstyle backcolor="#EFF3FB">
<columns>

<asp:TemplateField>

<itemtemplate>
<table>
<tr>
<td rowspan="4">
<asp:Image ID="Image1" runat="server"
Width="75px" ImageUrl="images/Image/image0.png" /> </td>
<td>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("Name") %>'></td>
<td rowspan="4">Address:-
<asp:Label ID="Label2" runat="server" Text='<%# Bind("Address") %>'></td>
</tr>
<tr>
<td>Contact:-
<asp:Label ID="Label3" runat="server" Text='<%# Bind("Contact") %>'></td>
</tr>
<tr>
<td>Class:-
<asp:Label ID="Label4" runat="server" Text='<%# Bind("ClassName") %>'></td>
</tr>
<tr>
<td>City:-
<asp:Label ID="Label5" runat="server" Text='<%# Bind("City") %>'></td>
</tr>

</table>




<footerstyle backcolor="#507CD1" font-bold="True" forecolor="White">
<PagerStyle BackColor="#2461BF" ForeColor="White"
HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#D1DDF1" ForeColor="#333333" Font-Bold="True" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<editrowstyle backcolor="#2461BF">
<alternatingrowstyle backcolor="White">

1 solution

Don't write
C#
GridView1.DataSource = ds;

in pageindex changing only write
C#
GridView1.PageIndex = e.NewPageIndex;
                     GridView1.DataBind();


in your code....
 
Share this answer
 
Comments
M@anish 8-Nov-12 6:29am    
but sir it give only first ten row of table on every page
Devang Vaja 8-Nov-12 6:33am    
have You seen dataset? how many rows it have?

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