Russian version
English version
| | | | SILICON TAIGA | ISDEF | CD | | | | | | | |
 
 
 
IT-
 
 
 
RSS-

C#: DataGrid + Checkbox(Delete/Insert)

checkbox- DataGrid ( ), ( ). , . (. . checkbox- DataGrid ),

checkbox- DataGrid ( ), ( ). , . (. . checkbox- DataGrid ), . , - , .

:

- ordertable ordertable1 (OrderID(int), login(nvchar), StockID(int), postedDate(nvchar), Quantity(int)).

:

: ordertable, btnInsert ordertable1.

dgOrdertable1, btnDelete .

WebForm1 , . 1

. 1

CheckBox- (. )

, dgOrdertable ordertable, dgOrdertable1 ordertable1. sqlDataAdapter1, ordertable, sqlDataAdapter2 - ordertable1. dataSet11, dgOrdertable dgOrdertable1.

:

 private void Page_Load( object sender, System.EventArgs e)
		{
			 if (!IsPostBack)
			{
				
				sqlDataAdapter1.Fill(dataSet11);
				sqlDataAdapter2.Fill(dataSet11);
				dgOrdertable.DataBind();
				dgOrdertable1.DataBind();
			}
		}

dgOrdertable dgOrdertable1

 private void btnInsert_Click( object sender, System.EventArgs e)
{
 int OrderID;
 int StockID;
 string login;
 string postedDate;
 int Quantity;			
CheckBox chkbox = new CheckBox();
 for ( int i =0; i < dgOrdertable.Items.Count-1; i++) 
{
 foreach (DataGridItem dgi in dgOrdertable.Items) 
{
 if (((CheckBox) dgi.FindControl("chkbox")).Checked) 
{				
login=dgOrdertable.Items[i].Cells[2].Text;
postedDate=dgOrdertable.Items[i].Cells[4].Text;
OrderID=System.Convert.ToInt16(dgOrdertable.Items[i].Cells[1].Text);
StockID=System.Convert.ToInt16(dgOrdertable.Items[i].Cells[3].Text);
Quantity=System.Convert.ToInt16(dgOrdertable.Items[i].Cells[5].Text);
//  sqlDataAdapter1  InsertCommand   CommandText "INSERT INTO ordertable 
//(OrderID, login, StockID, postedDate, Quantity) VALUES (@OrderID, @login, @StockID, //@postedDate, @Quantity)"

sqlDataAdapter2.InsertCommand.Parameters["@OrderID"].Value=OrderID;
sqlDataAdapter2.InsertCommand.Parameters["@login"].Value=login;
sqlDataAdapter2.InsertCommand.Parameters["@StockID"].Value=StockID;
sqlDataAdapter2.InsertCommand.Parameters["@postedDate"].Value=postedDate;
sqlDataAdapter2.InsertCommand.Parameters["@Quantity"].Value=Quantity;
sqlConnection1.Open();	
sqlDataAdapter2.InsertCommand.ExecuteNonQuery();
sqlConnection1.Close();
}
i++;
}					
sqlDataAdapter1.Fill(dataSet11);
sqlDataAdapter2.Fill(dataSet11);
dgOrdertable.DataBind();
dgOrdertable1.DataBind();
}
}

dgOrdertable1.

 private void btnDelete_Click( object sender, System.EventArgs e)
{
 int OrderID;
 int StockID;
 string login;
CheckBox chkbox = new CheckBox();
 for ( int i =0; i < dgOrdertable1.Items.Count; i++) 
{
 foreach (DataGridItem dgi in dgOrdertable1.Items) 
{
 if (((CheckBox) dgi.FindControl("chkbox")).Checked) 
{	
OrderID=System.Convert.ToInt16(dgOrdertable1.Items[i].Cells[1].Text);
login=dgOrdertable1.Items[i].Cells[2].Text;
StockID=System.Convert.ToInt16(dgOrdertable1.Items[i].Cells[3].Text);

// sqlDataAdapter1 DeleteCommand CommandText "DELETE FROM ordertable1 //WHERE (OrderID = @OrderID) AND (login = @login) AND (StockID = @StockID)" sqlDataAdapter2.DeleteCommand.Parameters["@OrderID"].Value=OrderID; sqlDataAdapter2.DeleteCommand.Parameters["@login"].Value=login; sqlDataAdapter2.DeleteCommand.Parameters["@StockID"].Value=StockID; sqlConnection1.Open(); sqlDataAdapter2.DeleteCommand.ExecuteNonQuery(); sqlConnection1.Close(); } i++; } sqlDataAdapter1.Fill(dataSet11); sqlDataAdapter2.Fill(dataSet11); dgOrdertable.DataBind(); dgOrdertable1.DataBind(); } }

.

. .

.


     
 
 
  : 07.05.2006  

| | | | SILICON TAIGA | ISDEF | CD | | | | | | | |

: Silicon Taiga    
Rambler's Top100 Rambler's Top100