html代码:
<table id="table1" runat="server">
<tr>
<td>编号</td>
<td>姓名</td>
</tr>
</table>js代码:点击添加按钮执行的脚本
var cell;
var textNode;
tbl= document.getElementById("table1");
rowsLen = tbl.rows.length
row = tbl.insertRow(rowsLen);//给table添加一行
textNode=document.createTextNode(rowsLen);
cell = row.insertCell(0);
cell.appendChild(textNode);
row.appendChild(cell); textNode=document.createTextNode(一个变量的值);
cell = row.insertCell(1);
cell.appendChild(textNode);
row.appendChild(cell); 问题:在添加了几行数据后,怎样把"table1"中的数据取出来放入数据库??
如果直接这样取的话this.table1.Rows.Count总是为1.
我用的是C#,VS2005
谢谢大家帮忙解决~~~~~~
<table id="table1" runat="server">
<tr>
<td>编号</td>
<td>姓名</td>
</tr>
</table>js代码:点击添加按钮执行的脚本
var cell;
var textNode;
tbl= document.getElementById("table1");
rowsLen = tbl.rows.length
row = tbl.insertRow(rowsLen);//给table添加一行
textNode=document.createTextNode(rowsLen);
cell = row.insertCell(0);
cell.appendChild(textNode);
row.appendChild(cell); textNode=document.createTextNode(一个变量的值);
cell = row.insertCell(1);
cell.appendChild(textNode);
row.appendChild(cell); 问题:在添加了几行数据后,怎样把"table1"中的数据取出来放入数据库??
如果直接这样取的话this.table1.Rows.Count总是为1.
我用的是C#,VS2005
谢谢大家帮忙解决~~~~~~
最少我这么做过.我认为.
我认为啊!
你这些js生成的东西,再你取值的时候,点击按钮的时候是一个服务器空间,回发....值都没了!所以是1,猜测而已!
然后在服务器端取Hidden得值就可以了
{
tbl1= document.getElementById("table1");
rowsLen = tbl.rows.length ;
for(i=0;i<rowsLen;i++)
{
alert(tbl.rows[i].cells[0].innerHTML); --得出你现在行里的数据
}
}
if(response.value!=null)
{
document.all("DropDownList2").length=0;
var ds = response.value;
if(ds != null && typeof(ds) == "object" && ds.Tables != null)
{
for(var i=0; i<ds.Tables[0].Rows.length; i++)
{
var newOption=document.createElement("OPTION");
newOption.text=ds.Tables[0].Rows[i].GoodsName;
newOption.value=ds.Tables[0].Rows[i].GoodsName;
document.all("DropDownList2").options.add(newOption);
}
}这是一段dataset和table的js!!,你看看!!
好像楼上几位说的办法都是一样的哦!
就是先用JS把值赋给hidden控件或者变量···然后在去取,
有点不知道赋给变量后怎么在aspx.cs中取值
好像楼上几位说的办法都是一样的哦!
就是先用JS把值赋给hidden控件或者变量···然后在去取,
有点不知道赋给变量后怎么在aspx.cs中取值
如果textbox realonly=true或Enabled=false也不保存viewstage,这时js修改也取不到值。
楼主试试怎么把值存到hiddenField里
或试下Request.Params["controlId"](我没试这种方法行不行)
但是好像限制100K
如果太大可以把它拆分http://www.wangchao.net.cn/bbsdetail_757581.html
var newOption=document.createElement("option");
newOption.text=paper.value+","+l.value+","+w.value+","+h.value+","+num.value+","+address.value+","+beizu.value;
// alert(newOption.text);
newOption.value=rowsLen;这样怎么会有错误呢
你用ajax.dll控件了吗??
<asp:DropDownList ID="ddlHidden" runat="server">
</asp:DropDownList>
脚本代码
document.getElementById("ddlHiden").options.add(new Option("ddd","dddd"));不知道为什么会出错??
是不是这样一定要建ajax网站才行
很好用的!!
还是要另外建一个ajax 的网站啊
list.options[list.options.length] = new Option("ddd","dddd");
在配置文件里httpHandlers节点写
<add verb="POST,GET" path="ajax/*.ashx" type="Ajax.PageHandlerFactory, Ajax"/>
然后,在app_code里写个类!!
类方法前加[Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.Read)]
那个是可以了。又有问题了啊我每加一条记录的时候就 把那行加到 dropdownList里面······
页面上dropdownList也可以显示所加的记录。
但是
protected void save_Click(object sender, EventArgs e)
{
com.Alert(ddlHidden.Items[0].Value);//显示dropdownList的值
}
的时候会出现错误。还是获取不到值
{
com.Alert(ddlHidden.SelectedItem.Value);//显示dropdownList的值
}
那样不还是取不到值么?如果你不想把内容放到Hidden里面
那就Post数据然后再后台Request.Form 。这样取数据
dropdownlist是服务器控件啊,然后把visble属性设下···然后在aspx.cs中取dropdownList里面的值啊····
它与隐藏控件有什么不同啊
{
}
如果把值加到dropdownList里面
按钮里面不写东西也会出错···
如果不加就不会出错错误提示:
Invalid postback or callback argument. Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.
{
}
如果把值加到dropdownList里面
按钮里面不写东西也会出错···
如果不加就不会出错错误提示:
Invalid postback or callback argument. Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.
换select + runat="server"吧,
让高手看看吧,我以前也看过这个问题