Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.1
|
ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.1 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 5th, 2004, 01:19 AM
Registered User
 
Join Date: Apr 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Deleting rows of datagrid and paging

Hai I have a problem in paging.
I have a datagrid with last column as checkbox. In the header of the lastcolumn i have a checkbox. If i choose the header checkbox, all the checkboxes in that particular page is checked and deleted. But once i click the delete buttpn the problem i encounter is

" Invalid CurrentPageIndex value. It must be >= 0 and < the PageCount. "

Here is the complete code:

private void Page_Load(object sender, System.EventArgs e)
{
 dgCustomerUpload.AllowPaging = true;
 dgCustomerUpload.PagerStyle.Mode = agerMode.NumericPages;
 dgCustomerUpload.PagerStyle.PageButtonCount = 10;
 dgCustomerUpload.PageSize = 10;

 if(!IsPostBack)
 {
 btnCustomerUpload.Attributes.Add("onClick", "javascript:return confirm('Are you sure you want to add these values?')");

 BindData();
 }
}

public void BindData()
{
 SqlConnection conn = new SqlConnection(ConfigurationSettings.AppSettings["CONN_STR"]);
 if(conn.State != ConnectionState.Open){conn.Open();}
 SqlDataAdapter adap = new SqlDataAdapter("SELECT * FROM [grp1].[dbo].v_gbims_CUSTOMER WHERE CUST_CD NOT IN (SELECT CUST_POWERID FROM [gbims].[dbo].t_CUSTOMER WHERE CUST_POWERID IS NOT NULL)",conn);

 DataSet ds = new DataSet();
 adap.Fill(ds,"t_CUSTOMER");
 dgCustomerUpload.DataSource = ds.Tables["t_CUSTOMER"].DefaultView;
 dgCustomerUpload.DataBind();
 conn.Close();

 }

 bool ChecktheBox(int varInt)
 {
 if (varInt== 1)
 {
  return true;
 }
 else
 {
 return false;
 }
}

private void btnCustomerUpload_Click(object sender, System.EventArgs e)
{

  ArrayList selectedRows = new ArrayList();
  foreach (DataGridItem item in dgCustomerUpload.Items)
  {

CheckBox chkselection = (CheckBox)item.FindControl("chkselection");
if (chkselection != null && chkselection.Checked)
{

 Label lblCUST_CD = (Label)item.FindControl("lblCUST_CD");
 Label lblCUST_NAME = (Label)item.FindControl("lblCUST_NAME");
 Label lblCUST_EMAIL_ADDR = (Label)item.FindControl("lblCUST_EMAIL_ADDR");
 Label lblCUST_STATUS = (Label)item.FindControl("lblCUST_STATUS");

 if (lblCUST_CD!= null)
 {

 string strCUST_CD = Regex.Replace(lblCUST_CD.Text,"'","''");
 string strCUST_NAME =Regex.Replace(lblCUST_NAME.Text,"'","''");
 string strCUST_EMAIL_ADDR =lblCUST_EMAIL_ADDR.Text;
 string strCUST_STATUS =lblCUST_STATUS.Text;



 SqlConnection conn = new SqlConnection(ConfigurationSettings.AppSettings["CONN_STR"]);
 if(conn.State != ConnectionState.Open){conn.Open();}
    SqlCommand cmdCUST =new SqlCommand("INSERT INTO [gbims].[dbo].t_CUSTOMER (CUST_POWERID,CUST_NAME,CUST_EMAIL_ADDR,CUST_STATU S) VALUES (" + "'" + strCUST_CD + "'" + "," + "'" + strCUST_NAME + "'" + "," + "'" + strCUST_EMAIL_ADDR + "'" + "," + "'" + strCUST_STATUS + "'" + ")",conn);

    cmdCUST.ExecuteNonQuery();
    conn.Close();
    chkselection.Checked=false;

   }
  }
  }
  BindData();

}



private void dgCustomerUpload_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEvent Args e)
{
                    dgCustomerUpload.CurrentPageIndex = e.NewPageIndex;
                BindData();


}




 
Old April 5th, 2004, 11:35 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hello,

I don't see any code for deleting... could you post it?

Brian
 
Old April 6th, 2004, 08:57 PM
Registered User
 
Join Date: Apr 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hai Brian thanks for responding

btnCustomerUpload_Click event is actually were i am removing the selected row from datagrid . One point to be noted is that i am just removign from datagrid display and not from database. After removing i am inserting the deleted row in a new table






Similar Threads
Thread Thread Starter Forum Replies Last Post
Deleting rows from a data table in datagrid ann03 ASP.NET 1.x and 2.0 Application Design 1 October 23rd, 2007 06:23 AM
Speed up macro - deleting rows icabo Excel VBA 1 October 8th, 2007 02:18 PM
Deleting rows not equal to specific values Oprete Excel VBA 1 March 25th, 2007 11:14 PM
Deleting rows in Winforms Datagrid livehed General .NET 0 May 4th, 2006 01:23 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.