0
在编辑状态下输入到文本框表格gridview中的值无法跟上。它是空的。如何从Gridview文本框中获取数据?
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();
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
if (Page.IsPostBack)
{
show();
GridView1.EditIndex = e.NewEditIndex;
DataBind();
}
}
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();
**//this's my problem the value of GridView1.Rows[0].Cells[8].Text; is null.
// but If I assign a value to it, ie.Comment = "nb123"; it's worked.**
ie.Comment = GridView1.Rows[0].Cells[8].Text;
db.SubmitChanges();
GridView1.EditIndex = -1;
binded();
}
}
我不明白为什么我的更新数据到文本框为空。
尽量不要调用'show()'到GridView1_RowEditing'事件处理函数 –
我试着按照你的意思去做,但还没有。谢谢你的帮助 – Collector