每当我尝试单击“搜索”按钮或选择Gridview中的按钮时,它会加载并向上滚动整个页面。我想留在原地。怎么样?
代码:
<asp:TextBox ID="txtComplaintSubject" runat="server" CssClass="textField_width"></asp:TextBox> 
<asp:Button ID="btnSearch" CssClass="btn btn-success" runat="server" Text="Search"
ValidationGroup="AdminRole" ClientIDMode="Static" OnClick="btnSearch_Click" />
<asp:GridView ID="gridViewComplaints" AutoGenerateSelectButton="true" runat="server" CssClass="mGrid" OnSelectedIndexChanged="gridViewComplaints_SelectedIndexChanged">
<EmptyDataRowStyle BorderStyle="None" ForeColor="Red" BorderWidth="0px" />
<EmptyDataTemplate>
No Data Found for this Input. Try Again.
</EmptyDataTemplate>
<SelectedRowStyle CssClass="selected-row" BackColor="YellowGreen" ForeColor="white" />
</asp:GridView>
protected void btnSearch_Click(object sender, EventArgs e)
{
ManageComposedLetter mngCompLetter = new ManageComposedLetter();
DataTable dt = mngCompLetter.FillGridView_Complaints(txtComplaintSubject.Text);
if (dt.Rows.Count > 0)
{
gridViewComplaints.DataSource = dt;
gridViewComplaints.DataBind();
}
else
{
dt.Rows.Add(dt.NewRow());
gridViewComplaints.DataSource = dt;
gridViewComplaints.DataBind();
int totalcolums = gridViewComplaints.Rows[0].Cells.Count;
gridViewComplaints.Rows[0].Cells.Clear();
gridViewComplaints.Rows[0].Cells.Add(new TableCell());
gridViewComplaints.Rows[0].Cells[0].ColumnSpan = totalcolums;
gridViewComplaints.Rows[0].Cells[0].Text = "No Data Found";
}
}
答案 0 :(得分:3)
如果您想在页面刷新后保持相同的位置,只需添加
MaintainScrollPositionOnPostback="true"
位于aspx文件的顶部,所以它看起来像这样:
<%@ Page Language="C#" MaintainScrollPositionOnPostback="true" AutoEventWireup="true" CodeBehind="Default.aspx.cs"
答案 1 :(得分:0)
答案 2 :(得分:0)
我想你也可以在页面加载中使用if(!Page.IsPostBack)。这个问题可能更容易。 (但我建议大家学习c的更新面板)