0 Replies - 1717 Views - Last Post: 09 October 2012 - 12:00 PM Rate Topic: -----

#1 nguyenl@co.thurston.wa.us  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 09-October 12

Asp.net paging and find function not working properly.

Posted 09 October 2012 - 12:00 PM

I have a listview with a search function and a pager. The search function allows me to search for an item and then fills the listview. Everything work fine until I click the "Next" pager button. When I do a search after click this "Next" button, I get an empty listview the first time. If I click "Find" again I get the correct results but then my "Edit" breaks. Please help.


using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using System.Web.Security; 
using System.Drawing; 
using System.Data.SqlClient; 
using System.Configuration; 
using System.Data; 
 
public partial class Controls_ManageFundsControl : System.Web.UI.UserControl 
{ 
 
    private void BindFundNoTable() 
    { 
        ListView ManageFundNoListView = this.FindControl("ManageFundsListView") as ListView; 
        TextBox FindFundNoTextBox = ManageFundNoListView.FindControl("FindFundNoTextBox") as TextBox; 
 
        //ManageFundNoListView.DataSourceID = null; 
        SqlConnection HighlanderVMconn = new SqlConnection(ConfigurationManager.ConnectionStrings["HighlanderVMconn"].ConnectionString); 
        HighlanderVMconn.Open(); 
        SqlCommand cmdExecFindALLFundNoSP = new SqlCommand("DisplayALLFundsSP", HighlanderVMconn); 
        cmdExecFindALLFundNoSP.CommandType = CommandType.StoredProcedure; 
        SqlDataAdapter da = new SqlDataAdapter(cmdExecFindALLFundNoSP); 
        DataSet ds = new DataSet(); 
        da.Fill(ds, "DisplayALLFundNotable"); 
        ManageFundNoListView.DataSource = ds.Tables["DisplayALLFundNotable"]; 
        ManageFundNoListView.DataBind(); 
        HighlanderVMconn.Close(); 
    } 
 
    protected void Page_Load(object sender, EventArgs e) 
    { 
        if (!IsPostBack) 
        { 
 
            BindFundNoTable(); 
 
        } 
    } 
    protected void FindFundNoButton_onclick(object sender, EventArgs e) 
    { 
        if (!Page.IsValid) 
        { 
            return; 
        } 
        ListView ManageFundNoListView = this.FindControl("ManageFundsListView") as ListView; 
        TextBox FindFundNoTextBox = ManageFundNoListView.FindControl("FindFundNoTextBox") as TextBox; 
 
         
        if (FindFundNoTextBox != null && ManageFundNoListView != null) 
        { 
             
            //Makes SQl connection 
            SqlConnection HighlanderVMconn = new SqlConnection(ConfigurationManager.ConnectionStrings["HighlanderVMconn"].ConnectionString); 
            HighlanderVMconn.Open(); 
                                  
            SqlCommand cmdExecFindFundNoSP = new SqlCommand("FindFundsSP", HighlanderVMconn); 
            cmdExecFindFundNoSP.CommandType = CommandType.StoredProcedure; 
            cmdExecFindFundNoSP.Parameters.AddWithValue("@FundNo", FindFundNoTextBox.Text); 
 
            SqlDataAdapter da = new SqlDataAdapter(cmdExecFindFundNoSP); 
            DataSet ds = new DataSet(); 
            da.Fill(ds, "FindFundNotable"); 
            ManageFundNoListView.DataSource = ds.Tables["FindFundNotable"]; 
            ManageFundNoListView.DataBind(); 
            HighlanderVMconn.Close(); 
        } 
    } 
    protected void ListViewItemEditing(object sender, ListViewEditEventArgs e) 
    { 
         
        ListView ManageFundNoListView = this.FindControl("ManageFundsListView") as ListView; 
        TextBox FindFundNoTextBox = ManageFundNoListView.FindControl("FindFundNoTextBox") as TextBox; 
        ManageFundNoListView.EditIndex = e.NewEditIndex; 
        BindFundNoTable(); 
 
    } 
 
 
    protected void ListViewItemUpdating(object sender, ListViewUpdateEventArgs e) 
    { 
        ListView ManageFundNoListView = this.FindControl("ManageFundsListView") as ListView; 
        TextBox FindFundNoTextBox = ManageFundNoListView.FindControl("FindFundNoTextBox") as TextBox; 
        ListViewItem item = ManageFundNoListView.Items[e.ItemIndex]; 
        TextBox DistIDTextBox = (TextBox)item.FindControl("DistIDTextBox"); 
 
       // ManageFundNoListView.DataSourceID = null; 
 
        string FundNo = ManageFundNoListView.DataKeys[e.ItemIndex].Value.ToString(); 
        SqlConnection HighlanderVMconn = new SqlConnection(ConfigurationManager.ConnectionStrings["HighlanderVMconn"].ConnectionString); 
        HighlanderVMconn.Open(); 
        SqlCommand cmdExecUpdateFundNoSP = new SqlCommand("UpdateFundsSP", HighlanderVMconn); 
        cmdExecUpdateFundNoSP.CommandType = CommandType.StoredProcedure; 
        cmdExecUpdateFundNoSP.Parameters.AddWithValue("@FundNo", FundNo); 
        cmdExecUpdateFundNoSP.Parameters.AddWithValue("@DistId", DistIDTextBox.Text); 
        cmdExecUpdateFundNoSP.ExecuteNonQuery(); 
 
        ManageFundNoListView.EditIndex = -1; 
        BindFundNoTable(); 
 
    } 
 
