• JavaScript获取GridView控件中选中行的行号和指定列的值


    首先在模板列中添加一个按钮用来选中行,页面有关代码如下:

    <asp:GridView ID="gdview" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None"
                                                Height="176px" Width="380px" OnRowDataBound="gdview_RowDataBound" OnSelectedIndexChanging="gdview_SelectedIndexChanging">
                                                <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
                                                <RowStyle BackColor="#E3EAEB" />
                                                <PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
                                                <SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
                                                <HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
                                                <EditRowStyle BackColor="#7C6F57" />
                                                <AlternatingRowStyle BackColor="White" />
                                                <Columns>
                                                    <asp:TemplateField>
                                                        <ItemTemplate>
    <input id="btnLocation" type="button" value="定位到" onclick="Select()" style="height: 20px" />
                                                        </ItemTemplate>
                                                    </asp:TemplateField>
                                                </Columns>
                                            </asp:GridView>

    脚本代码如下:

    //取得gridview中获取选中行指定列的值
          function Select()
          {
                //获取鼠标点击的元素
                var e=event.srcElement;
                //获取元素所在的行的行号(表头行号从0开始)。注意:parentElement只适用于IE浏览器,而parentNode则符合DOM标准。
                //var rowIndex=e.parentElement.parentElement.rowIndex ;
                var rowIndex=e.parentNode.parentNode.rowIndex ;
                //获取GridView控件
                var gdview=document.getElementById("<%=gdview.ClientID %>");
                //分别获取选定行指定列的值
                var value=gdview.rows(rowIndex).cells(列号).innerText;
          }

  • 相关阅读:
    ArcGis Engine中实现对符号的预览图输出
    重置IE为系统默认浏览器和VS2005的默认浏览器
    符号库制作过程说明
    关于arcgis engine符号库的讨论
    ArcGIS平台上的完美符号化插件方案
    Windows下的所有运行命令,你知多少?
    MapObjects地图填充符号库扩展
    用iframe 自动适应高度
    完美的C++:C++/CLI
    免费顶级CN域名,现在是每天10个
  • 原文地址:https://www.cnblogs.com/zhangzt/p/2192285.html
Copyright © 2020-2023  润新知