|
 |
|
สอบถามต่อค่ะจากที่เคยถามว่า gridview โชว์ข้อมูลตามเงื่อนไข เมื่อโชว์แล้วอยากทำการบันทึกข้อมูลเมื่อมีการแก้ไขค่ะ |
|
 |
|
|
 |
 |
|
ใช้หลักการ FindControl ครับ ส่วนจะทำอะไรก็แทรกใน Loop ได้เลยครับ
Code (C#)
void btnDelete_OnClick(object sender,EventArgs e)
{
CheckBox chkDel;
Label lblID;
int i;
for( i = 0; i <= myGridView.Items.Count - 1; i++)
{
chkDel = (CheckBox)myGridView.Items[i].FindControl("chkDel");
lblID = (Label)myGridView.Items[i].FindControl("lblCustomerID");
if(chkDel.Checked)
{
strSQL = "DELETE FROM customer WHERE CustomerID = '"+ lblID.Text +"' ";
objCmd = new SqlCommand(strSQL, objConn);
objCmd.ExecuteNonQuery();
}
}
BindData();
}
|
 |
 |
 |
 |
Date :
2013-12-04 09:25:20 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เขียนมาเป็นแบบนี้แต่มันไม่เซฟให้ทุกค่าต้องแก้ตรงไหนคะ
Code (C#)
protected void cmdSave_Click(object sender, EventArgs e)
{
eContractDBDataContext db = new eContractDBDataContext();
int icount = 0;
for (int i = 0; i < grdSearch.Rows.Count; i++)
{
CheckBox chkUse = new CheckBox();
chkUse = grdSearch.Rows[i].FindControl("chkUse") as CheckBox;
chkUse.Enabled = false;
if (chkUse.Checked == true)
{
CheckBox chkAdult = new CheckBox();
chkAdult = grdSearch.HeaderRow.FindControl("chkAdult") as CheckBox;
CheckBox chkTeen = new CheckBox();
chkTeen = grdSearch.HeaderRow.FindControl("chkTeen") as CheckBox;
CheckBox chkChild = new CheckBox();
chkChild = grdSearch.HeaderRow.FindControl("chkChild") as CheckBox;
TextBox txtMealPrice1 = new TextBox();
txtMealPrice1 = grdSearch.Rows[i].FindControl("txtMealPrice1") as TextBox;
if (txtMealPrice1.Text == "")
{
txtMealPrice1.Text = "0";
}
TextBox txtMealPrice2 = new TextBox();
txtMealPrice2 = grdSearch.Rows[i].FindControl("txtMealPrice2") as TextBox;
if (txtMealPrice2.Text == "")
{
txtMealPrice2.Text = "0";
}
TextBox txtMealPrice3 = new TextBox();
txtMealPrice3 = grdSearch.Rows[i].FindControl("txtMealPrice3") as TextBox;
if (txtMealPrice3.Text == "")
{
txtMealPrice3.Text = "0";
}
Mealz ml = new Mealz();
ml.Compulsory = "O";
ml.CreateBy = User.Identity.Name;
ml.CurrencyID = Request.QueryString["cur"].ToString().ToDecimal();
ml.MealTypeID = grdSearch.DataKeys[i].Value.ToString().ToDecimal();
ml.PropID = Request.QueryString["HotelID"].ToString().ToDecimal();
ml.UpdateBy = "";
ml.UpdateTime = DateTime.Now;
ml.ValidYear = "";
ml.ValidID = Request.QueryString["V"].ToString().ToDecimal();
if (chkAdult.Checked == true)
{
ml.AgeID = 33;
ml.MealPrice = txtMealPrice1.Text.ToDecimal();
}
if(chkTeen.Checked == true)
{
ml.AgeID = 34;
ml.MealPrice = txtMealPrice2.Text.ToDecimal();
}
if (chkChild.Checked == true)
{
ml.AgeID = 36;
ml.MealPrice = txtMealPrice3.Text.ToDecimal();
}
db.Mealzs.InsertOnSubmit(ml);
db.SubmitChanges();
icount = icount + 1;
}
}
if (icount == 0)
{
Alert("er", "Please Choose Meal Type", true);
return;
}
else
{
cmdSave.Visible = false;
cmdUpdate.Visible = true;
Alert(MsgType.FinishSave);
return;
}
}
|
 |
 |
 |
 |
Date :
2013-12-04 10:13:02 |
By :
หมูแดง |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 05
|