我似乎無法更改頁腳文本。我也嘗試了排序的事件,但沒有任何反應。我想要做的就是顯示狀態消息。這裏是我的代碼:在GridView中更改頁腳文本
protected void PageSettings_Sorting(object sender, GridViewSortEventArgs e)
{
if (((GridView)sender).EditIndex > -1)
{
e.Cancel = true;
}
else
{
// tried this on sorted aswell but can't change footer text
GridViewRow row = ((GridView)sender).FooterRow as GridViewRow;
Label lblStatus = new Label{ ID="lblStatus", Text="Sorting Column <b>\"" + e.SortExpression + "\" " + e.SortDirection + "</b>"};
row.Cells[0].Text = "Hello World"; //.Controls.Add(lblStatus);
}
}
protected void PageSettings_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row != null && e.Row.RowType == DataControlRowType.Header)
{
}
else if (e.Row != null && e.Row.RowType == DataControlRowType.Footer)
{
int count = e.Row.Cells.Count;
for (int i = count - 1; i >= 1; i += -1)
{
e.Row.Cells.RemoveAt(i);
}
e.Row.Cells[0].ColumnSpan = count;
e.Row.Cells[0].Controls.Add(new Literal { ID = "lblStatus" });
// can't FindControl or change Literals either
e.Row.Cells[0].Text = "Hello World"; // works here but not on sorting event
}
}
<asp:GridView ID="PageSettings" runat="server"
AllowPaging="true" AllowSorting="true"
AutoGenerateColumns="false"
AutoGenerateDeleteButton="true"
AutoGenerateEditButton="true"
ShowFooter="true"
DataSourceID="ObjectDataSourcePages"
OnLoad="PageSettings_Load"
OnRowDataBound="PageSettings_DataBound"
OnRowCreated="PageSettings_RowCreated"
OnRowEditing="PageSettings_RowEditing"
OnRowCancelingEdit="PageSettings_RowCancelingEdit"
OnPageIndexChanging="PageSettings_PageIndexChanging"
OnSorting="PageSettings_Sorting"
OnSorted="PageSetting_Sorted"
PageSize="2">
<Columns>
<asp:TemplateField HeaderText="Page Name" HeaderStyle-HorizontalAlign="Left" SortExpression="Name">
<ItemTemplate>
<%# Eval("Name") %>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="Name" runat="server" Text='<%# Bind("Name") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Path" HeaderStyle-HorizontalAlign="Left" SortExpression="Path">
<ItemTemplate>
<%# Eval("Path") %>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="Path" runat="server" Text='<%# Bind("Path") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Route Value" HeaderStyle-HorizontalAlign="Left" SortExpression="RouteValue">
<ItemTemplate>
<%# Eval("RouteValue") %>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="RouteValue" runat="server" Text='<%# Bind("RouteValue") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="RegExp" HeaderStyle-HorizontalAlign="Left" SortExpression="RegExp">
<ItemTemplate>
<%# Eval("RegExp") %>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="RegExp" runat="server" Text='<%# Bind("RegExp") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
郵政標記,所以我們可以證明/確定哪些內容頁腳了。 – adatapost 2012-01-07 13:12:17
爲什麼你想在你的整理事件中做到這一點?當然你想要在創建/綁定事件中完成它? – Brissles 2012-01-07 15:45:13