    protected void ListViewItemCanceling(object sender, ListViewCancelEventArgs e) 
     
    { 
        ListView ManageFundNoListView = this.FindControl("ManageFundsListView") as ListView; 
        TextBox FindFundNoTextBox = ManageFundNoListView.FindControl("FindFundNoTextBox") as TextBox; 
 
        ManageFundNoListView.EditIndex = -1; 
        BindFundNoTable(); 
 
    } 
 
    protected void InsertListViewItem(object sender, ListViewInsertEventArgs e) 
    { 
        ListView ManageFundNoListView = this.FindControl("ManageFundsListView") as ListView; 
        TextBox FindFundNoTextBox = ManageFundNoListView.FindControl("FindFundNoTextBox") as TextBox; 
        
       // ManageFundNoListView.DataSourceID = null; 
        ListViewItem item = e.Item; 
        TextBox FundNoTextBox = (TextBox)item.FindControl("FundNoTextBox"); 
        TextBox DistIDTextBox = (TextBox)item.FindControl("DistIDTextBox"); 
        SqlConnection HighlanderVMconn = new SqlConnection(ConfigurationManager.ConnectionStrings["HighlanderVMconn"].ConnectionString); 
        HighlanderVMconn.Open(); 
        SqlCommand cmdExecInsertFundNoSP = new SqlCommand("InsertFundsSP", HighlanderVMconn); 
        cmdExecInsertFundNoSP.CommandType = CommandType.StoredProcedure; 
        cmdExecInsertFundNoSP.Parameters.AddWithValue("@FundNo", FundNoTextBox.Text); 
        cmdExecInsertFundNoSP.Parameters.AddWithValue("@DistId", DistIDTextBox.Text); 
        cmdExecInsertFundNoSP.ExecuteNonQuery(); 
 
        BindFundNoTable(); 
 
 
    } 
    protected void ListViewDeleteItem(object sender, ListViewDeleteEventArgs e) 
    { 
        ListView ManageFundNoListView = this.FindControl("ManageFundsListView") as ListView; 
        TextBox FindFundNoTextBox = ManageFundNoListView.FindControl("FindFundNoTextBox") as TextBox; 
        ListViewItem item = ManageFundNoListView.Items[e.ItemIndex]; 
 
       // ManageFundNoListView.DataSourceID = null; 
        string FundNo = ManageFundNoListView.DataKeys[e.ItemIndex].Value.ToString(); 
        SqlConnection HighlanderVMconn = new SqlConnection(ConfigurationManager.ConnectionStrings["HighlanderVMconn"].ConnectionString); 
        HighlanderVMconn.Open(); 
        SqlCommand cmdExecDeleteFundsSP = new SqlCommand("DeleteFundsSP", HighlanderVMconn); 
        cmdExecDeleteFundsSP.CommandType = CommandType.StoredProcedure; 
        cmdExecDeleteFundsSP.Parameters.AddWithValue("@FundNo", FundNo); 
        cmdExecDeleteFundsSP.ExecuteNonQuery(); 
        HighlanderVMconn.Close(); 
        //ManageFundNoListView.DataSourceID = "ManageFundsSqlDataSource"; 
        FindFundNoTextBox.Text = "Search FundNo."; 
 
        BindFundNoTable(); 
    } 
 
