VoucherDetailInfoPanel 是div 的ID
TextBox1 是临时存放值得控件
75 是指减去头标题高度
前台脚本如下:
function GetPostion(e)
{
var element = document.getElementById("<%=VoucherDetailInfoPanel.ClientID %>");
if( document.selection)
{
var range = document.selection.createRange();
var stored_range = range.duplicate();
stored_range.moveToElementText( element );
stored_range.setEndPoint( 'EndToEnd', range );
element.selectionStart = stored_range.text.length - range.text.length;
element.selectionEnd = element.selectionStart + range.text.length;
document.getElementById("<%=TextBox1.ClientID %>").value=element.selectionStart;
}
}
function GetScrollTop() {
//debugger;
var div = document.getElementById("<%=VoucherDetailInfoPanel.ClientID %>");
div.scrollTop =document.getElementById("<%=TextBox1.ClientID %>").value-75;
}
脚本或者这样也可以 Begin
function GetPostion()
{ //debugger;
var element = document.getElementById("<%=VoucherDetailInfoPanel.ClientID %>");
if( document.selection)
{
document.getElementById("<%=TextBox1.ClientID %>").value=element.scrollTop+75;
}
}
function GetScrollTop() {
//debugger;
var div = document.getElementById("<%=VoucherDetailInfoPanel.ClientID %>");
div.scrollTop =document.getElementById("<%=TextBox1.ClientID %>").value-75;
}
End
后台代码
VoucherDetailGrid 列表控件 是GridView控件
protected void VoucherDetailGrid_RowEditing(object sender, GridViewEditEventArgs e)
{
if (e.NewEditIndex != VoucherDetailGrid.EditIndex)
{
int newEditRow = e.NewEditIndex;
EditRow(newEditRow);
ScriptManager.RegisterStartupScript(this, this.GetType(), "", "<script language='javascript'>GetScrollTop();</script>", false);// 这是调用前台的脚本
}
}
protected void VoucherDetailGrid_RowDataBound(object sender, GridViewRowEventArgs e)
{
int finSetCode = 0;
int j = 0;
if (ViewState[VIEWSTATE_FINSETCODE] != null)
{
finSetCode = Int32.Parse(ViewState[VIEWSTATE_FINSETCODE].ToString());
}
if (e.Row.RowType == DataControlRowType.DataRow)
{
VoucherDetailGrid.Attributes.Add("onclick", "GetPostion(event);"); // 这是调用前台的脚本
for (int i = 1; i < VoucherDetailGrid.Columns.Count; i++)
{
DataControlField dgc = VoucherDetailGrid.Columns[i];
if (dgc.HeaderText != String.Empty)
{
TCcVoucherSettingInfo tCcVoucherSettingInfo = BizVoucherSetting.GetVoucherItemByName(finSetCode, dgc.HeaderText);
if (tCcVoucherSettingInfo != null)
{
string voucherSettingId = tCcVoucherSettingInfo.VoucherSettingID;
string itemValue = String.Empty;
if (tCcVoucherSettingInfo.ItemType == (int)VoucherItemType.Dimension)
{
if (e.Row.FindControl(dgc.HeaderText + EDITTEXTBOX) != null)
{
bool isNo = BizFromAccount.IsFromAccountType(Convert.ToInt32(tCcVoucherSettingInfo.TypeValue),Convert.ToInt32(tCcVoucherSettingInfo.FinSetCode));
TextBox txb = (TextBox)e.Row.FindControl(dgc.HeaderText + EDITTEXTBOX);
string txbClient = txb.ClientID;
txb.Attributes.Add("onclick", "rowAccount(\'" + e.Row.RowIndex + "\',\'" + isNo + "\');__showDivContainer(\'" + txbClient + "\',\'" + tCcVoucherSettingInfo.FinSetCode + "\',\'" + tCcVoucherSettingInfo.TypeValue + "\');__DropDownClick(\'" + this.cc_MemberSelector.ClientID + "_divContainer\',\'150px\',\'" + txbClient + "\'); __setPosition(\'" + this.cc_MemberSelector.ClientID + "_divContainer\')");
txb.Attributes.Add("isAccount", "true");
txb.Attributes.Add("TypeValue", tCcVoucherSettingInfo.TypeValue);
}
}
}
}
}
}
}