【发布时间】:2025-12-07 15:45:01
【问题描述】:
我在 ma 网站上有一个长的 GridView 控件。它允许行选择。问题是,当我向下滚动此 GridView 并选择一些底部行时,会发生选择,但整个 GridView 正在滚动回顶部。
我参考this link 来解决我的问题,但无法在 GridView 控件中找到任何属性。我也在 msdn Link 上搜索。
请指导我此属性在哪里以及如何解决我的问题。根据下面的复选框事件,我选择了该行。选中复选框后启用删除和编辑按钮。
protected void ChkChanged_Click(object sender, EventArgs e)
{
int count = 0;
foreach (GridViewRow gr in grdProducts.Rows)
{
CheckBox chkGrd = ((CheckBox)gr.FindControl("CheckBox2"));
ImageButton editbutton = gr.FindControl("btnEdit") as ImageButton;
ImageButton deleteButton = gr.FindControl("btnDeleted") as ImageButton;
if (chkGrd.Checked)
{
count++;
editbutton.Visible = true;
deleteButton.Visible = true;
if (count > 1)
break;
}
else
{
editbutton.Visible = false;
deleteButton.Visible = false;
}
}
if (count > 1)
{
foreach (GridViewRow gr in grdProducts.Rows)
{
CheckBox chkGrd = ((CheckBox)gr.FindControl("CheckBox2"));
ImageButton editbutton = gr.FindControl("btnEdit") as ImageButton;
ImageButton deleteButton = gr.FindControl("btnDeleted") as ImageButton;
if (chkGrd.Checked)
{
editbutton.Visible = false;
deleteButton.Visible = false;
}
}
DeleteAll.Enabled = true;
}
}
【问题讨论】:
-
把gridview放到更新面板试试。
-
@sajanyamaha:我试过了,但是当我在 gridview 中选择行时它会移到最前面。