deleting a row in a gridview using c#

deleting a row in gridview by checking the checkboxes using delete but

Page 1 of 1

3 Replies - 22423 Views - Last Post: 21 May 2009 - 09:56 AM Rate Topic: -----

#1 mahithareddy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 25-December 08

deleting a row in a gridview using c#

Post icon  Posted 20 May 2009 - 11:12 PM

i used code like this
for deleting the rows in gridview

aspx.cs code

 protected void btndelete_Click1(object sender, EventArgs e)
	{

		//int index = this.grid.SelectedIndex;
		//this.grid.SelectedIndex = -1;
		//this.grid.DeleteRow(index);
		string strid = string.Empty;
		try
		{
		for (int i = 0; i < grid.Rows.Count; i++)
		{
			CheckBox chkdel = (CheckBox)grid.Rows[i].Cells[0].FindControl("chkdelete");
			if (chkdel != null)
			{
				if (chkdel.Checked)
				{
					strid = grid.Rows[i].Cells[0].Text;
					string Date = txtdate.Text;
					grid.DataSource = assign.delassignment(Date);
					grid.DataBind();
				}
			}
		  }
		  
	  }

	  catch (Exception ex)
	  {
		  lblMsg.Text = ex.ToString();

	  }


	  //grid.DataBind();
   }

	


		protected void chkdelete_CheckedChanged(object sender, EventArgs e)
		{
			CheckBox chktest = (CheckBox)sender;
			GridViewRow grdrow = (GridViewRow)chktest.NamingContainer;
			TextBox txtAss = (TextBox)grdrow.FindControl("txtassign");
			TextBox txtSub = (TextBox)grdrow.FindControl("txtsubject");
			if (chktest.Checked)
			{
				txtAss.ReadOnly = false;
				txtSub.ReadOnly = false;
			}
			else
			{
				txtAss.ReadOnly = true;
				txtSub.ReadOnly = true;
			}
		}

		private void uncheckall()
		{
			foreach (GridViewRow row in grid.Rows)
			{
				CheckBox chkuncheck = (CheckBox)row.FindControl("chkdelete");
				TextBox txtAss = (TextBox)row.FindControl("txtassign");
				TextBox txtSub = (TextBox)row.FindControl("txtsubject");
				chkuncheck.Checked = false;
				txtAss.ReadOnly = true;
				txtSub.ReadOnly = true;
			}
		}



Mod Edit: Please use code tags when posting your code. Code tags are used like so => :code:

Thanks,
PsychoCoder :)

Is This A Good Question/Topic? 0
  • +

Replies To: deleting a row in a gridview using c#

#2 firebolt  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 92
  • View blog
  • Posts: 5,561
  • Joined: 20-February 09

Re: deleting a row in a gridview using c#

Posted 20 May 2009 - 11:21 PM

Could you please place your code in the code tags. :code:
Can you tell us of any errors associated with your code.
Thanks.
Was This Post Helpful? 0
  • +
  • -

#3 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1642
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: deleting a row in a gridview using c#

Posted 21 May 2009 - 09:52 AM

Moved to ASP.NET :)
Was This Post Helpful? 0
  • +
  • -

#4 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1642
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: deleting a row in a gridview using c#

Posted 21 May 2009 - 09:56 AM

Are you receiving any errors? Does this code not work that way you intended it? When asking for help there are a couple items that are vital in order for someone to properly help you:
  • Post the code you're having problems with
  • Post the exact error you're receiving, if you are receiving one
  • If no error explain what the code is doing versus what you want it to do
  • Post your question in the body of your post, not the description field

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1