第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

麻煩幫忙解釋一下關(guān)于SortExpression的用法問題

麻煩幫忙解釋一下關(guān)于SortExpression的用法問題

素胚勾勒不出你 2021-11-25 15:15:04
請教一下,GridView里面的每個BoundField里面都有一個SortExpression,那排序的時候是按照哪一個表達(dá)式去排啊?其實(shí)我不大明白SortExpression有什么用的...是不是類似于字典那樣的排序,每個表達(dá)式都有用的?還是只有其中一個表達(dá)式有用?
查看完整描述

2 回答

?
鳳凰求蠱

TA貢獻(xiàn)1825條經(jīng)驗(yàn) 獲得超4個贊

排序字段,點(diǎn)擊定義了該屬性的字段名,可以獲得該字段的排序規(guī)則,并產(chǎn)生排序事件,修改dataset(數(shù)據(jù)源)的視圖狀態(tài),以該字段為規(guī)則進(jìn)行排序
還有同時常用到的屬性:SortDirection

下面這個例子可以很好的看出它的用法:

protected void kjkm_dg_SortCommand(object source, DataGridSortCommandEventArgs e)
{
string SortExpression = e.SortExpression.ToString(); //獲得當(dāng)前排序表達(dá)式
string SortDirection = "ASC"; //為排序方向變量賦初值
if (SortExpression == kjkm_dg.Attributes["SortExpression"]) //如果為當(dāng)前排序列
{
SortDirection = (kjkm_dg.Attributes["SortDirection"].ToString() == SortDirection ? "DESC" : "ASC"); //獲得下一次的排序狀態(tài)
}
kjkm_dg.Attributes["SortExpression"] = SortExpression;
kjkm_dg.Attributes["SortDirection"] = SortDirection;
mikecatbind();
}



查看完整回答
反對 回復(fù) 2021-11-28
?
qq_笑_17

TA貢獻(xiàn)1818條經(jīng)驗(yàn) 獲得超7個贊

GridView.SortExpression 屬性 是用來獲取與正在排序的列關(guān)聯(lián)的排序表達(dá)式。

下面是例子你看看吧。
<%@ Page language="C#" %>

<script runat="server">

void CustomersGridView_RowCreated(Object sender, GridViewRowEventArgs e)
{

// Use the RowType property to determine whether the
// row being created is the header row.
if (e.Row.RowType == DataControlRowType.Header)
{
// Call the GetSortColumnIndex helper method to determine
// the index of the column being sorted.
int sortColumnIndex = GetSortColumnIndex();

if (sortColumnIndex != -1)
{
// Call the AddSortImage helper method to add
// a sort direction image to the appropriate
// column header.
AddSortImage(sortColumnIndex, e.Row);
}
}
}

// This is a helper method used to determine the index of the
// column being sorted. If no column is being sorted, -1 is returned.
int GetSortColumnIndex()
{

// Iterate through the Columns collection to determine the index
// of the column being sorted.
foreach (DataControlField field in CustomersGridView.Columns)
{
if (field.SortExpression == CustomersGridView.SortExpression)
{
return CustomersGridView.Columns.IndexOf(field);
}
}

return -1;
}

// This is a helper method used to add a sort direction
// image to the header of the column being sorted.
void AddSortImage(int columnIndex, GridViewRow headerRow)
{

// Create the sorting image based on the sort direction.
Image sortImage = new Image();
if (CustomersGridView.SortDirection == SortDirection.Ascending)
{
sortImage.ImageUrl = "~/Images/Ascending.jpg";
sortImage.AlternateText = "Ascending Order";
}
else
{
sortImage.ImageUrl = "~/Images/Descending.jpg";
sortImage.AlternateText = "Descending Order";
}

// Add the image to the appropriate header cell.
headerRow.Cells[columnIndex].Controls.Add(sortImage);

}

</script>

<html>
<body>
<form runat="server">

<h3>GridView AllowSorting Example</h3>

<asp:gridview id="CustomersGridView"
datasourceid="CustomersSource"
autogeneratecolumns="false"
emptydatatext="No data available."
allowsorting="true"
onrowcreated="CustomersGridView_RowCreated"
runat="server">

<columns>
<asp:boundfield datafield="CustomerID"
headertext="Customer ID"
headerstyle-wrap="false"
sortexpression="CustomerID"/>
<asp:boundfield datafield="CompanyName"
headertext="CompanyName"
headerstyle-wrap="false"
sortexpression="CompanyName"/>
<asp:boundfield datafield="Address"
headertext="Address"
headerstyle-wrap="false"
sortexpression="Address"/>
<asp:boundfield datafield="City"
headertext="City"
headerstyle-wrap="false"
sortexpression="City"/>
<asp:boundfield datafield="PostalCode"
headertext="Postal Code"
headerstyle-wrap="false"
sortexpression="PostalCode" />
<asp:boundfield datafield="Country"
headertext="Country"
headerstyle-wrap="false"
sortexpression="Country"/>
</columns>

</asp:gridview>

<!-- This example uses Microsoft SQL Server and connects -->
<!-- to the Northwind sample database. Use an ASP.NET -->
<!-- expression to retrieve the connection string value -->
<!-- from the Web.config file. -->
<asp:sqldatasource id="CustomersSource"
selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]"
connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
runat="server"/>

</form>
</body>
</html>



查看完整回答
反對 回復(fù) 2021-11-28
  • 2 回答
  • 0 關(guān)注
  • 544 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號