gpt4 book ai didi

c# - 单击 gridview 中的选择按钮时页面刷新

转载 作者:行者123 更新时间:2023-11-30 22:06:44 25 4
gpt4 key购买 nike

每当我尝试在 Gridview 中单击搜索按钮或选择按钮时,它都会加载并向上滚动整个页面。我想把它留在原地。怎么样?

代码:

<asp:TextBox ID="txtComplaintSubject" runat="server" CssClass="textField_width"></asp:TextBox>&nbsp
<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";
}

最佳答案

如果你想在页面刷新后停留在相同的位置,只需添加

MaintainScrollPositionOnPostback="true"

在你的 aspx 文件的顶部,所以它看起来像这样:

<%@ Page Language="C#" MaintainScrollPositionOnPostback="true" AutoEventWireup="true" CodeBehind="Default.aspx.cs"

关于c# - 单击 gridview 中的选择按钮时页面刷新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23428226/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com