GridView 操作事件绑定技巧,单元格属性绑定指定值
2012-08-17 15:36
393 查看
1/在绑定数据时,绑定指定事件
2/单元格控件绑定一个或者多个,指定值
3/GridView的分页属性,
protected void gv_BomList_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
for (int i = 1; i < e.Row.Cells.Count; i++)
{
e.Row.Cells[i].Attributes.Add("onclick", ClientScript.GetPostBackClientHyperlink(e.Row.Cells[0].FindControl("SelectButton"), ""));
}
e.Row.Cells[0].Attributes.Add("onclick", ClientScript.GetPostBackClientHyperlink(e.Row.Cells[0].FindControl("chk_Button"), ""));
((LinkButton)e.Row.FindControl("SelectButton")).CommandArgument = e.Row.RowIndex.ToString();
((LinkButton)e.Row.FindControl("chk_Button")).CommandArgument = e.Row.RowIndex.ToString();
e.Row.Attributes.Add("onmouseover", "oldBG=this.style.backgroundColor; this.style.backgroundColor='#E6F5FA';");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=oldBG");
}
}
<asp:TemplateField Visible="False" HeaderText="Select">
<ItemTemplate>
<asp:LinkButton ID="SelectButton" runat="server" CausesValidation="False" CommandName="Button"
thisEcnID='<%#Eval("EcnDKey") %>' thisBomID='<%#Eval("MaterialBomKey") %>' Text="选择"></asp:LinkButton></ItemTemplate>
</asp:TemplateField>
//----------------------------------------------------------------------------------------------------------------------------------------------------------
<PagerTemplate>
<div style="text-align: center">
<asp:Label ID="lbl_count" runat="server" Text='<%# "总记录数:"+((System.Data.DataTable)((GridView)Container.NamingContainer).DataSource).Rows.Count+ " "%>'></asp:Label>
<asp:Label ID="lbl_page_size3" runat="server" Text='<%# "每页"+gv_BomList.PageSize+"条" %>'></asp:Label>
<asp:Label ID="lblPage1" runat="server" Text='<%# "第" + (((GridView)Container.NamingContainer).PageIndex + 1) + "页/共" + (((GridView)Container.NamingContainer).PageCount) + "页" %> '></asp:Label>
<asp:LinkButton ID="lbnFirst1" runat="Server" CommandArgument="First" CommandName="Page"
Enabled="<%# ((GridView)Container.NamingContainer).PageIndex != 0 %>" Text="首页"></asp:LinkButton>
<asp:LinkButton ID="lbnPrev1" runat="server" CommandArgument="Prev" CommandName="Page"
Enabled="<%# ((GridView)Container.NamingContainer).PageIndex != 0 %>" Text="上一页"></asp:LinkButton>
<asp:LinkButton ID="lbnNext1" runat="Server" CommandArgument="Next" CommandName="Page"
Enabled="<%# ((GridView)Container.NamingContainer).PageIndex != (((GridView)Container.NamingContainer).PageCount - 1) %>"
Text="下一页"></asp:LinkButton>
<asp:LinkButton ID="lbnLast1" runat="Server" CommandArgument="Last" CommandName="Page"
Enabled="<%# ((GridView)Container.NamingContainer).PageIndex != (((GridView)Container.NamingContainer).PageCount - 1) %>"
Text="尾页"></asp:LinkButton>
</div>
</PagerTemplate>
2/单元格控件绑定一个或者多个,指定值
3/GridView的分页属性,
protected void gv_BomList_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
for (int i = 1; i < e.Row.Cells.Count; i++)
{
e.Row.Cells[i].Attributes.Add("onclick", ClientScript.GetPostBackClientHyperlink(e.Row.Cells[0].FindControl("SelectButton"), ""));
}
e.Row.Cells[0].Attributes.Add("onclick", ClientScript.GetPostBackClientHyperlink(e.Row.Cells[0].FindControl("chk_Button"), ""));
((LinkButton)e.Row.FindControl("SelectButton")).CommandArgument = e.Row.RowIndex.ToString();
((LinkButton)e.Row.FindControl("chk_Button")).CommandArgument = e.Row.RowIndex.ToString();
e.Row.Attributes.Add("onmouseover", "oldBG=this.style.backgroundColor; this.style.backgroundColor='#E6F5FA';");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=oldBG");
}
}
<asp:TemplateField Visible="False" HeaderText="Select">
<ItemTemplate>
<asp:LinkButton ID="SelectButton" runat="server" CausesValidation="False" CommandName="Button"
thisEcnID='<%#Eval("EcnDKey") %>' thisBomID='<%#Eval("MaterialBomKey") %>' Text="选择"></asp:LinkButton></ItemTemplate>
</asp:TemplateField>
//----------------------------------------------------------------------------------------------------------------------------------------------------------
<PagerTemplate>
<div style="text-align: center">
<asp:Label ID="lbl_count" runat="server" Text='<%# "总记录数:"+((System.Data.DataTable)((GridView)Container.NamingContainer).DataSource).Rows.Count+ " "%>'></asp:Label>
<asp:Label ID="lbl_page_size3" runat="server" Text='<%# "每页"+gv_BomList.PageSize+"条" %>'></asp:Label>
<asp:Label ID="lblPage1" runat="server" Text='<%# "第" + (((GridView)Container.NamingContainer).PageIndex + 1) + "页/共" + (((GridView)Container.NamingContainer).PageCount) + "页" %> '></asp:Label>
<asp:LinkButton ID="lbnFirst1" runat="Server" CommandArgument="First" CommandName="Page"
Enabled="<%# ((GridView)Container.NamingContainer).PageIndex != 0 %>" Text="首页"></asp:LinkButton>
<asp:LinkButton ID="lbnPrev1" runat="server" CommandArgument="Prev" CommandName="Page"
Enabled="<%# ((GridView)Container.NamingContainer).PageIndex != 0 %>" Text="上一页"></asp:LinkButton>
<asp:LinkButton ID="lbnNext1" runat="Server" CommandArgument="Next" CommandName="Page"
Enabled="<%# ((GridView)Container.NamingContainer).PageIndex != (((GridView)Container.NamingContainer).PageCount - 1) %>"
Text="下一页"></asp:LinkButton>
<asp:LinkButton ID="lbnLast1" runat="Server" CommandArgument="Last" CommandName="Page"
Enabled="<%# ((GridView)Container.NamingContainer).PageIndex != (((GridView)Container.NamingContainer).PageCount - 1) %>"
Text="尾页"></asp:LinkButton>
</div>
</PagerTemplate>
相关文章推荐
- GridView的技巧 绑定行事件,取得单元格值,或取得单元格控件方法,鼠标经过样式
- 绑定gridview单元格内容过长,用tooltip,单元格截取指定长度,鼠标停留时显示全部内容,
- 在GridView里的LinkButton和绑定事件的操作
- jQuery1.9为动态添加元素绑定事件以及获取和操作checkbox的选择属性
- jQuery1.9为动态添加元素绑定事件以及获取和操作checkbox的选择属性11
- angularJS之link函数对元素事件绑定或属性的操作
- jQuery1.9为动态添加元素绑定事件以及获取和操作checkbox的选择属性
- GridView使用技巧之:根据绑定的内容改变单元格(或者行)的显示样式
- 从零开始学 Web 之 jQuery(五)操作元素其他属性,为元素绑定事件
- GridView的操作:基本操作(行和单元格绑定)
- 这么详细的分类 ASP.Net源代码网站你见过没有? ASP.Net中的每一个方法,每一个操作,每一个函数,每一个类.每一个属性,每一个事件都有相应的范例代码
- 编译vs2008的samples程序总是跳过,要配置属性还显示“未能完成操作 未指定的错误”的解决办法 .
- ASP.NET之Gridview的行绑定事件RowDataBound事件
- 操作datatable进行分页,绑定repeqter或者gridView
- 关于jQuery新的事件绑定机制on()的使用技巧
- JQuery —— 新建、添加、添加至某元素、属性添加、单击绑定事件
- jquery如何给对象动态添加属性以及选择器、事件的绑定
- ASP.NET2.0中Gridview中数据操作技巧
- GridView.RowCommand 事件 GridView.DataKeys 属性
- GridView绑定技巧终结者