i have gridview in which i have enable pagination when i select row from 5 page it is not retrieving exact data in textboxes which i select row.
here is my code
html
<div>
<script type = "text/javascript">
var ddlText, ddlValue, ddl, lblMesg;
function CacheItems() {
ddlText = new Array();
ddlValue = new Array();
ddl = document.getElementById("<%=DDLsbitemsearch.ClientID %>");
lblMesg = document.getElementById("<%=lblsbs2.ClientID%>");
for (var i = 0; i < ddl.options.length; i++) {
ddlText[ddlText.length] = ddl.options[i].text;
ddlValue[ddlValue.length] = ddl.options[i].value;
}
}
window.onload = CacheItems;
function FilterItems(value) {
ddl.options.length = 0;
for (var i = 0; i < ddlText.length; i++) {
if (ddlText[i].toLowerCase().indexOf(value) != -1) {
AddItem(ddlText[i], ddlValue[i]);
}
}
lblMesg.innerHTML = ddl.options.length + " items found.";
if (ddl.options.length == 0) {
AddItem("No items found.", "");
}
}
function AddItem(text, value) {
var opt = document.createElement("option");
opt.text = text;
opt.value = value;
ddl.options.add(opt);
}
</script>
<table class="auto-style1">
<tr>
<td class="auto-style4"> </td>
<td class="auto-style6"><h1>Bale Transfer From Order to Order</h1></td>
</tr>
<tr>
<td class="auto-style4"> </td>
<td class="auto-style6"> </td>
</tr>
<tr>
<td class="auto-style4">Bale No</td>
<td class="auto-style6">
<asp:TextBox ID="txtbno" runat="server" ReadOnly="True"></asp:TextBox>
</td>
<td class="auto-style2"> </td>
</tr>
<tr>
<td class="auto-style3">Item Name:</td>
<td class="auto-style5">
<asp:DropDownList ID="DDLtitem" runat="server" Height="16px" Enabled="False">
</asp:DropDownList>
</td>
<td> </td>
</tr>
<tr>
<td class="auto-style3">Order No :</td>
<td class="auto-style5">
<asp:TextBox ID="txtton" runat="server"></asp:TextBox>
Transfer Order :
<asp:TextBox ID="txttrnfbno" runat="server"></asp:TextBox>
</td>
<td> </td>
</tr>
<tr>
<td class="auto-style3">Quantity</td>
<td class="auto-style5">
<asp:Label ID="lbt" runat="server" Text="Label"></asp:Label>
</td>
<td> </td>
</tr>
<tr>
<td class="auto-style7"> </td>
<td>
<asp:Button ID="btnupdate" runat="server" Text="Transfer" OnClick="btnupdate_Click" />
</td>
<td> </td>
</tr>
</table>
</div>
<table class="auto-style1">
<tr>
<td class="auto-style9">Search By Bale No:</td>
<td class="auto-style10">
<asp:TextBox ID="txtsearchbno" runat="server" AutoPostBack="True" OnTextChanged="txtsearchbno_TextChanged"></asp:TextBox>
Search Ref_ID :<asp:TextBox ID="txtsearchrefid" runat="server" AutoPostBack="True" OnTextChanged="txtsearchrefid_TextChanged"></asp:TextBox>
Item :
<asp:DropDownList ID="DDLsbitemsearch" AutoPostBack="true" runat="server" OnSelectedIndexChanged="DDLsbitemsearch_SelectedIndexChanged">
</asp:DropDownList>
<asp:TextBox ID="txtsbs2" runat="server" onkeyup = "FilterItems(this.value)" AutoPostBack="true"></asp:TextBox>
<asp:Label ID="lblsbs2" runat="server" Text="."></asp:Label>
</td>
<td class="auto-style10"></td>
</tr>
<tr>
<td class="auto-style8"> </td>
<td>
<asp:GridView ID="GVsmlbal" runat="server" AutoGenerateSelectButton="True" BackColor="White" BorderColor="#E7E7FF" BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Horizontal" AllowPaging="True" AllowSorting="True" OnSelectedIndexChanged="GVsmlbal_SelectedIndexChanged" OnPageIndexChanging="GVsmlbal_PageIndexChanging">
<AlternatingRowStyle BackColor="#F7F7F7" />
<FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
<HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" />
<PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" />
<RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />
<SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
<SortedAscendingCellStyle BackColor="#F4F4FD" />
<SortedAscendingHeaderStyle BackColor="#5A4C9D" />
<SortedDescendingCellStyle BackColor="#D8D8F0" />
<SortedDescendingHeaderStyle BackColor="#3E3277" />
</asp:GridView>
</td>
<td> </td>
</tr>
</table>
c#
SqlConnection con = new SqlConnection();
QryMgmt dm = new QryMgmt();
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
this.DataBind();
}
SqlConnection con = new SqlConnection("Data Source=DESKTOP-5PJ76B9;Integrated Security=SSPI;Initial Catalog=SilverProduction;MultipleActiveResultSets=True;");
{
using (SqlCommand cmd = new SqlCommand("Allsmallbale"))
{
//cmd.Parameters.AddWithValue("@Action", "SELECT");
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = con;
sda.SelectCommand = cmd;
using (DataTable dt = new DataTable())
{
sda.Fill(dt);
GVsmlbal.DataSource = dt;
GVsmlbal.DataBind();
con.Close();
}
}
}
}
if (!Page.IsPostBack)
{
con = new SqlConnection("Data Source=DESKTOP-5PJ76B9;Integrated Security=SSPI;Initial Catalog=SilverProduction;MultipleActiveResultSets=True;");
con.Open();
SqlDataAdapter adprt = new SqlDataAdapter("select * from ItemMasterFile", con);
DataSet dsprt = new DataSet();
adprt.Fill(dsprt);
DDLtitem.DataSource = dsprt.Tables[0];
DDLtitem.DataTextField = "Descriptionitem";
DDLtitem.DataValueField = "Codeitem";
DDLtitem.DataBind();
}
if (!IsPostBack)
{
con = new SqlConnection("Data Source=DESKTOP-5PJ76B9;Integrated Security=SSPI;Initial Catalog=SilverProduction;MultipleActiveResultSets=True;");
con.Open();
SqlDataAdapter adpsbs1 = new SqlDataAdapter("select * from ItemMasterFile", con);
DataSet dssbs1 = new DataSet();
adpsbs1.Fill(dssbs1);
DDLsbitemsearch.DataSource = dssbs1.Tables[0];
DDLsbitemsearch.DataTextField = "Descriptionitem";
DDLsbitemsearch.DataValueField = "Codeitem";
DDLsbitemsearch.DataBind();
DDLsbitemsearch.Items.Insert(0, new ListItem("Select Item", "0"));
con.Close();
}
}
protected void btnupdate_Click(object sender, EventArgs e)
{
String str = ("Data Source=DESKTOP-5PJ76B9;Integrated Security=SSPI;Initial Catalog=SilverProduction;MultipleActiveResultSets=True;");
SqlConnection con = new SqlConnection(str);
SqlCommand cmd = new SqlCommand("updatebaleqtysmall", con);
cmd.CommandType = CommandType.StoredProcedure;
if (txttrnfbno.Text == "")
{
Response.Write("<script>alert('Please Insert Transfer Order No')</script>");
}
else
{
// int Prdno = int.Parse(txttrnfbno.Text);
// int orderno = int.Parse(txtton.Text);
cmd.Parameters.AddWithValue("@Prdno", txtbno.Text);
cmd.Parameters.AddWithValue("@OrderNo", txttrnfbno.Text);
con.Open();
int i = cmd.ExecuteNonQuery();
if (i > 0)
{
// Response.Write("<script>alert('Record save successuly')</script>");
Response.Redirect("TransferSmallbale.aspx");
}
else
{
Response.Write("<script>alert('Record save successuly')</script>");
}
con.Close();
}
}
protected void GVsmlbal_SelectedIndexChanged(object sender, EventArgs e)
{
txtbno.Text = GVsmlbal.SelectedRow.Cells[1].Text;
//string SesnId1 = dm.GetData("select CustomerID from dbo.Customer where CustomerName='" + GVPrd.SelectedRow.Cells[4].Text.Trim() + "'").Rows[0][0].ToString();
string SesnId2 = dm.GetData("select Codeitem from dbo.ItemMasterFile where Descriptionitem='" + GVsmlbal.SelectedRow.Cells[3].Text.Trim() + "'").Rows[0][0].ToString();
//ddpcus.SelectedValue = SesnId1;
DDLtitem.SelectedValue = SesnId2;
txtton.Text = GVsmlbal.SelectedRow.Cells[2].Text;
lbt.Text = GVsmlbal.SelectedRow.Cells[4].Text;
}
protected void txtsearchbno_TextChanged(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=DESKTOP-5PJ76B9;Integrated Security=SSPI;Initial Catalog=SilverProduction;MultipleActiveResultSets=True;");
SqlCommand cmdbno = new SqlCommand("searchbno", con);
cmdbno.CommandType = CommandType.StoredProcedure;
cmdbno.Parameters.AddWithValue("Prdno", txtsearchbno.Text);
SqlDataAdapter adptbno = new SqlDataAdapter(cmdbno);
DataTable dtbno = new DataTable();
adptbno.Fill(dtbno);
GVsmlbal.DataSource = dtbno;
GVsmlbal.DataBind();
cmdbno.Dispose();
con.Close();
}
protected void txtsearchrefid_TextChanged(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=DESKTOP-5PJ76B9;Integrated Security=SSPI;Initial Catalog=SilverProduction;MultipleActiveResultSets=True;");
SqlCommand cmdbnor = new SqlCommand("searchbalrefid", con);
cmdbnor.CommandType = CommandType.StoredProcedure;
cmdbnor.Parameters.AddWithValue("Order_Ref_No", txtsearchrefid.Text);
SqlDataAdapter adptbnor = new SqlDataAdapter(cmdbnor);
DataTable dtbnor = new DataTable();
adptbnor.Fill(dtbnor);
GVsmlbal.DataSource = dtbnor;
GVsmlbal.DataBind();
cmdbnor.Dispose();
con.Close();
}
protected void DDLsbitemsearch_SelectedIndexChanged(object sender, EventArgs e)
{
{
SqlConnection con = new SqlConnection("Data Source=DESKTOP-5PJ76B9;Integrated Security=SSPI;Initial Catalog=SilverProduction;MultipleActiveResultSets=True;");
SqlCommand cmdsbs = new SqlCommand("itemwisesearchprdbale", con);
cmdsbs.CommandType = CommandType.StoredProcedure;
cmdsbs.Parameters.AddWithValue("Codeitem", DDLsbitemsearch.SelectedValue);
SqlDataAdapter adptsbs = new SqlDataAdapter(cmdsbs);
DataTable dtsbs = new DataTable();
adptsbs.Fill(dtsbs);
GVsmlbal.DataSource = dtsbs;
GVsmlbal.DataBind();
cmdsbs.Dispose();
con.Close();
}
}
protected void GVsmlbal_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GVsmlbal.PageIndex = e.NewPageIndex;
GVsmlbal.DataSource = ViewState["Paging"];
}
Please help