how to add gridview page index change
.aspx
<fieldset style="width: 978px; height: 404px;">
<legend><span class="auto-style14">Send Mail and SMS multiple users</span> </legend>
<table class="auto-style2">
<tr>
<td>
<asp:GridView ID="grEmp" runat="server" AutoGenerateColumns="false" AllowPaging="true"
OnPageIndexChanging="OnPageIndexChanging" PageSize="10" OnSelectedIndexChanged="grEmp_SelectedIndexChanged">
<Columns>
<asp:BoundField DataField="vn_emp_cd" HeaderText="VN_EMP_CD" />
<asp:BoundField DataField="ven_emp_name" HeaderText="VEN_EMP_NAME" />
<asp:BoundField DataField="txn_desc" HeaderText="TXN_DESC" />
<asp:BoundField DataField="amt" HeaderText="AMOUNT" />
<asp:BoundField DataField="phone" HeaderText="PHONE" />
<asp:BoundField DataField="email" HeaderText="EMAIL ID" />
<asp:TemplateField HeaderText="CheckAll">
<HeaderTemplate>
<asp:CheckBox ID="chkSelectAll" runat="server" AutoPostBack="true" OnCheckedChanged="chkSelectAll_CheckedChanged" />Send
Mail To All ?
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkSelect" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</asp:GridView>
</td>
</tr>
</table>
</fieldset>
<asp:Button ID="btnSendMail" runat="server" Text="Send " OnClick="btnSendMail_Click"
CausesValidation="false" />
aspx.cs
namespace Email
{
public partial class WebForm1 : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(@"Data Source=(localdb)\Projects;Initial Catalog=Employee;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False");
protected void Page_Load(object sender, EventArgs e)
{
if (Session["FirstName"] == null)
Response.Redirect("login.aspx");
else
{
String EmplooyeId = Convert.ToString((int)Session["empid"]);
String FirstName = Session["FirstName"].ToString();
String LastName = Session["LastName"].ToString();
String Department = Session["Department"].ToString();
lbluserInfo.Text = "Department:- " + Department + ".";
Label1.Text = "Welcome, " + FirstName + " " + LastName + ".";
}
if (!IsPostBack)
{
BindEmpGrid();
}
}
protected void BindEmpGrid()
{
SqlCommand cmd = new SqlCommand("select * from email where flag <> 'Y'", con);
DataTable dt = new DataTable();
SqlDataAdapter adp = new SqlDataAdapter(cmd);
adp.Fill(dt);
grEmp.DataSource = dt;
grEmp.DataBind();
}
protected void chkSelectAll_CheckedChanged(object sender, EventArgs e)
{
CheckBox chkAll = (CheckBox)grEmp.HeaderRow.FindControl("chkSelectAll");
foreach (GridViewRow gvRow in grEmp.Rows)
{
CheckBox chkSel = (CheckBox)gvRow.FindControl("chkSelect");
if (
chkAll.Checked)
{
chkSel.Checked = true;
}
else
{
chkSel.Checked = false;
}
}
}
protected void grEmp_SelectedIndexChanged(object sender, EventArgs e)
{
grEmp.PageIndex = e.NewPageIndex;
this.BindEmpGrid();
}
}
}