我有一个带有文本项模板的网格,用于将数据从网格插入到数据库中。我必须在运行时制作一些公式而不回发页面任何人都可以帮助我在哪个事件中我能做到这一点我的代码是下面的。
For Each gvRow2 As GridViewRow In GridView1.Rows
Dim txtNetWt As TextBox = CType(gvRow2.FindControl("txtNetWt"), TextBox)
Dim txtGrossWt As TextBox = CType(gvRow2.FindControl("txtGrossWt"), TextBox)
Dim txtTareWt As TextBox = CType(gvRow2.FindControl("txtTareWt"), TextBox)
txtNetWt.Text = Val(txtGrossWt.Text) - Val(txtTareWt.Text)
Next
答案 0 :(得分:0)
您可以使用Asp.Net Ajax扩展控件甚至更好的jQuery。看看代码 - JavaScript的工作原理:
标记:
<head runat="server">
<title></title>
<script type="text/javascript">
function doThat(cells) {
var result = parseFloat(cells.childNodes[1].value) + parseFloat(cells.childNodes[3].value);
if (!isNaN(result))
cells.childNodes[5].value = result;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:TextBox ID="TextBox1" onchange="doThat(this.parentNode)" runat="server">
</asp:TextBox>
<asp:TextBox ID="TextBox2" onchange="doThat(this.parentNode)" runat="server">
</asp:TextBox>
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</form>