c# gridview中 选定特定值的问题
已知一个Gridview里面有多个列多条记录比如其中一个列是col1如何点击这个列上的具体一个记录比如说这个记录为A弹出新的窗口并且这个新的窗口也是一个Gridview这...
已知一个Gridview
里面有多个列
多条记录
比如其中一个列是 col1
如何点击这个列上的 具体一个记录 比如说这个记录为A
弹出新的窗口
并且这个新的窗口也是一个Gridview
这里查询显示一个与记录A 相关的一组数据 展开
里面有多个列
多条记录
比如其中一个列是 col1
如何点击这个列上的 具体一个记录 比如说这个记录为A
弹出新的窗口
并且这个新的窗口也是一个Gridview
这里查询显示一个与记录A 相关的一组数据 展开
2个回答
展开全部
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{//判断是否是数据行
if (e.Row.RowState == DataControlRowState.Edit)
{ // 编辑状态
//e.Row.Attributes.Remove("onclick");
e.Row.Attributes.Remove("onmouseover");
//e.Row.Attributes.Remove("ondblclick");
e.Row.Attributes.Remove("style");
e.Row.Attributes["title"] = "编辑行";
}
if (e.Row.RowType == DataControlRowType.DataRow)
{
//鼠标移动到某行上,该行变色
// e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#ccddee'");
//鼠标移开后,恢复
//e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor");
//鼠标显示为小手状态
e.Row.Attributes["style"] = "Cursor:hand";
}
}
protected override void Render(HtmlTextWriter writer)
{
// GridView
foreach (GridViewRow row in GridView1.Rows)
{
if (row.RowState == DataControlRowState.Edit)
{ // 编辑状态
//row.Attributes.Remove("onclick");
row.Attributes.Remove("onmouseover");
//row.Attributes.Remove("ondblclick");
row.Attributes.Remove("style");
row.Attributes["title"] = "编辑行";
continue;
}
if (row.RowType == DataControlRowType.DataRow)
{
// 单击事件,为了响应双击事件,需要延迟单击响应,根据需要可能需要增加延迟
// 获取ASP.NET内置回发脚本函数,返回 __doPostBack(<<EventTarget>>, <<EventArgument>>)
// 可直接硬编码写入脚本,不推荐
//row.Attributes["onclick"] = String.Format("javascript:setTimeout(\"if(dbl_click){{dbl_click=false;}}else{{{0}}};\", 1000*0.3);", ClientScript.GetPostBackEventReference(GridView1, "Select$" + row.RowIndex.ToString(), true));
// 双击,设置 dbl_click=true,以取消单击响应
// row.Attributes["ondblclick"] = String.Format("javascript:dbl_click=true;window.location.href='UpdateDepartment.aspx?DepartmentID={0}';", GridView1.DataKeys[row.RowIndex].Value.ToString());
//
row.Attributes["onclick"] = String.Format("javascript:setTimeout(\"if(dbl_click){{dbl_click=false;}}else{{{0}}};\", 1000*0.3);", ClientScript.GetPostBackEventReference(GridView1, "Select$" + row.RowIndex.ToString(), true));
row.Attributes["style"] = "cursor:pointer";
row.Attributes["title"] = "单击选择行,双击打开详细页面";
}
}
base.Render(writer);
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{//设置选中行的颜色
GridView1.SelectedRowStyle.BackColor = Color.FromArgb(222, 110, 222, 210);
}
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{//将GRIDVIEW的第一列,即选择列隐藏
e.Row.Cells[0].Attributes.Add("style", "display:none;");
}
protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
{
this.GridView1.EditIndex = e.NewSelectedIndex;
}
<head runat="server">
<title></title>
<script type="text/javascript">
// 辅助全局变量,指示是否双击
var dbl_click = false;
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" OnRowDataBound="GridView1_RowDataBound" OnRowCreated="GridView1_RowCreated" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" OnSelectedIndexChanging="GridView1_SelectedIndexChanging" runat="server">
</asp:GridView>
</div>
</form>
</body>
</html>
{//判断是否是数据行
if (e.Row.RowState == DataControlRowState.Edit)
{ // 编辑状态
//e.Row.Attributes.Remove("onclick");
e.Row.Attributes.Remove("onmouseover");
//e.Row.Attributes.Remove("ondblclick");
e.Row.Attributes.Remove("style");
e.Row.Attributes["title"] = "编辑行";
}
if (e.Row.RowType == DataControlRowType.DataRow)
{
//鼠标移动到某行上,该行变色
// e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#ccddee'");
//鼠标移开后,恢复
//e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor");
//鼠标显示为小手状态
e.Row.Attributes["style"] = "Cursor:hand";
}
}
protected override void Render(HtmlTextWriter writer)
{
// GridView
foreach (GridViewRow row in GridView1.Rows)
{
if (row.RowState == DataControlRowState.Edit)
{ // 编辑状态
//row.Attributes.Remove("onclick");
row.Attributes.Remove("onmouseover");
//row.Attributes.Remove("ondblclick");
row.Attributes.Remove("style");
row.Attributes["title"] = "编辑行";
continue;
}
if (row.RowType == DataControlRowType.DataRow)
{
// 单击事件,为了响应双击事件,需要延迟单击响应,根据需要可能需要增加延迟
// 获取ASP.NET内置回发脚本函数,返回 __doPostBack(<<EventTarget>>, <<EventArgument>>)
// 可直接硬编码写入脚本,不推荐
//row.Attributes["onclick"] = String.Format("javascript:setTimeout(\"if(dbl_click){{dbl_click=false;}}else{{{0}}};\", 1000*0.3);", ClientScript.GetPostBackEventReference(GridView1, "Select$" + row.RowIndex.ToString(), true));
// 双击,设置 dbl_click=true,以取消单击响应
// row.Attributes["ondblclick"] = String.Format("javascript:dbl_click=true;window.location.href='UpdateDepartment.aspx?DepartmentID={0}';", GridView1.DataKeys[row.RowIndex].Value.ToString());
//
row.Attributes["onclick"] = String.Format("javascript:setTimeout(\"if(dbl_click){{dbl_click=false;}}else{{{0}}};\", 1000*0.3);", ClientScript.GetPostBackEventReference(GridView1, "Select$" + row.RowIndex.ToString(), true));
row.Attributes["style"] = "cursor:pointer";
row.Attributes["title"] = "单击选择行,双击打开详细页面";
}
}
base.Render(writer);
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{//设置选中行的颜色
GridView1.SelectedRowStyle.BackColor = Color.FromArgb(222, 110, 222, 210);
}
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{//将GRIDVIEW的第一列,即选择列隐藏
e.Row.Cells[0].Attributes.Add("style", "display:none;");
}
protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
{
this.GridView1.EditIndex = e.NewSelectedIndex;
}
<head runat="server">
<title></title>
<script type="text/javascript">
// 辅助全局变量,指示是否双击
var dbl_click = false;
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" OnRowDataBound="GridView1_RowDataBound" OnRowCreated="GridView1_RowCreated" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" OnSelectedIndexChanging="GridView1_SelectedIndexChanging" runat="server">
</asp:GridView>
</div>
</form>
</body>
</html>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询