使用Ajax页面方法添加gridview行 [英] Add gridview row using Ajax pagemethod

查看:55
本文介绍了使用Ajax页面方法添加gridview行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我是Ajax的新手,

我想在按钮单击时使用javascript/Ajax(页面方法或其他方法)向gridview添加一行(空白行),以使页面无法回发.
并在单击按钮时使用页面方法将gridview的所有行添加到数据库.

你能帮我吗?

提前谢谢.
swapnil

Hello all,

I m new for Ajax,

I want to add a row(blank row) to gridview using javascript/Ajax(page method or else) on button click so that page can not be postback.
And add all rows of gridview to database using page method on button click.

can u plz help me?

Thanks in advance.
swapnil

推荐答案

您不需要使用任何服务器端代码来添加行.默认情况下,gridview呈现为html表,因此您的JavaScript只需要在底部添加另一个tr,例如this

You don''t need to use any server-side code to add a row. The gridview is rendered as a html table by default, so your JavaScript just needs to add another tr, usually at the bottom, such as this

function AddRow()
{


(" ).append("
("#tableID").append("<table><tbody><tr><td>Fill in as necessary<table><tbody><tr><td></td></tr></tbody></table></td></tr></tbody></table>"); }



读取数据可能像这样



Reading the data could be like this

function ReadValues()
{


(" ).each( 功能() { // 在每个td中查找辛醇和值 }); }
("#tableID td").each(function() { // find ocntrol and value in each td }); }



使用AJAX方法从GridView添加数据或从GridView读取数据将不起作用,因为AJAX调用是带外的,并且GridView是服务器控件,需要ASP.NET页面生命周期才能从页面数据或视图状态重构它.



Using an AJAX method to add or read data from a GridView won''t work since the AJAX call is out of band and the GridView is a server control which needs the ASP.NET page lifecyle to reconstitue it from page data or view state.


这篇关于使用Ajax页面方法添加gridview行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