如何判断DataGrid里的某一行被选了? 如何判断DataGrid里的某一行被选了? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 DataGrid.CurrentRowIndex获取或设置选定行的索引 我写的一个:在这个函数里:private void MyDataGrid_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e){ //////////////////配合前台脚本实现鼠标移动到每行上变颜色和点击没列的头上是会变颜色即而实现隐藏列 e.Item.ID="dg"+e.Item.Cells[0].Text.ToString(); if(e.Item.ItemIndex>=0) { e.Item.Attributes.Add("onmouseover","ItemSet(this)");//////在每行上增加脚本处理 } else { for(int i=0;i<e.Item.Cells.Count;i++) { e.Item.Cells[i].ID="dg"+i; e.Item.Cells[i].Attributes.Add("onclick","CellsSet(this,'"+(i+1)+"')");//////在每列的头上增加脚本处理 } } /////////////////////}前台的脚本:<script language="javascript">if (!objbeforeItem){ var objbeforeItem=null; var objbeforeItembackgroundColor=null;}function ItemSet(obj){ if(objbeforeItem) { objbeforeItem.style.backgroundColor=objbeforeItembackgroundColor; } objbeforeItembackgroundColor=obj.style.backgroundColor; obj.style.backgroundColor="#92d4fe"; objbeforeItem=obj;}if (!objbefore){ var objbefore=null;}function CellsSet(obj,cellId){ if(objbefore) { objbefore.style.backgroundColor=""; } obj.style.backgroundColor="#92d4fe"; objbefore=obj; }</script>结合脚本,当鼠标移动到一行上时,这一行就变颜色,另外点击头行的列时也变颜色,也可以在脚本中写自己的处理 如果是Windows Form下。or(int i = 0;i < dataGrid1.VisibleRowCount;i++) { if(this.dataGrid1.IsSelected(i)) {//选中 } } http://community.csdn.net/Expert/topic/3896/3896149.xml?temp=.5940821 c#播放器 130万数据,报内存溢出,怎么优化。 请问这个sql中的update语句的执行顺序是怎样的?谢谢! 还是关于excel操作的问题 一个关于消息回复的设计问题 类的初始化赋值问题 C#做的网页,通过IIS发布以后,无法连接数据了;在开发环境是可以连的,这是什么原因? 上海科泰世纪的笔试题,大家看看! c# combobox控件问题。。。。。。。。。。。。。。。。。。。。。。。。。。 疑难问题,敬请高手关注----怀疑是asp.net的bug 用vs.net做安装程序时.如何才能不点完成就能让安装程序安装完后会自动关闭? 100分,在C# 中怎样实现接收邮件并保存附件?
获取或设置选定行的索引
private void MyDataGrid_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
//////////////////配合前台脚本实现鼠标移动到每行上变颜色和点击没列的头上是会变颜色即而实现隐藏列
e.Item.ID="dg"+e.Item.Cells[0].Text.ToString();
if(e.Item.ItemIndex>=0)
{
e.Item.Attributes.Add("onmouseover","ItemSet(this)");//////在每行上增加脚本处理
}
else
{
for(int i=0;i<e.Item.Cells.Count;i++)
{
e.Item.Cells[i].ID="dg"+i;
e.Item.Cells[i].Attributes.Add("onclick","CellsSet(this,'"+(i+1)+"')");//////在每列的头上增加脚本处理
}
}
/////////////////////
}前台的脚本:
<script language="javascript">
if (!objbeforeItem)
{
var objbeforeItem=null;
var objbeforeItembackgroundColor=null;
}
function ItemSet(obj)
{
if(objbeforeItem)
{
objbeforeItem.style.backgroundColor=objbeforeItembackgroundColor;
}
objbeforeItembackgroundColor=obj.style.backgroundColor;
obj.style.backgroundColor="#92d4fe";
objbeforeItem=obj;
}if (!objbefore)
{
var objbefore=null;
}
function CellsSet(obj,cellId)
{
if(objbefore)
{
objbefore.style.backgroundColor="";
}
obj.style.backgroundColor="#92d4fe";
objbefore=obj; }
</script>结合脚本,当鼠标移动到一行上时,这一行就变颜色,另外点击头行的列时也变颜色,
也可以在脚本中写自己的处理
or(int i = 0;i < dataGrid1.VisibleRowCount;i++)
{
if(this.dataGrid1.IsSelected(i))
{
//选中
}
}