日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

gridview排序加箭头(二)

發布時間:2025/3/15 编程问答 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 gridview排序加箭头(二) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

gridview排序的時候,在.NET里是不能被標注的,下面提供如下方法:主要是顯示的時候進行了下判斷,然后進行不同的排序,這樣就給這個gridview加上了排序的箭頭,有意思的是<font face='Webdings'>個樣式,如果你對<font face='Webdings'>不是很了解,下面是提供的連接:

http://www.cnblogs.com/freeton/archive/2009/06/27/1512139.html

注意:

Aspx頁面:

設置排序:SortExpression="zhiwei"(給相應的字段設置)

.cs

開始設置的默認的排序狀態用ViewState進行設置,寫在!IsPostBack下面。

主要用到:GVpositionrecods_RowCreated與GVpositionrecods_Sorting事件

頁面 代碼 <asp:GridView?AllowSorting="True"?ID="GVpositionrecods"?runat="server"?PageSize="12"
????????????????????AllowPaging
="True"?EmptyDataText="沒有任何數據可以顯示"?Width="99%"?AutoGenerateColumns="False"
????????????????????OnRowDataBound
="GVpositionrecods_RowDataBound"?OnSelectedIndexChanged="GVpositionrecods_SelectedIndexChanged"
????????????????????OnSelectedIndexChanging
="GVpositionrecods_SelectedIndexChanging"?OnPageIndexChanging="GVpositionrecods_PageIndexChanging"
????????????????????OnRowCreated
="GVpositionrecods_RowCreated"?OnSorting="GVpositionrecods_Sorting">
????????????????????
<Columns>
????????????????????????
<asp:TemplateField?HeaderText="職位"?SortExpression="zhiwei">
????????????????????????????
<ItemTemplate>
????????????????????????????????
<a?href='throwseeen2.aspx?qiyeid=<%#Eval("qiyeid")%>&id=<%#Eval("ORDER_FORM_ID")?%>'>
????????????????????????????????????
<%#Eval("zhiwei")?%>
????????????????????????????????
</a>
????????????????????????????
</ItemTemplate>
????????????????????????????
<ItemStyle?HorizontalAlign="Center"?/>
????????????????????????
</asp:TemplateField>
????????????????????????
<asp:TemplateField?HeaderText="企業名稱"?SortExpression="qiyeid">
????????????????????????????
<ItemTemplate>
????????????????????????????????
<a?href='seeenlist.aspx?getidforen=<%#Eval("qiyeid")%>'>
????????????????????????????????????
<%#Eval("qiye")%>
????????????????????????????????
</a>
????????????????????????????
</ItemTemplate>
????????????????????????????
<ItemStyle?HorizontalAlign="Center"?/>
????????????????????????
</asp:TemplateField>
????????????????????????
<asp:BoundField?DataField="COUNT"?HeaderText="人數"?SortExpression="COUNT">
????????????????????????????
<ItemStyle?HorizontalAlign="Center"?/>
????????????????????????
</asp:BoundField>
????????????????????????
<asp:BoundField?DataField="STAR_TIME"?SortExpression="STAR_TIME"?HeaderText="發布時間"
????????????????????????????DataFormatString
="{0:yyyy-MM-dd}"?HtmlEncode="False">
????????????????????????????
<ItemStyle?HorizontalAlign="Center"?/>
????????????????????????
</asp:BoundField>
????????????????????????
<asp:BoundField?DataField="END_TIME"?SortExpression="END_TIME"?HeaderText="結束時間"
????????????????????????????DataFormatString
="{0:yyyy-MM-dd}"?HtmlEncode="False">
????????????????????????????
<ItemStyle?HorizontalAlign="Center"?/>
????????????????????????
</asp:BoundField>
????????????????????????
<asp:BoundField?DataField="flag"?HeaderText="狀態">
????????????????????????????
<ItemStyle?HorizontalAlign="Center"?/>
????????????????????????
</asp:BoundField>
????????????????????
</Columns>
????????????????????
<AlternatingRowStyle?BackColor="#E2F8FF"></AlternatingRowStyle>
????????????????????
<HeaderStyle?HorizontalAlign="Center"?BackColor="#99CCFF"></HeaderStyle>
????????????????????
<PagerStyle?CssClass="cssPager"?/>
????????????????
</asp:GridView>

?默認排序設置

