gridview的每行添加了3个textbox,想前两个textbox值输入完后,点一下第三个就能求出和。
还有我想用textbox显示出数据库的某一字段的内容,怎么绑定。不用数据源控件的,用代码绑定,我做的是三层架构的。
大家帮帮忙,急!!!谢谢了先。
还有我想用textbox显示出数据库的某一字段的内容,怎么绑定。不用数据源控件的,用代码绑定,我做的是三层架构的。
大家帮帮忙,急!!!谢谢了先。
调试欢乐多
this.textbox3.text=(Double.parse(textbox1.text.toString())+Double.parse(textbox1.text.toString())).toString();2.不用数据源控件的话,你可以将数据查找出来啊,之后给textbox赋值。
dataset ds=new dataset();
ds=数据源;this.gridview.DataSource=ds;
this.gridview.datakeyname=new string[]{"主键字段"};
this.gridview.databind();前台
<asp:textbox runat="server"><%#Eval("字段名称")%></text>
ObjectDataSource
指定你的逻辑层的类和方法
以后和原来的一样
一楼的朋友,我本来有个脚本可以实现的,但是把三个都放到gridview中后,根本不晓得如何触发第三个textbox,我在后台代码理都不晓得如何获取它,我对脚本一点都不懂得。求帮助
function Operator() {
var AttendanceScore = document.getElementById("TxtAttendance").value;
var TestScore = document.getElementById("TxtTest").value;
document.getElementById("AverageScore").value = (AttendanceScale * AttendanceScore + TestScale * TestScore).toFixed(0);
}
后台代码里面的调用:
this.AverageScore.Attributes.Add("onclick", "Operator()");TxtText 和 TxtAttendance 是前两个textbox的ID,AverageScore是第三个的,现在我就是不知道如何获取gridview中textbox的值,还有在后台怎么给第三个textbox增加onclick事件,挑用Operator()
这个在body里面是实现没有问题的。大家帮忙看看
{
var basewage=document.getElementById("txtbasewage").value;
var positionwage=document.getElementById("txtpositionwage").value;
if(positionwage=='')
{
positionwage=0;
}
var bonus=document.getElementById("txtbonus").value;
if(bonus=='')
{
bonus=0;
}
var withhold=document.getElementById("txtwithhode").value;
if(withhold=='')
{
withhold=0;
}
var beforetax=document.getElementById("txtbeforetax");
if(beforetax=='')
{
beforetax=0;
}
var taxbate=document.getElementById("txttaxbate").value;
if(taxbate=='')
{
taxbate=0;
}
var aftertax=document.getElementById("txtaftertax");
if(aftertax=='')
{
aftertax=0;
}
var count1 =document.getElementById("txtcount1").value;
if(count1=='')
{
count1=0;
}
var money1 =document.getElementById("txtmoney1").value;
if(money1=='')
{
money1=0;
}
var count2 =document.getElementById("txtcount2").value;
if(count2=='')
{
count2=0;
}
var money2 = document.getElementById("txtmoney2").value;
if(money2=='')
{
money2=0;
}
var count3=document.getElementById("txtcount3").value;
if(count3=='')
{
count3=0;
}
var money3=document.getElementById("txtmoney3").value;
if(money3=='')
{
money3=0;
}
var count4 =document.getElementById("txtcount4").value;
if(count4=='')
{
count4=0;
}
var money4 =document.getElementById("txtmoney4").value;
if(money4=='')
{
money4=0;
}
var count5 =document.getElementById("txtcount5").value;
if(count5=='')
{
count5=0;
}
var money5 =document.getElementById("txtmoney5").value;
if(money5=='')
{
money5=0;
}
var LabTotal= document.getElementById("txttotlewage");
var s1=0,s2=0,s3=0,s4=0,s5=0;
s1=count1*money1;
s2=count2*money2;
s3=count3*money3;
s4=count4*count4;
s5=count5*count5;
var Stotle=parseFloat(s1)+parseFloat(s2)+parseFloat(s3)+parseFloat(s4)+parseFloat(s5);
LabTotal.innerText=Stotle;
var beforetotle=0;
beforetotle=parseFloat(basewage)+parseFloat(positionwage)+parseFloat(bonus)-parseFloat(withhold)-parseFloat(Stotle);
beforetax.innerText=beforetotle;
aftertax.innerText=parseInt(beforetotle)-(parseInt(beforetotle)*(parseInt(taxbate)/100.00));
}多个文本框求和
请问js中,如果"TxtAttendance"是gridview模板列中的控件也可以取到它的值吗
foreach (GridViewRow rows in gv.Rows)
{
TextBox txtbox3= ((TextBox)rows.FindControl("txtbox3"));
TextBox txtbox1= ((TextBox)rows.FindControl("txtbox1"));
TextBox txtbox2= ((TextBox)rows.FindControl("txtbox2"));
txtbox3.Attributes.Add("onclick", "plus(" + txtbox1.ClientID + "," + txtbox2.ClientID + "," + txtbox3.ClientID + ")");
}
页面js
function plus(first,second,aim)
{ if(first.value==""&&first.value=="0")
{
return;
}
if(second.value=="")
{
return;
}
aim.value = first.value+second.value;
}楼主按我的写,应该没错
{
if(first.value==""&&first.value=="0") { return; }
if(second.value=="") { return; }
aim.value = first.value+second.value;
}
function Operator() {
//获取第一个文本框的值
var TxtAttendance = parseInt(document.getElementById("TxtAttendance").value);
//获取第二个文本框的值
var TxtTest = parseInt(document.getElementById("TxtTest").value);
//给第三个文本框赋值,前提是获取第三个文本框的ID(假设第三个文本框ID为txt)
document.getElementById("txt").value = (TxtAttendance + TxtTest).toFixed(0);
}
后台操作for (int i = 0; i < GridView1.Rows.Count; i++)
{
//获取第三个文本框
TextBox txt = GridView1.Rows[i].FindControl("txt") as TextBox;
//添加处理事件
txt.Attributes.Add("onclick", "Operator()");
}
2、用textbox显示出数据库的某一字段的内容,前台
<asp:TextBox ID="TextBox1" runat="server" Text='<%# GetValue() %>'></asp:TextBox>public string GetValue()
{
string sql = "select 某一字段 from 表 where 条件";
DataTable dt = DBConnection.GetDataSet(sql);
if (dt != null && dt.Rows.Count > 0)
{
return dt.Rows[0]["字段名"].ToString();
}
else
{
return "";
}
}