When you remove Update Panel then actually your page post back completely . before this it was partially postback on button click. so if you put button and gridview in same update panel then it should works or if you put gridview and button in diffrent update
panel then set the attribute updatemode = "Conditional".
Regards
Shwetamber
Marked as answer by ermine0122 on Mar 02, 2012 03:19 AM
ermine0122
Member
3 Points
2 Posts
Template column in GridView
Feb 28, 2012 03:27 AM|LINK
How can I add a datatable value to TextBox in GridView on ButtonClick Event?
protected void btnView_Click(object sender, EventArgs e) { //Read TextBox inside GridView value, calculate //Then Add calculated data to TextBox In GridView DataTable tbl = new DataTable(); tbl.Columns.Add("Ngay", Type.GetType("System.DateTime")); tbl.Columns.Add("ChiSo", Type.GetType("System.Double")); tbl.Columns.Add("SanLuong", Type.GetType("System.Double")); tbl.Columns.Add("GhiChu", Type.GetType("System.String")); tbl.Columns.Add("Ack",Type.GetType("System.Boolean")); tbl.Columns.Add("ThoaThuan", Type.GetType("System.Boolean")); tbl.Columns.Add("Offset", Type.GetType("System.Boolean")); foreach (GridDataItem dataItem in Grid1.Items) { //read data from GridView, worked EnDataNhapTay data = new EnDataNhapTay(); TextBox TextBoxNgay = (TextBox)(dataItem["Ngay"].FindControl("txtNgay")); TextBox TextBoxChiSo = (TextBox)(dataItem["ChiSo"].FindControl("txtChiSo")); TextBox TextBoxSanLuong = (TextBox)(dataItem["SanLuong"].FindControl("txtSanLuong")); TextBox TextBoxGhiChu = (TextBox)(dataItem["GhiChu"].FindControl("txtGhiChu")); CheckBox CheckBoxThoaThuan = (CheckBox)(dataItem["ThoaThuan"].FindControl("chkThoaThuan")); CheckBox CheckBoxOffset = (CheckBox)(dataItem["Offset"].FindControl("chkOffset")); if (string.IsNullOrEmpty(TextBoxChiSo.Text) && string.IsNullOrEmpty(TextBoxSanLuong.Text)) continue; try { data.DateTime = DateTime.Parse(TextBoxNgay.Text, culture); } catch { continue; } if (string.IsNullOrEmpty(TextBoxChiSo.Text)) data.ChiSo = double.MinValue; else data.ChiSo = double.Parse(TextBoxChiSo.Text); if (string.IsNullOrEmpty(TextBoxSanLuong.Text)) data.SanLuong = double.MinValue; data.ThoaThuan = CheckBoxThoaThuan.Checked; data.OffSet = CheckBoxOffset.Checked; data.GhiChu = TextBoxGhiChu.Text; data.MaVT = cbbMaVT.Text; if (string.IsNullOrEmpty(cbbMaVT.Text)) continue; //Calculate data, worked SqlDataReader rdr = BLMeterData.CalculateMeterData(data); while (rdr.Read()) { DataRow row = tbl.NewRow(); row[0] = (DateTime)rdr[1]; if (DBNull.Value.Equals(rdr[2])) row[1] = DBNull.Value; else row[1] = (double)rdr[2]; if (DBNull.Value.Equals(rdr[3])) row[2] = DBNull.Value; else row[2] = (double)rdr[3]; if (DBNull.Value.Equals(rdr[4])) row[3] = DBNull.Value; else row[3] = (string)rdr[4]; row[4] = (bool)rdr[5]; row[5] = (bool)rdr[6]; row[6] = (bool)rdr[7]; tbl.Rows.Add(row); } Public.CloseDataReader(rdr); } //Write calculated data to GridView, can't see any change when code done??? for (int i = 0; i < tbl.Rows.Count; i++) { GridDataItem dataItem = Grid1.Items[i]; TextBox TextBoxNgay = (TextBox)(dataItem["Ngay"].FindControl("txtNgay")); TextBox TextBoxChiSo = (TextBox)(dataItem["ChiSo"].FindControl("txtChiSo")); TextBox TextBoxSanLuong = (TextBox)(dataItem["SanLuong"].FindControl("txtSanLuong")); TextBox TextBoxGhiChu = (TextBox)(dataItem["GhiChu"].FindControl("txtGhiChu")); CheckBox CheckBoxAck = (CheckBox)(dataItem["Ack"].FindControl("chkGhiChu")); CheckBox CheckBoxThoaThuan = (CheckBox)(dataItem["ThoaThuan"].FindControl("chkThoaThuan")); CheckBox CheckBoxOffset = (CheckBox)(dataItem["Offset"].FindControl("chkOffset")); TextBoxNgay.Text = ((DateTime)tbl.Rows[i][0]).ToString(dateFormat); if (DBNull.Value.Equals(tbl.Rows[i][1])) TextBoxChiSo.Text = string.Empty; else TextBoxChiSo.Text = ((double)tbl.Rows[i][1]).ToString(); if (DBNull.Value.Equals(tbl.Rows[i][2])) TextBoxSanLuong.Text = string.Empty; else TextBoxSanLuong.Text = ((double)tbl.Rows[i][2]).ToString(); if (DBNull.Value.Equals(tbl.Rows[i][3])) TextBoxGhiChu.Text = string.Empty; else TextBoxGhiChu.Text = ((double)tbl.Rows[i][3]).ToString(); //CheckBoxAck.Checked = (bool)tbl.Rows[i][4]; //CheckBoxThoaThuan.Checked = (bool)tbl.Rows[i][5]; //CheckBoxOffset.Checked = (bool)tbl.Rows[i][6]; } }basheerkal
Star
10672 Points
2426 Posts
Re: Template column in GridView
Feb 28, 2012 04:36 AM|LINK
Hi
Cannot get What do you do . Why don't you bind your gridview to your Data table.
and bind Textbox in Templatefiled to the required field?
B
(Talk less..Work more)
ermine0122
Member
3 Points
2 Posts
Re: Template column in GridView
Feb 28, 2012 05:47 AM|LINK
I have just removed update panel wrap gridview, and it worked
Dont know why
Thank you anyway
shwetamber
Participant
1252 Points
294 Posts
Re: Template column in GridView
Feb 28, 2012 05:59 AM|LINK
Hi,
When you remove Update Panel then actually your page post back completely . before this it was partially postback on button click. so if you put button and gridview in same update panel then it should works or if you put gridview and button in diffrent update panel then set the attribute updatemode = "Conditional".
Regards
Shwetamber