选择控件单击选择事件使选中的文件至顶状态

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

有时候需要对 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

bAlignToTopOptional. Boolean that specifies one of the following values:
trueDefault. Scrolls the object so that top of the object is visible at the top of the window.
falseScrolls 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);

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值