Click here to Skip to main content
15,899,937 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I created new ASP GridView and customize it without select DataSource.
and create SqlDataSource (define connectionstring, parameters) .
then assign GridView DataSource programmatically in my .CS File .. and it's work very well.

But when moving between GridView Pages the gridview disappear and do nothing...

XML
<asp:GridView ID="gridAdminRoles" runat="server"
DataKeyNames="RoleID" CellPadding="4"
ForeColor="#333333" GridLines="None" AutoGenerateColumns="False"
ShowFooter="True" Width="100%" AllowPaging="True" PageSize="7"
onpageindexchanging="gridAdminRoles_PageIndexChanging" >

<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />

<Columns>
<asp:BoundField DataField="RoleID" HeaderText="RoleID" />
<asp:BoundField DataField="RoleName" HeaderText="Name" />
<asp:BoundField DataField="BranchName" HeaderText="Branch" />


</Columns>
</asp:GridView>


XML
<asp:SqlDataSource ID="RolesDataSource" runat="server"
                 ConnectionString="<%$ ConnectionStrings:ShareCon %>"
                 SelectCommand="GetBranchesRoles"
                 SelectCommandType="StoredProcedure" >
                </asp:SqlDataSource>


In Page_Load() Event...
C#
gridAdminRoles.DataSource = RolesDataSource;
gridAdminRoles.DataBind();


All of this working properly |^|

Now i want moving between pages of gridview So i wrote this code into PageIndexChanging but the GridView Disappear ...

C#
protected void gridAdminRoles_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
    gridAdminRoles.PageIndex = e.NewPageIndex;
    gridAdminRoles.DataBind();
}
Posted

1 solution

C#
protected void gridAdminRoles_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
    gridAdminRoles.PageIndex = e.NewPageIndex;

    //Set Datasource
    gridAdminRoles.DataSource = RolesDataSource;

    gridAdminRoles.DataBind();
}.
 
Share this answer
 
Comments
SerpentKiss2010 19-Apr-11 6:25am    
Thank you sir,
this also will be succeeded
protected void gridAdminRoles_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
gridAdminRoles.PageIndex = e.NewPageIndex;

//Set Datasource
gridAdminRoles.DataSourceID = gridAdminRoles.DataSourceID;

gridAdminRoles.DataBind();
}.

because gridview depending on three datasources .... ThankYou

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