1

I'm using gridview without datasource. On PageIndexChanging the page is blank.

My backend code is:

protected void gridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
    Gen_Lic_Grid.PageIndex = e.NewPageIndex;
    Gen_Lic_Grid.DataBind();
}

My front end code is:

  <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>
Amarnath Balasubramanian
  • 9,300
  • 8
  • 34
  • 62
Esha
  • 391
  • 1
  • 9
  • 37

2 Answers2

3

You need to set the datasource before calling Gen_Lic_Grid.DataBind();.

protected void gridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
    Gen_Lic_Grid.PageIndex = e.NewPageIndex;
    Gen_Lic_Grid.DataSource = MyVariable;
    Gen_Lic_Grid.DataBind();
}
GeorgesD
  • 1,072
  • 5
  • 7
  • 2
    Addition: when not using a declarative datasource control like `SqlDataSource`. But OP is not using it so your answer seems to be the solution. – Tim Schmelter Dec 18 '12 at 09:56
  • @TimSchmelter: I think that they meant it to be on one line – Neil Knight Dec 18 '12 at 09:56
  • how do you define the `datasource` because honestly, i'm not getting it. – Esha Dec 18 '12 at 10:04
  • @Syrion just include NeedDataSource event in your code and bind datasource there. Next time whenever you use databind() it will automatically call that event and you don't need to define ds (datasource) here. – Dev Dec 18 '12 at 10:06
  • Okay i'm really sorry for asking stupid questions but what is `myvariable` exactly? – Esha Dec 18 '12 at 10:17
  • MyVariable is the datasource you want to bind ?!!! Maybe your dataset, your dataview, whatever you want. – GeorgesD Dec 18 '12 at 10:18
0

I think you should use PageIndexChanged event instead of PageIndexChanging. I think you haven't used NeedDataSource event.

Dev
  • 6,570
  • 10
  • 66
  • 112