点击GridView任意位置,选中所在行
来源:互联网 发布:淘宝租手机 编辑:程序博客网 时间:2024/05/16 06:04
1.在GridView中加入ridiobutton控件
<asp:GridView ID="GridView1" runat="server"
DataSourceID="ObjectDataSource1" SkinID="common" OnRowDataBound="GridView1_RowDataBound">
<Columns>
<asp:BoundField DataField="depId" HeaderText="部门编号" SortExpression="depId"/>
<asp:BoundField DataField="depName" HeaderText="部门名称" SortExpression="depName"/>
<asp:BoundField DataField="principal" HeaderText="负责人" SortExpression="principal"/>
<asp:BoundField DataField="depMemo" HeaderText="备注" SortExpression="depMemo" />
<asp:TemplateField InsertVisible="False">
<ItemTemplate>
<input id='<%#"select_" + DataBinder.Eval(Container, "dataitem.depId")%>' name="select" type="radio" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
2.在GridView的RowDataBound事件里写入变色代码
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DataRowView row = (DataRowView)e.Row.DataItem;
string id = row["depId"].ToString();
e.Row.Attributes.Add("onclick", "select" + id + "checked=true;");
}
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "if(this!=prev){c=this.style.backgroundColor;this.style.backgroundColor='#D8F3C6'}");//当鼠标停留时更改背景色
e.Row.Attributes.Add("onmouseout", "if(this!=prev){this.style.backgroundColor=c}");//当鼠标移开时还原背景色
e.Row.Attributes["style"] = "Cursor:hand";//设置悬浮鼠标指针形状为"小手"
//DataRowView row = (DataRowView)e.Row.DataItem;
//string id = row["depId"].ToString();
//e.Row.Attributes.Add("onclick", "select_" + e.Row.Cells[0].Text + ".checked=true;");
e.Row.Attributes.Add("onclick", "select_" + e.Row.Cells[0].Text + ".checked=true;selectx(this)");
}
}3.在前台js脚本写控制函数
<script language="javascript" type="text/javascript" >
var prev=null;
function selectx(row) /**//*改变选中行的颜色还原为选中行的颜色*/
{
if(prev!=null)
{
prev.style.backgroundColor='#E4F7D8';
}
row.style.backgroundColor='#8EC26F';
prev=row;
}
</script>
- 点击GridView任意位置,选中所在行
- GridView点击任意地方选中
- 扩展GridView实现多选(全选)、点击行任意位置选择行、选中变色、添加双击事件等
- ASP.NET2005 gridview中点击某行的任意位置选中某行 交替效果 变换鼠标手势
- 扩展GridView实现多选(全选)、点击行任意位置选择行、选中变色、添加双击事件等
- 扩展GridView实现多选(全选)、点击行任意位置选择行、选中变色、添加双击事件等
- gridview 点击某行任意位置选择该行
- 在GridView中,中高亮顯示光標所在行
- pl/sql developer不需要选中,执行光标所在行
- GridView的模板列中判断控件所在行
- 获得GridView模板列中控件所在行
- 【C】查找关键字所在行,输出位置及该行
- Android 点击任意位置隐藏
- 关于js 点击所在行,获取隐藏域问题
- SWT Table:获取表格所选中单元格所在行和列
- 点击窗体任意位置拖动 c#
- 点击屏幕任意位置隐藏虚拟键盘
- 获取winform任意位置点击事件
- 关于用Nunit获取不到Web.Config配置的问题(随笔)
- 软件的架构与设计模式之模式的种类
- 联系人
- D3D study 1
- STL实践(count_if)
- 点击GridView任意位置,选中所在行
- 认识和使用COleVariant
- 数据库查询性能提升
- LOB对象操作
- 使用Microsoft CryptoAPI进行加密、解密、签名及验证
- ajax.dll的原理
- 存储过程
- C++ 命名空间namespace
- 触发器