我在Textbox
中有一个GridView
如果文本框中的文本已更改,我想更改Label.Text。但是我无法调用用.cs页编写的javascript函数。 TbUnitCost_TextChanged
方法中是否有任何错误。
这是我的aspx页面
<ItemTemplate>
<asp:TextBox Style="text-align: right" ID="TbUnitCost" runat="server" Width="80px" Text='<%#Bind("Unit_Cost")%>' AutoPostBack="true" OnTextChanged="TbUnitCost_TextChanged" TextMode="Number"></asp:TextBox>
</ItemTemplate>
Page后面的代码如下
protected void TbUnitCost_TextChanged (object sender, EventArgs e)
{
GridViewRow currentRow = (GridViewRow)((TextBox)sender).Parent.Parent;
int rowNo = currentRow.RowIndex;
string gridName = "GridWorkExpenses";
TextBox tbunitCost = (TextBox)currentRow.FindControl("TbUnitCost");
int row = Convert.ToInt32(tbunitCost.Text);
tbunitCost.Attributes.Add("onchange","javascript:calculateTotalCost('"+rowNo+"','"+gridName+"');");
}
而javascript函数是:
<script type ="text/javascript">
function calculateTotalCost(rowNo, GridName) {
if (GridName== 'GridWorkExpenses') {
var rowscount = document.getElementById('<%=GridWorkExpensesSheet.ClientID%>').rows.length;
return calculateTotalUnitCost("GridWorkExpensesSheet", rowscount,rowNo);
}
}
</script>
最佳答案
尝试使用此:
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Script", "CalculateTotalCost", true);
描述任何进一步的问题(如果有)。