gridview

GridView 高级技术

流过昼夜 提交于 2020-01-03 04:45:06
GridView 高级技术 汇总脚注 GridView 的主要目标是显示一组记录,但是你还可以加入一些有趣的信息,如汇总数据。需要如下的操作: 设置 GridView.ShowFooter 为 true ,这样可以显示脚注行(但没有数据) 在 GridView.FooterRow 中加入内容 本例假设正在处理产品列表,一个简单的汇总可以显示产品总价或均价。第一步是确定何时计算这个信息。如果正使用手工绑定(DataSource),那么可以在数据对象绑定到 GridView 之间就读取它的值并进行计算。但如果使用的是声明性绑定(DataSourceID),就要借助别的技术了。 <asp:SqlDataSource ID="sourceProducts" runat="server" ConnectionString="<%$ ConnectionStrings:Northwind %>" ProviderName="System.Data.SqlClient" SelectCommand="select ProductID,ProductName,UnitPrice,UnitsInStock from Products"> </asp:SqlDataSource> <asp:GridView ID="gridProducts" runat="server" DataSourceID=

gridview动态添加列

◇◆丶佛笑我妖孽 提交于 2020-01-03 04:44:24
gridview动态添加列,而且列中是一个链接,打开新窗口需要传值 方法一:在Page_Load事件中添加 可以完成功能,但添加的列始终在第一列,而且打开的新窗口不能自己设定大小 if (!IsPostBack) { HyperLinkField bfd1 = new HyperLinkField(); bfd1.HeaderText = "详细"; bfd1.Text = "查看"; string[] URL = { "身份证号" }; bfd1.DataNavigateUrlFields = URL; bfd1.DataNavigateUrlFormatString = "~/Search/detail.aspx?id={0}"; bfd1.Target = "_blank"; bfd1.ItemStyle.Width = 25; gridview1.Columns.Add(bfd1); } 方法二:在gridview1_RowDataBound事件中添加 if (e.Row.RowType == DataControlRowType.DataRow) { string JS = "detail.aspx?id=" + e.Row.Cells[0].Text.ToString(); e.Row.Cells[i].Width = 25; e.Row.Cells[i].Text =

GridView动态添加列的两篇文章

浪子不回头ぞ 提交于 2020-01-03 04:44:09
转自: http://blog.csdn.net/liang4571231/archive/2009/03/26/4025944.aspx public class MyTemplate:ITemplate { private string strColumnName; private DataControlRowType dcrtColumnType; public MyTemplate(string strColumnName, DataControlRowType dcrtColumnType) { this.strColumnName = strColumnName; this.dcrtColumnType = dcrtColumnType; } public void InstantiateIn(Control ctlContainer) { switch (dcrtColumnType) { case DataControlRowType.Header: //列标题 Literal ltr = new Literal(); ltr.Text = strColumnName; ctlContainer.Controls.Add(ltr); break; case DataControlRowType.DataRow: //模版列内容——加载hyperlink1

获取GRIDVIEW中的TemplateField显示的文本值

好久不见. 提交于 2020-01-03 04:43:38
GRIDVIEW中数据源绑定后的属性绑定我一般采取2种办法 一个是BoundField,只要设置DataField的对应属性名即可; 如: <asp:BoundField HeaderText ="系列" DataField="Catena" ItemStyle-Width="10%"/> 还有一个是TemplateField ,用来处理特殊的显示; 如: <asp:TemplateField HeaderText ="年销量"> <ItemTemplate> <%# GetSalesVolumes(Container.DataItem) %> </ItemTemplate> <ItemStyle Width="10%" HorizontalAlign="Center" /> </asp:TemplateField> 但是我在RowDataBound的绑定的一些事件中经常获取不到TemplateField中的文本值; row.Cells[index].Text 的值为""; 后面查了些资料和思考了下,发现TemplateField是个容器,用来自定义显示的,绑定值为其的子容器; 调试监视了下发现 <ItemTemplate> <%# GetSalesVolumes(Container.DataItem) %> </ItemTemplate> 写法中row.Cells[index]

获取GRIDVIEW中的TemplateField显示的文本值

无人久伴 提交于 2020-01-03 04:43:23
GRIDVIEW中数据源绑定后的属性绑定我一般采取2种办法 一个是BoundField,只要设置DataField的对应属性名即可; 如: <asp:BoundField HeaderText ="系列" DataField="Catena" ItemStyle-Width="10%"/> 还有一个是TemplateField ,用来处理特殊的显示; 如: <asp:TemplateField HeaderText ="年销量"> <ItemTemplate> <%# GetSalesVolumes(Container.DataItem) %> </ItemTemplate> <ItemStyle Width="10%" HorizontalAlign="Center" /> </asp:TemplateField> 但是我在RowDataBound的绑定的一些事件中经常获取不到TemplateField中的文本值; row.Cells[index].Text 的值为""; 后面查了些资料和思考了下,发现TemplateField是个容器,用来自定义显示的,绑定值为其的子容器; 调试监视了下发现 <ItemTemplate> <%# GetSalesVolumes(Container.DataItem) %> </ItemTemplate> 写法中row.Cells[index]

how to access templatefield from code behind

和自甴很熟 提交于 2020-01-03 04:22:09
问题 the reason why i am looking to update dynamic is because i am using objectdatasource and my objectdatasource have a collection of object and within that object i have another object that i wanted to access so for an example: +Student ...... ...... ...... -Courses ......... ......... Name Update end how do i bind templatefield from code-behind? <asp:Gridview ID="gridview1" runat="Server"> <columns> <asp:TemplateField HeaderText="Name" SortExpression="Name"> <ItemTemplate> </ItemTemplate> </asp

Refresh GridView from ClientSide (Javascript) in asp.net

依然范特西╮ 提交于 2020-01-03 04:14:27
问题 I have added the Gridview control on a webPage. I am deleting any row (one row at a time) by calling PageMethod as follow: <script type="text/javascript"> function Delete_Row(){ PageMethods.DeleteRow(row_id, GetTimeCallback, ErrorHandler, TimeOutHandler); } GetTimeCallback = function (result) { if (result) { alert('Row is deleted'); // I want to refresh the Gridview here } } <script type="text/javascript"> where " row_id " is primery key of the row. It shows the alert perfectly but does not

How to create SEO friendly paging (in Digg.com style) using ASP.Net 2.0(C#)?

坚强是说给别人听的谎言 提交于 2020-01-03 03:26:04
问题 I have created a digg.com style pagination for my ASP.Net 2.0 (with C#) website's gridview control using this article: http://kpumuk.info/asp-net/gridview-with-custom-digg-like-pager/ In order to achieve digg.com style, the author of the above mentioned article has customized gridview control and created a C# control named as GridviewWithPager using two derived controls (gridview and link button control), which allowed to add Digg-style pagination to an application. But this pagination is not

Dropdownlist in templatefield - update fails (null value insertion)

筅森魡賤 提交于 2020-01-03 03:23:08
问题 I have a gridview. In this i have a templatefield with a DropDownList (DDL in EditItemTemplate mode, label in ItemTemplate mode). When i hit edit on of of the detailsview's rows i can select any value from the DDL (the DDL is populated from a sqldatasource), but if i try to execute the update, it fails, because it thinks i didn't supply the data... Here is the exact error (the DB refuse NULL data): Cannot insert the value NULL into column 'status', table 'gyumolcs.dbo.orders'; column does not

Persisting DropDownList Value in PageIndexChanged of GridView

喜你入骨 提交于 2020-01-03 03:21:08
问题 Protected Sub grdView_PageIndexChanging(sender As Object, e As GridViewPageEventArgs) Handles grdView.PageIndexChanging grdView.SelectedIndex = -1 grdView.PageIndex = e.NewPageIndex ' To persist DDL values at paging using datatable Dim Data As New DataTable Data.Columns.Add("RowIndex", Type.GetType("System.Int32")) Data.Columns.Add("SelectedValue", Type.GetType("System.String")) For Each Row As GridViewRow In grdView.Rows Dim ddl As DropDownList = DirectCast(Row.FindControl("ddlSample"),