Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET Gridview bind
My frontend code:
<asp:GridView ID="Gen_Lic_Grid" runat="server" AllowPaging="True" AutoGenerateColumns="False" CellPadding="4" DataKeyNames="Lic_No" ForeColor="#333333" GridLines="None" OnPageIndexChanging="gridView_PageIndexChanging" PageSize="15" Width="110%">
   <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
    <Columns>
 <asp:BoundField DataField="Lic_No" HeaderText="License No" ReadOnly="True" SortExpression="Lic_No" />
 <asp:BoundField DataField="UserID" HeaderText="User ID" SortExpression="UserID" />
 <asp:BoundField DataField="Org" HeaderText="Organization"
                                    SortExpression="Org" />
 <asp:BoundField DataField="UserName" HeaderText="User Name" SortExpression="UserName" />
 <asp:BoundField DataField="SolType" HeaderText="Solution Type" SortExpression="SolType" />
<asp:BoundField DataField="Version" HeaderText="Version" SortExpression="Version" />
<asp:BoundField DataField="Lic_Type" HeaderText="License Type" SortExpression="Lic_Type" />
<asp:BoundField DataField="Meap_Supp" HeaderText="Meap Support" SortExpression="Meap_Supp" />
<asp:BoundField DataField="Lic_From" HeaderText="License From" SortExpression="Lic_From" />
<asp:BoundField DataField="Lic_To" HeaderText="License To" SortExpression="Lic_To" />
<asp:BoundField DataField="Supp_From" HeaderText="Support From" SortExpression="Supp_From" />
<asp:BoundField DataField="Supp_To" HeaderText="Support To" SortExpression="Supp_To" />
<asp:BoundField DataField="Max_User" HeaderText="Max Users" SortExpression="Max_User" />
<asp:BoundField DataField="Max_Mach" HeaderText="Max Machines" SortExpression="Max_Mach" />
<asp:BoundField DataField="Mach_IP" HeaderText="Machine IP" SortExpression="Mach_IP" />
<asp:BoundField DataField="Mach_MAC" HeaderText="Machine MAC" SortExpression="Mach_MAC" />
</Columns>
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#999999" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>
 
My backend code:
 
protected void gridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
    Gen_Lic_Grid.PageIndex = e.NewPageIndex;
    Gen_Lic_Grid.DataSource = //<-- what should be written here?
    Gen_Lic_Grid.DataBind();
}
 
My gridview is blank on page changing and i'm not getting what to write in the datasource. Can someone guide me?
Posted 18-Dec-12 0:27am
Comments
Avinash_Pathak at 18-Dec-12 5:31am
   
protected void gridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
Gen_Lic_Grid.PageIndex = e.NewPageIndex;
Gen_Lic_Grid.DataSource = //<-- what should be written here?
Gen_Lic_Grid.DataBind();
}
before this code you must bind your gridview. and it must be in separate function and call that function in this code block.,
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi,
 
DataSet ds = new DataSet(); which contain database data
protected void gridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
    Gen_Lic_Grid.PageIndex = e.NewPageIndex;
//add dataset
    Gen_Lic_Grid.DataSource =ds;
    Gen_Lic_Grid.DataBind();
}
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Gen_Lic_Grid.PageIndex = e.NewPageIndex;
 
//write here the code for filling the datatable or what you have written to fill your gridview
   Gen_Lic_Grid.DataSource = dt
   Gen_Lic_Grid.DataBind();
 

Thanks
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Hello,
 
please add datatable into session during Gen_Lic_Grid loading on page_load event and then use it as below :
 
protected void Gen_Lic_Grid_PageIndexChanging(object sender, GridViewPageEventArgs e)
       {
          Gen_Lic_Grid.PageIndex = e.NewPageIndex; 
          Gen_Lic_Grid.DataSource = Session["LicList"];         
          Gen_Lic_Grid.DataBind();
 
       }
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 277
1 Maciej Los 210
2 BillWoodruff 205
3 Jochen Arndt 180
4 DamithSL 165
0 OriginalGriff 5,130
1 DamithSL 4,157
2 Maciej Los 3,670
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,821


Advertise | Privacy | Mobile
Web03 | 2.8.141216.1 | Last Updated 18 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100