使用javascript访问Gridview单元格 [英] Gridview cell access using javascript

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

问题描述

我在asp页面中有一个如下所示的gridview控件,并显示userdetails中的图片和用户名。现在的问题是,当我点击gridview中的任何用户名时,我如何获得用户名。也许使用javascript或c#代码。不要使用任何命令字段或任何其他控件。只需单击gridview并在另一个文本框中显示用户名。请尽快帮助我。有没有人可以帮助我?

I have a gridview control like following in the asp page and shows the picture and username from the userdetails. now question is how can i get the username when i click when i click on any of the username in the gridview. Maybe used javascript or c# code. Dont use any command field or any other control. just click on the gridview and show the username in another textbox. please help me as soon as possible.is there any one can help me?

<asp:gridview id="gv" showheader="false">
<columns>
  <templatefield>
        <itemtemplate>
            <asp:image runat="Server" imageurl='<%# Eval("pictpath") %>'/>
        </itemtemplate>
  </templatefield>
    <templatefield>
        <itemtemplate>
            <asp:Label runat="server" text='<%% Eval("username") %>'/>
        </itemtemplate>
    </templatefield>
</columns>

已添加代码块[ /编辑]

Code block added[/Edit]

推荐答案

asp.net网格视图渲染html表。所以当你使用javascript然后你应该travase html表。以下代码spinet将帮助您理解该过程。

asp.net grid view render html table. So when you use javascript then you should travase html table. The following code spinet will help you to understand the process.
<head runat="server">
    <title></title>
    <script src="jquery.min.js"></script>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <asp:gridview id="gv" showheader="false" runat="server" autogeneratecolumns="False" name="grdData" xmlns:asp="#unknown">
                <columns>
                    <asp:templatefield>
                        <itemtemplate>
                            <asp:image id="imgPicPath" runat="Server" alternatetext="Missing" imageurl="<%# Eval("pictpath") %>" />
                        </itemtemplate>
                    
                    <asp:templatefield>
                        <itemtemplate>
                            <asp:label id="lblUserName" runat="server" text="<%# Eval("username") %>" />
                        </itemtemplate>
                    
                     <asp:templatefield>
                        <itemtemplate>
                            <asp:label id="lblUserId" runat="server" text="<%# Eval("Id") %>" />
                        </itemtemplate>
                    
                </columns>            
        </div>
        <input type="button" id="btnShow" value="show" onclick="showGrid();"/>
    </form>
    </script>
</body>



< script type =text / javascript>


<script type="text/javascript">

function showGrid() {
           var tbl =


[id
("[id


= GV]);
var rows = tbl.find(' TR');
for var index = 0 ; index< rows.length; index ++){
var row = rows [index];

var image =
=gv]"); var rows = tbl.find('tr'); for (var index = 0; index < rows.length; index++) { var row = rows[index]; var image =


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

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