在一个页面中有一个GRID,它生成的列表中,在每一行都有两个输入框,在其中的一个输入值后,它的值会自动乘以一个数,然后显示到另一个输入框中,如何实现,要不刷新的。
解决方案 »
- 希望大家给推荐本可以提高asp.net的书名
- 【cookies】为什么丢失了
- 求教Oracle rollback问题
- 求助:名称以无效字符开头。处理资源 'http://localhost/book' 时出错。第 1 行,位置: 2
- 如何让动态显示的图片滚动起来?
- 数据邦定
- *****ASP.NET+C#开发的经典OA系统*****
- 请高手指点一下:(.net)Server Error in '/' Application.具体如下
- 想了一年的问题了,那位高手解决一下,源代码见内,程序为什么总报错呢
- 哪位的求职简历能给我看一下,应该怎么写?求一种好的结构写法。最好是DOC文档
- 求救。求救,在本地好好的,发布完放到IIS里就不行了??
- 请教一个伪静态的问题 大侠求教一下!!
function checkInt(o){
theV=isNaN(parseInt(o.value))?0:parseInt(o.value);
if(theV!=o.value){o.value=theV;}
txtTotal.value=txtAmount.value*txtPrice.value;
}
function checkP(o){
theV=isNaN(parseFloat(o.value))?0:parseFloat(o.value);
theV=parseInt(theV*100)/100;
if(theV!=o.value){
theV=(theV*100).toString();
theV=theV.substring(0,theV.length-2)+"."+theV.substring(theV.length-2,theV.length)
o.value=theV;
}
txtTotal.value=txtAmount.value*txtPrice.value;
}
</script>
数量:
<input id=txtAmount value=0 onkeyup="checkInt(this);" onpaste="checkInt(this);" oncut="checkInt(this);" ondrop="checkInt(this);" onchange="checkInt(this);">
单价:
<input id=txtPrice value=0 onkeyup="checkP(this);" onpaste="checkP(this);" oncut="checkP(this);" ondrop="checkP(this);" onchange="checkP(this);" style="border-right-width:0px;margin-right:0px;">
<input style="border-left-width:0px;margin-left:-4px;width:18px" value="¥" readonly>
总价:
<input id=txtTotal value=0 style="border-right-width:0px;margin-right:0px;" readonly>
<input style="border-left-width:0px;margin-left:-4px;width:18px" value="¥" readonly>
如果是单独的好作,关键是它是一个GRID,每一行都有两个输入框,每行的控制每行的。
asp.net会在浏览器端生成不同的ID ,但都是有固定命名规范的,具体不太了解 你可以找下源码看看。。不刷新的话就用JS,局部回传 Ajax也行。。
<head>
<script type="text/javascript">
function upperCase()
{
var x=document.getElementById("fname").value;
document.getElementById("fname1").value=parseInt(x)*5;
}
</script>
</head><body>输入数字:
<input type="text" id="fname" onblur="upperCase()" />
<input type="text" id="fname1" />
</body>
</html>
Jquery做这个还是比较简单给所有的textbox相同的name,给它们绑定change事件通过层次关系,得到值改变值
使用parentNode.parentNode查找到所在的行,然后就可以找到该行的其他输入框了。
DataSourceID="SqlDataSource1">
<Columns>
<ItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("fen") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</asp:GridView>
现在就是在其中的一个输入值后,它的值会自动乘以一个数,然后显示到另一个输入框中
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID" />
<asp:BoundField DataField="Name" HeaderText="Name" />
<asp:TemplateField HeaderText="InputOne">
<ItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" onblur="Caculate(this)"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="InputTwo">
<ItemTemplate>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
<script type="text/javascript">
function Caculate(obj){
if(obj.value.length<=0){
return;
}
var ct = 5;
var PN = obj.parentNode;
while(PN.tagName!="TD")
PN=PN.parentNode;
var nt = PN.nextSibling;
while(nt.tagName!="TD")
nt = nt.nextSibling;
var ntTxt = nt.firstChild;
ntTxt.value = ct*obj.value;
}
</script>
</form>
public partial class GridView : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GridView1.DataSource = GetTable();
GridView1.DataBind();
}
}
public DataTable GetTable()
{
string[] name = { "csdn", "cnblogs", "msdn" };
DataTable dt = new DataTable();
dt.Columns.Add("ID", typeof(int));
dt.Columns.Add("Name", typeof(string));
for (int i = 0; i < name.Length; i++)
{
DataRow row = dt.NewRow();
row[0] = i + 1;
row[1] = name[i];
dt.Rows.Add(row);
}
return dt;
}
protected void Button1_Click(object sender, EventArgs e)
{
foreach (GridViewRow row in GridView1.Rows)
{
TextBox txt = row.FindControl("TextBox2") as TextBox;
if (txt != null)
Response.Write(txt.Text + "<br/>");
}
}
}
{
xiagetext=ParsetInt($(currentDom).next("input").val());
xiagetext*=ParsetInt(currentDom.val());
}
手写的 大体就是这样 做 不知道函数对不对 jquery的 呵呵