 |
|
ASP.Net สงสัยเรื่อง update ข้อมูลจาก gridview ลง database ครับ |
|
 |
|
|
 |
 |
|
ดูตอน Page_Load() และการ Bind Data ครับ ได้มีการดักตัวนี้หรือเปล่า
Code (C#)
if(!Page.IsPostBack)
{
// BindData
}
|
 |
 |
 |
 |
Date :
2014-02-12 10:01:33 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (C#)
testlinq1DataContext db = new testlinq1DataContext();
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
show();
}
}
private void show()
{
var ace = from a in db.ITdevicedetails
join b in db.Brands
on a.Specid equals b.Specid
join c in db.Devicestatus
on a.Statusid equals c.Statusid
where a.Statusid == "ST03"
join d in db.Typedevices
on a.Type equals d.Type
select new
{
IDdevice = a.IDdevice,
Type = d.Type,
Brand = b.Brand1,
Spec = b.Spec
,
Model = b.Model,
Accode = a.Accode,
IPaddress = a.IPaddress,
Serialnumber = a.Serialnumber,
Status = c.Status,
Comment = a.Comment
};
GridView1.DataSource = ace.ToList();
GridView1.DataBind();
}
ดักแล้วครับ สงสัยว่าทำไมมันยังส่งเป็นค่าว่างอยู่ รบกวนด้วยครับ
|
 |
 |
 |
 |
Date :
2014-02-13 16:06:06 |
By :
ninjasand |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Debug ดูเลยครับ 
|
 |
 |
 |
 |
Date :
2014-02-13 21:08:22 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
if (Page.IsPostBack)
{
var ie =
(from ac in db.ITdevicedetails where ac.IDdevice == "note01" select ac).FirstOrDefault();
บรรทัดนี้ตัวเดียวเลย
TextBox xp = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[9].Controls[0]));
ie.Comment = xp.Text;
db.SubmitChanges();
GridView1.EditIndex = -1;
binded();
}
}
ได้แล้วครับ สรุปเป็นเพราะตอนแรกลืมดัก ispostback และ ผมลืมอ้างถึง textbox ใน gridview ด้วย นั่ง งง มาเกือบเดือนเพิ่งแก้ได้ ตอนแรก admin ทักเรื่อง ispostback มาผมเลยลองใส่แล้วแต่ยังไม่ได้เพราะผมไม่ได้แก้ โค้ดที่อ้างถึง textbox ใน gridview ด้วยเลยคิดว่าไม่ใช่พอมาเขียนโค้ดอ้างถึง textbox ใน gridview แล้ว แต่ไม่ได้ใส่ isposback ด้วย ก็เลยนั่ง งง อยู่ที่เดิมไม่ไปไหน พอเอาสองจุดนี้มาเชื่อมกันได้ก็ได้ผลเลย ok ได้เรื่องแล้ว ขอบคุณมากครับ admin
|
 |
 |
 |
 |
Date :
2014-02-24 10:06:07 |
By :
ninjasand |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|