光標定位的問題:document.getElementById(...) 是null或不是一個物件
光標定位的問題:document.getElementById(...) 是null或不是一個物件
楼主derek()2004-03-12 10:31:13 在 .NET技术 / ASP.NET 提问 代碼如下, 執行時出現錯誤. 我是想在用戶按下datagrid中的Edit 按鈕後, 光標定位在其中一cell
private void DataGrid1_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
this.DataGrid1.Width=500;
e.Item.Cells.Width=60;
e.Item.Cells.Width=30;
e.Item.Cells.Width=80;
e.Item.Cells.Width=80;
e.Item.Cells.Width=80;
e.Item.Cells.Width=70;
if(e.Item.ItemType==ListItemType.EditItem)
{
((TextBox)e.Item.Cells.Controls).Width=80;
((TextBox)e.Item.Cells.Controls).Width=80;
((TextBox)e.Item.Cells.Controls).Width=80;
((TextBox)e.Item.Cells.Controls).Width=70;
//分別用以下兩種調用方式
//1 --- this.SetFocus(((TextBox)e.Item.Cells.Controls));
//2 --- this.SetFocus(e.Item.Cells.Controls);
}
}
private void SetFocus (Control controlToFocus)
{
StringBuilder scriptFunction=new StringBuilder();
string scriptClientId;
scriptClientId = controlToFocus.ClientID;
scriptFunction.Append("<script language="javascript">");
scriptFunction.Append("document.getElementById("");
scriptFunction.Append(scriptClientId);
//scriptClientId的值分別是
//調用方式1時---DataGrid1__ctl2__ctl3
//調用方式2時---DataGrid1__ctl3__ctl3
scriptFunction.Append("").focus();");
scriptFunction.Append("</script>");
RegisterStartupScript("focus", scriptFunction.ToString()); //出現錯誤
說 "document.getElementById(...)" 是null或不是一個物件
}
问题点数:100、回复次数:12Top
1 楼derek()回复于 2004-03-15 17:39:44 得分 0
net_lover:
在html里為 body加上 runat=server id="isok" 後, 在c#代碼編輯器里還是不能直接引用,說: The type or namespace name "rightsconfig" could not be found (are you missing a using directive or an assembly reference?)
請問如何用?
reqperwu & 2002pine: 沒用模板,所以請問沒用模板第請況下應該如何做
vabug:
document.getElementByTagName("text").focus() 物件不支援此屬性或方法Top
2 楼SVG(ben)回复于 2004-03-17 11:48:37 得分 15
修改一下 SetFocus 的接口参数了.
用 table.rows.cells.childNodes.focus(); 的js 方法来实现 focusTop
3 楼Lostinet(每晚 8:00 见)回复于 2004-03-17 11:55:34 得分 15
WebControl的ID没有指定的情况下,是不会自动生成客户端的id的.
Top
-
相关文章
2秒记住本站域名
玩过泡泡龙吗?Readygo?Go! 再加上.Com.Cn的后缀,那就是大名小顶的readygo.com.cn
