用鼠标点击选中DataGrid其中一条记录,文本控件显示相应条的信息,可以实现吗?

wwch369 2006-10-24 09:45:27
在线等.
...全文
248 3 打赏 收藏 举报
写回复
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
daishengs 2006-10-24
  • 打赏
  • 举报
回复
可以,只要在
private void DataGrid_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemIndex>=0)
{
e.Item.Attributes.Add("onclick","document.all('TextBox1').value='值'");
}
}
wwch369 2006-10-24
  • 打赏
  • 举报
回复
谢谢
悄悄的回来了 2006-10-24
  • 打赏
  • 举报
回复
private void DataGrid_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemIndex>=0)
{
//鼠标放上去DataGrid变色---------------------------------
e.Item.Attributes.Add("onmouseover","MoveOver(this)");
e.Item.Attributes.Add("onmouseout","MoveOut(this)");
//-------------------------------------------------------

//鼠标单击DataGrid变色-----------------------------------
e.Item.Attributes.Add("onclick","Onclick(this)");
//双击修改--------------------------------------
e.Item.Attributes.Add("ondblclick","OnUpdate()");

}
}

//双击修改
function OnUpdate()
{
var objDataGrid,rol,Delcolor;
objDataGrid=document.getElementById("DataGrid");
for(var i=1;i<objDataGrid.rows.length;i++)
{
rol=objDataGrid.rows.item(i);
if(rol.style.backgroundColor=="#6699ff")
{
Delcolor="#6699ff";
//Trim(rol.cells[0].innerText);//DataGrid第0列的值,以此类推

}
}
if(Delcolor!="#6699ff")
{
//提示用户选择记录
}
}


//附带的JS方法
if (!objbeforeItem)
{
var objbeforeItem=null;
var objbeforeItembackgroundColor=null;
var preRow = null; //上一次单击鼠标的对象
}

function MoveOver(CurrentObj)//鼠标放上
{
objbeforeItembackgroundColor=CurrentObj.style.backgroundColor;
CurrentObj.style.cursor="hand";
CurrentObj.style.backgroundColor="#6699ff";
objbeforeItem=CurrentObj;
}

function MoveOut(CurrentObj)//鼠标移开
{
if(objbeforeItem!=preRow)//鼠标移开时判断,单击是否等于当前鼠标所在项
{
objbeforeItem.style.backgroundColor=objbeforeItembackgroundColor;
}
}

function Onclick(CurrentObj) //鼠标单击时改变颜色
{
if(preRow)//判断是否把上一次改变的颜色复位。
{
preRow.style.backgroundColor =objbeforeItembackgroundColor;
}
CurrentObj.style.backgroundColor = "#6699ff";
preRow = CurrentObj;
}
相关推荐
发帖
.NET社区

6.1w+

社区成员

.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
帖子事件
创建了帖子
2006-10-24 09:45
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。