代碼 ?protected?void?Page_Load(object?sender,?EventArgs?e)
????{
????????
if?(Session["student"]?==?null)
????????{
????????????Response.Write(
"<script>alert('頁面已過期,請重新登錄!');window.parent.frames.location.href='../Default.aspx'</script>");
????????}
????????
else?if?(!IsPostBack?&&?Session["t_resume_info"]?!=?null)
????????{
????????????ViewState[
"sortExp"]?=?"STAR_TIME";//默認排序的字段
????????????ViewState["sortDir"]?=?"Desc";//?字段是安什么排序的
????????????
//綁定數據源
????????????bind();

????????????
this.lbcontent.Visible?=?false;
????????}
????????
else?if?(Session["t_resume_info"]?==?null)
????????{
????????????
this.lbcontent.Text?=?"您還沒有任何錄取的信息";
????????}
????}

?綁定的數據源

代碼 public?void?bind()
????{
????????
//得到對應的簡歷的ID,從SN里面查看值
????????ccwu.Model.T_RESUME_INFO?listTemp?=?(ccwu.Model.T_RESUME_INFO)Session["t_resume_info"];
????????ccwu.Model.T_ORDER_RESUME?torderresume?
=?new?ccwu.Model.T_ORDER_RESUME();
????????
int?id?=?Convert.ToInt32(listTemp.ID.ToString());
????????
//得到對應的簡歷的ID,從SN里面查看值


????????ccwu.DAL.T_JOB?jobdal?
=?new?ccwu.DAL.T_JOB();
????????
string?where?=?"RESUME_INFO_ID='"?+?id.ToString()?+?"'";


????????DataSet?ds?
=?jobdal.getlistResume(where);
????????DataView?dv?
=?new?DataView(ds.Tables[0]);
????????dv.Sort?
=?ViewState["sortExp"].ToString()?+?"?"?+?ViewState["sortDir"].ToString();
????????GVpositionrecods.DataSource?
=?dv;
????????
this.GVpositionrecods.DataBind();
????????
if?(this.GVpositionrecods.Rows.Count?>?0)
????????{

????????}
????????
else//如果數據源是空的
????????{
????????????
//表頭的設置
????????????GridViewRow?row?=?new?GridViewRow(-1,?-1,?DataControlRowType.EmptyDataRow,?DataControlRowState.Normal);
????????????
foreach?(DataControlField?field?in?this.GVpositionrecods.Columns)
????????????{
????????????????TableCell?cell?
=?new?TableCell();
????????????????cell.Text?
=?field.HeaderText;
????????????????cell.Width?
=?field.HeaderStyle.Width;
????????????????cell.Height?
=?field.HeaderStyle.Height;
????????????????cell.ForeColor?
=?field.HeaderStyle.ForeColor;
????????????????cell.Font.Size?
=?field.HeaderStyle.Font.Size;
????????????????cell.Font.Bold?
=?field.HeaderStyle.Font.Bold;
????????????????cell.Font.Name?
=?field.HeaderStyle.Font.Name;
????????????????cell.Font.Strikeout?
=?field.HeaderStyle.Font.Strikeout;
????????????????cell.Font.Underline?
=?field.HeaderStyle.Font.Underline;
????????????????cell.BackColor?
=?field.HeaderStyle.BackColor;
????????????????cell.VerticalAlign?
=?field.HeaderStyle.VerticalAlign;
????????????????cell.HorizontalAlign?
=?field.HeaderStyle.HorizontalAlign;
????????????????cell.CssClass?
=?field.HeaderStyle.CssClass;
????????????????cell.BorderColor?
=?field.HeaderStyle.BorderColor;
????????????????cell.BorderStyle?
=?field.HeaderStyle.BorderStyle;
????????????????cell.BorderWidth?
=?field.HeaderStyle.BorderWidth;
????????????????row.Cells.Add(cell);
????????????}
????????????TableItemStyle?headStyle?
=?this.GVpositionrecods.HeaderStyle;
????????????TableItemStyle?emptyStyle?
=?GVpositionrecods.EmptyDataRowStyle;
????????????emptyStyle.Width?
=?headStyle.Width;
????????????emptyStyle.Height?
=?headStyle.Height;
????????????emptyStyle.ForeColor?
=?headStyle.ForeColor;
????????????emptyStyle.Font.Size?
=?headStyle.Font.Size;
????????????emptyStyle.Font.Bold?
=?headStyle.Font.Bold;
????????????emptyStyle.Font.Name?
=?headStyle.Font.Name;
????????????emptyStyle.Font.Strikeout?
=?headStyle.Font.Strikeout;
????????????emptyStyle.Font.Underline?
=?headStyle.Font.Underline;
????????????emptyStyle.BackColor?
=?headStyle.BackColor;
????????????emptyStyle.VerticalAlign?
=?headStyle.VerticalAlign;
????????????emptyStyle.HorizontalAlign?
=?headStyle.HorizontalAlign;
????????????emptyStyle.CssClass?
=?headStyle.CssClass;
????????????emptyStyle.BorderColor?
=?headStyle.BorderColor;
????????????emptyStyle.BorderStyle?
=?headStyle.BorderStyle;
????????????emptyStyle.BorderWidth?
=?headStyle.BorderWidth;
????????????
//空白行的設置
????????????GridViewRow?row1?=?new?GridViewRow(0,?-1,?DataControlRowType.EmptyDataRow,?DataControlRowState.Normal);

????????????TableCell?cell1?
=?new?TableCell();
????????????cell1.Text?
=?"沒有任何數據可以顯示";
????????????cell1.BackColor?
=?System.Drawing.Color.White;
????????????row1.Cells.Add(cell1);
????????????cell1.ColumnSpan?
=?6;//合并列

????????????
if?(this.GVpositionrecods.Controls.Count?==?0)
????????????{
????????????????GVpositionrecods.Page.Response.Write(
"<script?language='javascript'>alert('必須在初始化表格類之前執行DataBind方法并設置EmptyDataText屬性不為空!');</script>");
????????????}
????????????
else
????????????{
????????????????GVpositionrecods.Controls[
0].Controls.Clear();
????????????????
this.GVpositionrecods.Controls[0].Controls.AddAt(0,?row);
????????????????
this.GVpositionrecods.Controls[0].Controls.AddAt(1,?row1);
????????????}
????????}

????}

