现在的位置: 首页 > 综合 > 正文

用JQuery获取AspxGridView单元格的值

2013年03月17日 ⁄ 综合 ⁄ 共 1016字 ⁄ 字号 评论关闭

丽水市汽车运输集团有限公司信息中心 苟安廷

AspxGridView是大家常用的第三方控件,但客户端操作介绍不多,在工作中,我采用下面的方法通过JQuery获取指定单元格的值,希望对你有所帮助:
function Tools()
{
};
//gridId为AspxGridView的客户端ID,rowIndex为行号,colIndexOrCaption为列号或列名,注意,
//客户端没有字段名,只有列标题,也就是说服务器端的caption
Tools.GetAxGridViewCellValue = function(gridId, rowIndex, colIndexOrCaption)
{
    var colIndex = -1;
    var $Captions = $('#' + gridId + '_DXHeadersRow' + ' td table tr td');
    //排序/过滤等操作后,会在该列列后面加一个单元格显示图标,因此,实际列不能计算进去
    var colTrueIndex = 0;
    //如果传入的标题,先查询列
    if (isNaN(colIndexOrCaption))
    {
        for (var i = 0; i < $Captions.length; i++)
        {
            var strText = $Captions.eq(i).text();
            if (strText == colIndexOrCaption)
            {
                colIndex = colTrueIndex;
                break;
            }
           
            if (strText.length > 0)
                colTrueIndex++;
        }
    }
    else
        colIndex = colIndexOrCaption;

    if (colIndex < 0 || colIndex >= $Captions.length)//无效的列
        return "";
    $td = $('#' + gridId + "_DXDataRow" + rowIndex + ' td').eq(colIndex);
    if ($td == null)
        return "";
    else
        return $td.text();
}

抱歉!评论已关闭.