I use linq to sql,and use a drop down for showing records,
I use this code for paging in .aspx file
<asp:DropDownList ID="drpPageSize" class="form-control" runat="server" AutoPostBack="True" OnSelectedIndexChanged="drpPageSize_SelectedIndexChanged" meta:resourcekey="drpPageSizeResource1">
<asp:ListItem Selected="True" meta:resourcekey="ListItemResource1">5</asp:ListItem>
<asp:ListItem meta:resourcekey="ListItemResource2">10</asp:ListItem>
<asp:ListItem meta:resourcekey="ListItemResource10">50</asp:ListItem>
<asp:ListItem meta:resourcekey="ListItemResource12">100</asp:ListItem>
<asp:ListItem Text="All" meta:resourcekey="ListItemResource11"></asp:ListItem>
</asp:DropDownList>
and use this code for .cs file,here is both code for gridbind and drpselect index changed event
protected void grdBind()
{
try
{
EventManagerDataContext db = new EventManagerDataContext();
var q = from a in db.EMR_EVENTs
join b in db.EMR_CLIENTs on a.ClientID equals b.ClientID
select new
{
ClientName = b.Name,
ClientID = a.ClientID,
Name = a.Name,
No_Of_Invitees = a.No_Of_Invitees,
Extra_Invitees = a.Extra_Invitees,
Total_Invitees = a.Extra_Invitees + a.No_Of_Invitees,
EventID = a.EventID,
};
grid.DataSource = q.ToList();
if (Convert.ToInt32(Session["k"])== 1)
{
grid.PageSize = Convert.ToInt32(Session["total"]);
}
else
{
grid.PageSize = int.Parse(drpPageSize.SelectedValue);
}
grid.DataBind();
}
catch
{
throw;
}
}
protected void drpPageSize_SelectedIndexChanged(object sender, EventArgs e)
{
if (drpPageSize.SelectedIndex == 4)
{
grid.AllowPaging = false;
Session["k"] = 1;
grdBind();
}
else
{
Session["k"] = 2;
grid.PageSize = int.Parse(drpPageSize.SelectedItem.Text);
grdBind();
}
}
my all code is working. but i found that when i select all from gridview i found all records,but after select all from drop down i select 5 then i not get the 5 records ,insted of i get all the records,same as in 10,50,100
any solution please.?
i also appreciate that a better code for my requirement,my main purpose is show all records from gridview while i select all from dropdown.