|
|
|
การ refresh datagridview แก้ไขยังไงดี มันไม่ เปลี่ยนค่าให้สะทีอ่ะครับ |
|
|
|
|
|
|
|
แก้ไขยังไงดี มันไม่ เปลี่ยนค่าให้สะทีอ่ะครับ
Code (C#)
protected void Page_Load(object sender, EventArgs e)
{
if (Convert.ToString(Session["login"]) != "live")
{
Response.Redirect("login.aspx");
}
else
{
if (!IsPostBack)
{
clsdb db = new clsdb(Convert.ToString(Session["sql"]));
OleDbConnection dbcon;
dbcon = db.connectdb();
dbcon.Open();
String sql = "select username from account";
OleDbDataAdapter da;
System.Data.DataSet dset = new System.Data.DataSet();
System.Data.DataTable dt;
da = new System.Data.OleDb.OleDbDataAdapter(sql, dbcon);
da.Fill(dset);
dt = dset.Tables[0];
Label1.Text = (String)dt.Rows[0]["username"];
bindata();
}
else
{
}
//bindata();
}
}
protected void bindata()
{
OleDbConnection dbcon;
String sql;
OleDbDataAdapter da;
System.Data.DataSet dset = new System.Data.DataSet();
System.Data.DataTable dt;
clsdb db = new clsdb(Convert.ToString(Session["sql"]));
dbcon = db.connectdb();
dbcon.Open();
//sql = "select (select count(line_name) from dt_line as a where b.line_name >= a.line_name),b.line_name from dt_line as b Order by b.line_name";
sql = "select * from dt_line Order by line_name";
da = new System.Data.OleDb.OleDbDataAdapter(sql, dbcon);
da.Fill(dset);
dt = dset.Tables[0];
if (dt.Rows.Count == 0)
{
Label2.Visible = true;
Label2.Text = "No List Line Name";
}
//----------- cell seqance
gv_line.RowDataBound += new GridViewRowEventHandler(gv_rowdatabound);
//-----------
gv_line.DataSource = dset;
gv_line.DataBind();
da = null;
dset = null;
dt = null;
db.closedb();
}
protected void gv_rowdatabound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[0].Text = Convert.ToString(e.Row.RowIndex + (gv_line.PageSize * gv_line.PageIndex) + 1);
}
}
protected void showcom(Object s, GridViewPageEventArgs e)
{
gv_line.PageIndex = e.NewPageIndex;
bindata();
}
protected void rowdatabound(Object s, GridViewRowEventArgs e)
{
Label Expr1000 = (Label)(e.Row.FindControl("Expr1000"));
if (Expr1000 != null)
{
Expr1000.Text = Convert.ToString(DataBinder.Eval(e.Row.DataItem, "Expr1000"));
}
Label line_no = (Label)(e.Row.FindControl("line_no"));
if (line_no != null)
{
line_no.Text = (String)DataBinder.Eval(e.Row.DataItem, "line_no");
}
Label line_name = (Label)(e.Row.FindControl("line_name"));
if (line_name != null)
{
line_name.Text = (String)DataBinder.Eval(e.Row.DataItem, "line_name");
}
}
protected void commandgv(Object s, GridViewCommandEventArgs e)
{
String sql;
clsdb db = new clsdb(Convert.ToString(Session["sql"]));
OleDbConnection dbcon;
dbcon = db.connectdb();
dbcon.Open();
if ((String)e.CommandName == "delv")
{
sql = "select * from dt_report where line_no = (select line_no from dt_line where line_no ='" + gv_line.DataKeys[Convert.ToInt16(e.CommandArgument)].Value + "')";
OleDbDataAdapter da = new OleDbDataAdapter(sql, dbcon);
System.Data.DataSet dset = new System.Data.DataSet();
da.Fill(dset);
if (dset.Tables[0].Rows.Count == 0)
{
sql = "Delete * from dt_line where line_no = '" + gv_line.DataKeys[Convert.ToInt16(e.CommandArgument)].Value + "'";
OleDbCommand cmd = new OleDbCommand(sql, dbcon);
cmd.ExecuteNonQuery();
cmd.Dispose();
cmd = null;
bindata();
//Response.Redirect("line.aspx");
}
else
{
L_error_del.Visible = true;
L_error_del.Font.Size = 10;
L_error_del.ForeColor = System.Drawing.Color.Red;
L_error_del.Text = "Line no. : " + gv_line.DataKeys[Convert.ToInt16(e.CommandArgument)].Value +
" is in Report SCAP Job no. ";
for (int i = 0; i < dset.Tables[0].Rows.Count; i++)
{
if ((i + 1) == dset.Tables[0].Rows.Count)
{
L_error_del.Text += (String)dset.Tables[0].Rows[i]["job_no"] + " ";
}
else
{
L_error_del.Text += (String)dset.Tables[0].Rows[i]["job_no"] + ", ";
}
}
L_error_del.Text += ".You Should Delete Report SCAP this has the Line no.";
link_ngreport.Visible = true;
}
}
else if ((String)e.CommandName == "editv")
{
Session["value"] = gv_line.DataKeys[Convert.ToInt16(e.CommandArgument)].Value;
Response.Redirect("edit_line.aspx");
}
else
{
}
}
Tag : - - - -
|
|
|
|
|
|
Date :
2010-04-21 13:39:21 |
By :
zicxnals |
View :
1981 |
Reply :
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ลอง debug ทีละ step อ่ะได้แฮะ แต่ให้ run ปกติ กลับไม่ refresh งง อ่ะครับ
|
|
|
|
|
Date :
2010-04-21 14:17:47 |
By :
zicxnals |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
กระซิบๆ asp.net ไม่มี datagridview นะ มีแต่ gridview
|
|
|
|
|
Date :
2010-04-21 15:37:04 |
By :
tungman |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
อ่ะครับ ผมทำได้แหละละครับ ไม่ได้ close connecting ตัวแรกก่อนเลยไม่ refresh ให้ งง อยู่ตั้งนาน
|
|
|
|
|
Date :
2010-04-21 16:03:44 |
By :
zicxnals |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|