通过单击C#中的列标题对GridView进行排序

编程入门 行业动态 更新时间:2024-10-27 21:25:22
本文介绍了通过单击C#中的列标题对GridView进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我的代码如下所示.如何通过单击任何列标题对gridview进行排序?让我们说一下,从gridview完成搜索后将其排序. 我已经设置了allow sorting = true以及如何在下面> 中进行编码

Hi, My code looks like below. How to sort the gridview by clicking any of the column header? Let say sort it after done the search from gridview. I already set the allow sorting = true and how should i code in below>

SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandType = CommandType.Text; cmd.CommandText = "select top 1000 machineNameDisplay, equipment_type, frequency, formStatus, NextDueDate, cal_eqid from dbo.Obs_PMChkList_1 where v_dept = 'BGA EOL'"; //DataSet ds = new DataSet(); DataTable dt = new DataTable(); DataView dv = new DataView(); SqlDataAdapter adp = new SqlDataAdapter(cmd); adp.Fill(dt); GridView1.DataSource = dt; dv = dt.DefaultView; //Session["values"] = dv; //BindData(""); GridView1.DataBind(); conn.Close();

protected void btnSearch_Click(object sender, EventArgs e) { string searchString = txtSearch.Text; foreach (GridViewRow row in GridView1.Rows) { TableCellCollection cells = row.Cells; foreach (TableCell cell in cells) { //if (cell.Text.ToLower().StartsWith(searchString.ToLower())) if (cell.Text.ToLower().StartsWith(searchString.ToLower())) { break; } else { //does not meet cell.Visible = false; } } } }

protected void GridView1_Sorting(object sender, GridViewSortEventArgs e) { //How to code here? }

推荐答案

请参考以下链接. 带有上下图标的Gridview排序,分页 [ ^ ] 使用对象数据源进行优化的分页和排序 [ ^ ] GridView:排序和使用C#的泛型和可空数据类型函数进行分页GetaOrDefault() [ ^ ] Hi, Refer the below link. Gridview Sorting with Up and Down Icons, Paging[^] Optimized Paging and Sorting using Object Data Source[^] GridView:Sorting & Paging Using Generics And Nullable Datatype Function Of C# GetValueOrDefault()[^]

一无所有,应该可以正常工作 nothing at all, It should working

1.我的搜索功能似乎无法正常工作.我的预期结果是显示整行,但没有显示.例如,我搜索"abc",并且该行的第二列包含"abc",系统仅从第二列开始显示.我需要它来显示整行(包括第一个单元格). 2.在此之后,如果需要单击标题,则需要对其进行排序.它必须能够从我的搜索结果中进行排序. 请帮忙! Hi, 1. My search function seems does not working as expected. My expected result is display the whole row but it does not. For eg, i search for "abc" and the 2nd column of the row contains "abc", system only display from second column onwards. I need it to display in whole row (include 1st cell). 2. After this, i need to sort it if click on the header. It have to able to sort it from my search result. Please help!

更多推荐

通过单击C#中的列标题对GridView进行排序

本文发布于:2023-11-04 06:40:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1557217.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:单击   标题   GridView

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!