`
modabobo
  • 浏览: 510023 次
文章分类
社区版块
存档分类
最新评论

用JQuery获取AspxGridView单元格的值

 
阅读更多

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

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();
}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics