GridView里的文本框改变事件

<asp:TemplateField HeaderText="实收数量">
<ItemTemplate>
<asp:TextBox ID="txtorgqty" runat="server" Text='<%# string.Format("{0:0.##}",Eval("orgqty")) %>'
Width="100px" Visible="false" AutoPostBack="true" OnTextChanged="txtorgqty_TextChanged"></asp:TextBox>
<%-- <asp:CheckBox ID="cbGV" runat="server" Enabled='<%# ViewState["DocnoStatus"].ToString()=="OP"?true:false %>' AutoPostBack="true" oncheckedchanged="ItemCheckBox_CheckedChanged" /> --%>

<asp:Label ID="lblorgqty" runat="server" Text='<%# string.Format("{0:0.##}",Eval("orgqty")) %>'
Visible="true"></asp:Label>
</ItemTemplate>

protected void txtorgqty_TextChanged(object sender, EventArgs e)
{
TextBox txtorgqty = (TextBox)sender;
// Page.ClientScript.RegisterStartupScript(typeof(string), "msg", "<script>alert('触发txtorgqty_TextChanged事件 "+txtorgqty.Text+"!')</script>");

int index = ((GridViewRow)(txtorgqty.NamingContainer)).RowIndex;
GridViewRow row = GridView1.Rows[index];
Label lblacphigh = (Label)row.Cells[11].FindControl("lblacphigh"); //上限(%)
double dacphigh = (double.Parse(lblacphigh.Text.Trim())) / 100;//上限除100后
Label lblqty1 = (Label)row.Cells[9].FindControl("lblqty1"); //待收
double tsqty = (double.Parse(lblqty1.Text.Trim())) * (1 + dacphigh);
if ((double.Parse(txtorgqty.Text.Trim())>tsqty))
{
Page.ClientScript.RegisterStartupScript(typeof(string), "msg", "<script>alert('实收数量超过上限!')</script>");
txtorgqty.Focus();
BtnSave.Enabled = false;
//Session["btnsaveEnabled"] = false;
}
else
{
BtnSave.Enabled = true ;
// Session["btnsaveEnabled"] = true;


}
}

原文地址:https://www.cnblogs.com/buy0769/p/5667812.html