?關鍵代碼

代碼 ?protected?void?GVpositionrecods_RowCreated(object?sender,?GridViewRowEventArgs?e)
????{
????????
if?(e.Row.RowType?==?DataControlRowType.Header)//如果是表頭,則執行如下操作
????????{
????????????
foreach?(TableCell?tc?in?e.Row.Cells)
????????????{
????????????????
//這種方法直接新加一個控件,也可以換成圖片???????????????
????????????????if?(tc.Controls.Count?>?0)//這里要判斷一下此時是不是已經生成了linkbutton
????????????????{
????????????????????
string?s1?=?((LinkButton)tc.Controls[0]).Text;
????????????????????
//樣式Webdings是123都有自己對應的圖片
????????????????????((LinkButton)tc.Controls[0]).Text?=?s1.Replace(s1,?s1?+?"<font?face='Webdings'>5</font>");
????????????????????
//倒序的樣式
????????????????????if?(tc.Controls.Count?>?0?&&?tc.Controls[0].GetType().ToString()?==?"System.Web.UI.WebControls.DataControlLinkButton")
????????????????????{
????????????????????????
if?(((LinkButton)tc.Controls[0]).CommandArgument.ToString()?==?ViewState["sortExp"].ToString())
????????????????????????{
????????????????????????????
string?s2?=?((LinkButton)tc.Controls[0]).Text;
????????????????????????????
if?(ViewState["sortDir"].ToString()?==?"Desc")
????????????????????????????{
????????????????????????????????((LinkButton)tc.Controls[
0]).Text?=?s2.Replace("5",?"6");
????????????????????????????}
????????????????????????}
????????????????????}
????????????????}
????????????}
????????}
????}

?當點擊列頭的時候

代碼 protected?void?GVpositionrecods_Sorting(object?sender,?GridViewSortEventArgs?e)
????{
????????
string?sPage?=?e.SortExpression;

????????
if?(ViewState["sortExp"].ToString()?==?sPage)
????????{
????????????
if?(ViewState["sortDir"].ToString()?==?"Desc")
????????????????ViewState[
"sortDir"]?=?"ASC";
????????????
else
????????????????ViewState[
"sortDir"]?=?"Desc";
????????}
????????
else
????????{
????????????ViewState[
"sortExp"]?=?e.SortExpression;
????????}
????????bind();
????}

?

轉載于:https://www.cnblogs.com/muer/archive/2010/03/26/1697213.html

總結

以上是生活随笔為你收集整理的gridview排序加箭头(二)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。