写入gridview单元格 [英] Write to gridview cell

查看:95
本文介绍了写入gridview单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有一个asp.net grdview,我希望能够用javascript编写,但我希望能够单独写入每个单元格  ;

i have a asp.net grdview that i want to be able to write to in javascript but i want to be able to write to each cell indivdually 

现在写了我已经把它写成了这样的每个单元格

write now ive got it to write the samething to every cell like this

<asp:TemplateField HeaderText="test"> 
                <ItemTemplate> 
                    <asp:LinkButton ID="LinkButton2"  onfocusin="focused(this)" runat="server" OnClick="LinkButton1_Click" onkeyup="enter(this,2)"> <%#  Eval("column2")  %>   <script>
                                                                                                                                                                                   
                                                                                                                                                                                      // var c = document.getElementById("GridView3").rows[1].cells[1].innerText;
                                                                                                                                                                                      // var d = document.getElementById("GridView3").rows[1].cells[0].innerText;
                                                                                                                                                                                  // document.getElementById("GridView3").rows[1].cells[1].value = "testing";
                                                                                                                                                                                      
                                                                                                                                                                                           document.write(".        ." );
                                                                                                                                                                                               
                                                                                                                                                                                       
                                                                                                                                                                                   
                             </script>  </asp:LinkButton>
<%--                    <asp:TextBox ID="TextBox2" onfocus="this.select();" Text='<%# Eval("column2") %>' AutoPostBack="True" OnTextChanged ="GridView2_TextChanged2"  onkeyup="enter(this,2)"  runat="server"></asp:TextBox> --%>
                </ItemTemplate> 
            </asp:TemplateField> 

推荐答案

确保我的观点正确。

to make sure that i got your point right.

你有一个网格视图,其中有一个链接按钮,一旦点击你想使用javascript在单元格上写一些值。

you have a grid view in which there is a linkbutton, once clicked you want to write some values on the cell using javascript.

如果是这样,你可以在链接按钮上执行以下操作

if so you can do the following

添加属性onclick =" ; writeToCell(this)"

on the linkbutton add the attribute onclick="writeToCell(this)"

function writeToCell(lnk){
if (lnk == undefined)
{
var e = window.event
lnk = e.srcElement || e.target;
}
var parentCell = getParentCell(lnk);
//you may  use this of innerText ( chrome and FF doesn't support)
parentCell.appendChild(document.createTextNode("your text"));
}

function getParentCell(obj){
if(obj.nodeName == "TD")
return obj;

getParentCell(obj.parentNode);
}


如果要写入多个单元格,可以通过更改函数getParentCell中的检查来获取父行,以验证nodeName =="TR" ;然后在单元格内循环并写下你的内容。



if you want to write to more than one cell, you can get the parent row by change the check in the function getParentCell to validate the nodeName =="TR" then loop inside the cells and write your content.



这篇关于写入gridview单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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