update ค่าไม่วนรอบ โชว์แต่รอบแรก ค่ะ ทำให้ update ไม่ได้ asp.net c#
เอา code มาทั้งหมดดีกว่าครับ
Date :
2011-04-22 12:06:12
By :
webmaster
นี่คือ code ทั้งหมด ค่ะ
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
BindData();
}
}
void BindData()
{
string StrFO = WebConfigurationManager.ConnectionStrings["BaseMungthai"].ToString();
SqlConnection Conn = new SqlConnection(StrFO);
Conn.Open();
string sqlFO2;
sqlFO2 = " SELECT tbDCusCardS.CardSNo, tbMAO.AoCode, tbMAO.AoName, tbMAgent.AgentCode, tbMAgent.AgentName, tbMCardS.SaveDate, tbDCusCardS.AmtPeroid, tbDCusCardS.DocuMentNo, tbDCusCardS.CusName, tbDCusCardS.CusSurName FROM tbDCusCardS INNER JOIN tbMAgent ON tbDCusCardS.AgentID = tbMAgent.AgentID INNER JOIN tbMCardS ON tbDCusCardS.CardFID = tbMCardS.CardFID INNER JOIN tbMAO ON tbMAgent.AoID = tbMAO.AoID WHERE tbDCusCardS.CardSNo ='" + Request.QueryString["CardSNo"] + "' ";
SqlDataAdapter da = new SqlDataAdapter(sqlFO2, Conn);
this.LNo00101.Text = Request.QueryString["CardSNo"];
Conn.Close();
///////
string StrConn2 = WebConfigurationManager.ConnectionStrings["BaseMungthai"].ToString();
SqlConnection Conn2 = new SqlConnection(StrConn2);
Conn2.Open();
string sqlProduct2;
sqlProduct2 = " SELECT tbDCusCardS.CardFID,tbDCusCardS.CardSNo, tbDCusCardS.WorkType, tbDCusCardS.DocuMentNo, tbMAgent.AgentCode, tbMAgent.AgentName, tbDCusCardS.CusName, tbDCusCardS.CusSurName, tbDCusCardS.TempID, tbDCusCardS.TempDate, tbDCusCardS.AmtPeroid, tbDCusCardS.Status, tbDCusCardS.Grounding FROM tbDCusCardS INNER JOIN tbMAgent ON tbDCusCardS.AgentID = tbMAgent.AgentID WHERE tbDCusCardS.CardSNo= '" + LNo00101.Text + "' ";
SqlDataAdapter da2 = new SqlDataAdapter(sqlProduct2, Conn2);
DataSet ds2 = new DataSet();
da2.Fill(ds2, "tbDCusCardS");
GridFO11.DataSource = ds2.Tables["tbDCusCardS"];
GridFO11.DataBind();
Conn2.Close();
}
// อันนี้คือ code ให้ โชว์ใน Girdview
protected void GridFO11_RowDataBound(Object s, GridViewRowEventArgs e)
{
//*** Hyperlink_WorkType ***//
HyperLink HF011 = (HyperLink)(e.Row.FindControl("HF011"));
if (HF011 != null)
{
// HF011.Text = (string)DataBinder.Eval(e.Row.DataItem, "WorkType");
HF011.NavigateUrl = "FO_0010101.aspx?CardSNo=" + (string)DataBinder.Eval(e.Row.DataItem, "CardSNo");
}
//*** Hyperlink_DocuMentNo ***//
HyperLink HF012 = (HyperLink)(e.Row.FindControl("HF012"));
if (HF012 != null)
{
//HF012.Text = (string)DataBinder.Eval(e.Row.DataItem, "DocuMentNo");
HF012.NavigateUrl = "FO_0010101.aspx?CardSNo=" + (string)DataBinder.Eval(e.Row.DataItem, "CardSNo");
}
//*** Hyperlink_AgentCode ***//
HyperLink HF013 = (HyperLink)(e.Row.FindControl("HF013"));
if (HF013 != null)
{
// HF013.Text = (string)DataBinder.Eval(e.Row.DataItem, "AgentCode");
HF013.NavigateUrl = "FO_0010101.aspx?CardSNo=" + (string)DataBinder.Eval(e.Row.DataItem, "CardSNo");
}
//*** Hyperlink_AgentCode ***//
HyperLink HF014 = (HyperLink)(e.Row.FindControl("HF014"));
if (HF014 != null)
{
//HF014.Text = (string)DataBinder.Eval(e.Row.DataItem, "AgentName");
HF014.NavigateUrl = "FO_0010101.aspx?CardSNo=" + (string)DataBinder.Eval(e.Row.DataItem, "CardSNo");
}
//*** Hyperlink_AgentName ***//
HyperLink HF015 = (HyperLink)(e.Row.FindControl("HF015"));
if (HF015 != null)
{
// HF015.Text = (string)DataBinder.Eval(e.Row.DataItem, "CusName") + "" + (string)DataBinder.Eval(e.Row.DataItem, "CusSurName");
HF015.NavigateUrl = "FO_0010101.aspx?CardSNo=" + (string)DataBinder.Eval(e.Row.DataItem, "CardSNo");
}
//*** Hyperlink_TempID ***//
HyperLink HF016 = (HyperLink)(e.Row.FindControl("HF016"));
if (HF016 != null)
{
// HF016.Text = Convert.ToString(DataBinder.Eval(e.Row.DataItem, "TempID"));
HF016.NavigateUrl = "FO_0010101.aspx?CardSNo=" + (string)DataBinder.Eval(e.Row.DataItem, "CardSNo");
}
//*** Hyperlink_TempID ***//
HyperLink HF017 = (HyperLink)(e.Row.FindControl("HF017"));
if (HF017 != null)
{
// HF017.Text = Convert.ToString(DataBinder.Eval(e.Row.DataItem, "TempDate"));
HF017.NavigateUrl = "FO_0010101.aspx?CardSNo=" + (string)DataBinder.Eval(e.Row.DataItem, "CardSNo");
}
//*** Hyperlink_TempID ***//
HyperLink HF018 = (HyperLink)(e.Row.FindControl("HF018"));
if (HF018 != null)
{
// HF018.Text = Convert.ToString(DataBinder.Eval(e.Row.DataItem, "AmtPeroid"));
HF018.NavigateUrl = "FO_0010101.aspx?CardSNo=" + (string)DataBinder.Eval(e.Row.DataItem, "CardSNo");
}
}
// จะให้ update ค่ะ
protected void Button2_Click(object sender, EventArgs e)
{
int i;
LNoFO.Text = "";
LDocFO.Text = "";
LSta.Text = "";
LRe.Text = "";
LSe.Text = "";
//update
string StrConn3 = WebConfigurationManager.ConnectionStrings["BaseMungthai"].ToString();
SqlConnection Conn3 = new SqlConnection(StrConn3);
System.Data.SqlClient.SqlCommand objCmd;
Conn3.Open();
string sqlProduct3;
for (i = 0; i <= GridFO11.Rows.Count-1 ; i++)
{
HyperLink LDocFO2 = (HyperLink)GridFO11.Rows[i].FindControl("HF012");
DropDownList DropDownList1 = (DropDownList)this.GridFO11.Rows[i].FindControl("DropDownList1");
//Textarea
System.Web.UI.HtmlControls.HtmlTextArea TextArea1 = (System.Web.UI.HtmlControls.HtmlTextArea)this.GridFO11.Rows[i].FindControl("TextArea1");
string TextArea2 = TextArea1.Value;
//Display the value
Label lblDisplayValue = new Label();
lblDisplayValue.Text = TextArea2;
LNoFO.Text = LNoFO.Text + "<br>" + LNo00101.Text;
LDocFO.Text = LDocFO.Text + "<br>" + LDocFO2.Text;
LSta.Text = LSta.Text + "<br>" + DropDownList1.Text;
LRe.Text = LRe.Text + "<br>" + lblDisplayValue.Text;
if (this.RadioButton1.Checked == true)
{
this.LSe.Text = this.LSe.Text + "<br>" + "สมบูรณ์ทั้งหมด";
}
if (this.RadioButton2.Checked == true)
{
this.LSe.Text = this.LSe.Text + "<br>" + "ไม่สมบูรณ์ทั้งหมด";
}
if (this.RadioButton3.Checked == true)
{
this.LSe.Text = this.LSe.Text + "<br>" + "ไม่สมบูรณ์เฉพาะบางรายการ";
}
sqlProduct3 = "UPDATE tbDCusCardS SET" +
" Status= '" + LSta.Text + "'" +
// "Grounding = '" + LRe.Text + "' " +
" WHERE CardSNo ='" + LNoFO.Text + "' and DocuMentNo ='" + LDocFO.Text + "' ";
// sqlProduct3 = "UPDATE tbDCusCardS SET Status= 'LSta.Text' WHERE CardSNo ='LNoFO.Text' and DocuMentNo ='LDocFO.Text'";
SqlCommand cmd = new SqlCommand();
SqlDataAdapter da3 = new SqlDataAdapter(sqlProduct3, Conn3);
objCmd = new System.Data.SqlClient.SqlCommand();
objCmd.Connection = Conn3;
objCmd.CommandType = CommandType.Text;
objCmd.CommandText = sqlProduct3;
objCmd.ExecuteNonQuery();
// SqlCommand cmdDel = new SqlCommand(sqlProduct3, Conn3);
// cmdDel.ExecuteNonQuery();
}
Conn3.Close();
}
}
Date :
2011-04-25 09:54:15
By :
mushroomsn
ผมลองดูแล้ว GridFO11.Rows.Count ไม่ได้มีปัญหาอะไรนะครับ
คิดว่าน่าจะเป็นตรงจุดอื่นหรือป่าวครับ
Date :
2011-04-25 13:59:47
By :
mi16
Load balance : Server 00