    protected void PagePropertiesChanging(object sender, PagePropertiesChangingEventArgs e) 
    { 
 
        ListView ManageFundNoListView = this.FindControl("ManageFundsListView") as ListView; 
        TextBox FindFundNoTextBox = ManageFundNoListView.FindControl("FindFundNoTextBox") as TextBox; 
 
      
        DataPager pager = (DataPager)((ListView)sender).FindControl("DataPager1"); 
        pager.SetPageProperties(e.StartRowIndex, e.MaximumRows, false); 
        BindFundNoTable(); 
      
    } 
 
     
 
    //*****************************************Custom Validators************************************************* 
    protected void FindFundNoMessageCustomValidator_ServerValidate(object source, ServerValidateEventArgs args) 
    { 
 
        ListView ManageFundNoListView = this.FindControl("ManageFundsListView") as ListView; 
        TextBox FindFundNoTextBox = ManageFundNoListView.FindControl("FindFundNoTextBox") as TextBox; 
        
 
            ManageFundNoListView.EditIndex = -1; 
            //Makes SQl connection 
            SqlConnection HighlanderVMconn = new SqlConnection(ConfigurationManager.ConnectionStrings["HighlanderVMconn"].ConnectionString); 
            HighlanderVMconn.Open(); 
            SqlCommand cmdExecCheckFundsExistsSP = new SqlCommand("CheckFundsExistsSP", HighlanderVMconn); 
            cmdExecCheckFundsExistsSP.CommandType = CommandType.StoredProcedure; 
            cmdExecCheckFundsExistsSP.Parameters.AddWithValue("@FundNo", FindFundNoTextBox.Text); 
            cmdExecCheckFundsExistsSP.CommandType = CommandType.StoredProcedure; 
 
            int ResultsCount = Convert.ToInt32(cmdExecCheckFundsExistsSP.ExecuteScalar().ToString()); 
 
 
            if (ResultsCount == 0) 
            { 
                args.IsValid = false; 
            } 
           
 
            HighlanderVMconn.Close(); 
 
     
         
    } 
 
    protected void FindFundNoDupMessageCustomValidator_ServerValidate(object source, ServerValidateEventArgs args) 
    { 
        ListView ManageFundNoListView = this.FindControl("ManageFundsListView") as ListView; 
        TextBox FundNoTextBox = ManageFundNoListView.InsertItem.FindControl("FundNoTextBox") as TextBox; 
       
 
            ManageFundNoListView.EditIndex = -1; 
            //Makes SQl connection 
            SqlConnection HighlanderVMconn = new SqlConnection(ConfigurationManager.ConnectionStrings["HighlanderVMconn"].ConnectionString); 
            HighlanderVMconn.Open(); 
            SqlCommand cmdExecCheckFundsExistsSP = new SqlCommand("CheckFundsExistsSP", HighlanderVMconn); 
            cmdExecCheckFundsExistsSP.CommandType = CommandType.StoredProcedure; 
            cmdExecCheckFundsExistsSP.Parameters.AddWithValue("@FundNo", FundNoTextBox.Text); 
            cmdExecCheckFundsExistsSP.CommandType = CommandType.StoredProcedure; 
            int ResultsCount = Convert.ToInt32(cmdExecCheckFundsExistsSP.ExecuteScalar().ToString());  
 
 
            if (ResultsCount != 0) 
            { 
                args.IsValid = false; 
            } 
 
            HighlanderVMconn.Close(); 
 
         
    } 
} 
        //*****************************************Custom Validators End************************************************* 
 





Is This A Good Question/Topic? 0
  • +

Page 1 of 1