有时候需要对 dropdownlist,gridview 增加选择事件的时候,需要至当前选中的文件为为上下居中状态可以使用以下代码方法实现。
scrollIntoView Method | Internet Development Index |
Causes the object to scroll into view, aligning it either at the top or bottom of the window.
Syntax
object.scrollIntoView( [bAlignToTop])
Parameters
bAlignToTop Optional. Boolean that specifies one of the following values:
true Default. Scrolls the object so that top of the object is visible at the top of the window. false Scrolls the object so that the bottom of the object is visible at the bottom of the window.
Return Value
No return value.
Remarks
The scrollIntoView method is useful for immediately showing the user the result of some action without requiring the user to manually scroll through the document to find the result.
Depending on the size of the given object and the current window, this method might not be able to put the item at the very top or very bottom, but will position the object as close to the requested position as possible.
Example
protected void **_SelectedIndexChanged(object sender, EventArgs e)
{//******
this.Scroll(**.SelectedIndex);
}
void Scroll(int index)
{
string s = "<script>function window.onload(){document.all('" + this.**.ClientID + "').options [" + index + "].scrollIntoView();}</script>";
Page.RegisterStartupScript("", s);}

本文介绍了一种使DropdownList或GridView中的选定项在视图中居中的方法。通过使用scrollIntoView方法,可以确保用户能够立即看到操作结果,而无需手动滚动查找。文章还提供了一个具体的ASP.NET示例。
165

被折叠的 条评论
为什么被折叠?



