求救~ItemDataBound中取不到值~先谢拉
我直接在TextBox1中输入一些值,然后双击DataGrid,但是取不到刚刚输入的值,总是为空,有谁知道吗?谢谢啦private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
e.Item.Attributes.Add("ondblClick","alert("+TextBox1.Text+")");
} --------------------编程问答-------------------- 先占个座 --------------------编程问答-------------------- 加~~~~~~~~~~~~~
if(e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
{} --------------------编程问答-------------------- 你的textbox1是datagrid里面的还是datagrid外面?
如果是里面的在这里你得有个
if(e.item.itemindex>=0)
{
TextBox textbox1= (TextBox)e.items[i].FindControl("TextBox1");
e.Item.Attributes.Add("ondblClick","alert("+textbox1.Text+")");
} --------------------编程问答-------------------- alert("+TextBox1.Text+")
写错了。alert("+document.getElementById("DDL_TextBox1").value+") --------------------编程问答-------------------- 加了还是取不到值,谢,还有谁知道吗? --------------------编程问答-------------------- private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
{
e.Item.Attributes.Add("ondblClick","alert("+TextBox1.Text+")");
}
}
--------------------编程问答-------------------- 打错字
alert("+document.getElementById("TextBox1").value+")
--------------------编程问答-------------------- 是在DataGrid外面的 --------------------编程问答-------------------- alert是在客户端取客户端的值
大家有没有搞错!!!!!!!!!!! --------------------编程问答-------------------- 我是写在服务器代码里的~它提示找不到document,谢 --------------------编程问答-------------------- document.getElementById("TextBox1").value--这个是客户端方法
e.Item.Attributes.Add("ondblClick","a = document.getElementById("+TextBox1.ClientID+").value;alert(a);"); --------------------编程问答-------------------- 啊!忘记一件事!
好像要alert(\"+document.getElementById(\"TextBox1\").value+\")
这么写才得,要不就被视图编译 --------------------编程问答-------------------- 网页上有错误~缺少 ')'谢,我再调调看 --------------------编程问答-------------------- 说实在话,还不如在
页面的
<head>标签内写个js方法
<script language=javascript>
function alertTxt()
{
a = document.getElementById("TextBox1").value;
alert(a);
}
</script>
然后
if(e.item.itemindex>=0)
{
//TextBox textbox1= (TextBox)e.items[i].FindControl("TextBox1");
e.Item.Attributes.Add("ondblClick","alertTxt();");
}
--------------------编程问答-------------------- Public Sub alertTxt()
Dim script As String = _
"<script language=" + Chr(34) + "javascript" + Chr(34) _
+ ">" + _
" var txt= document.getElementById(" + Chr(34) + _
TextBox1 + Chr(34) + ").value;" + _
"alert( txt);" + _
"</script>"
Page.RegisterStartupScript("alert", script)
End Sub
------------------------------------------------------------
e.Item.Attributes.Add("ondblClick",alertTxt())
--------------------编程问答-------------------- 看了你另外一个问题,你这样弄看看
<head>标签内写个js方法
<script language=javascript>
function alertTxt()
{
a = document.getElementById("TextBox1").value;
window.location = 'car_Singlebooking.aspx?id='+a;//最好把你的url中的txt改为其他的,txt是文本文件的后缀,还是不要用在这里
} --------------------编程问答-------------------- private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
{
TextBox tb = (TextBox)e.Item.FindControls("TextBox1");
e.Item.Attributes.Add("ondblClick","alert(\""+tb.Text+"\")");
}
}
补充:.NET技术 , ASP.NET