想双击GridView某行时,通过JS函数调用Button4的Click事件,但是无法成功
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("ondblclick", "rowdata()");
}
}
后台Click事件
protected void Button4_Click(object sender, EventArgs e)
{
TextBox1.Text = Button4.ID;
}
前台JS函数
<script type="text/javascript">
function rowdata()
{
document.getElementByID("Button4").onclick();
}
</script>
请看看哪里不对,document.getElementByID("Button4").onclick()是这样写吗
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("ondblclick", "rowdata()");
}
}
后台Click事件
protected void Button4_Click(object sender, EventArgs e)
{
TextBox1.Text = Button4.ID;
}
前台JS函数
<script type="text/javascript">
function rowdata()
{
document.getElementByID("Button4").onclick();
}
</script>
请看看哪里不对,document.getElementByID("Button4").onclick()是这样写吗
解决方案 »
- 查询效率问题?
- 向数据集中拖两张表,但一张表得不到数据,不知道为什么?
- 网站中js脚本注入病毒,急救
- 请教关于sql server 2005的问题?
- sql 视图里调用函数的效率问题
- 在英文操作系统中我用Request.UserHostAddress为什么不能正确获取到客户端的ip地址
- 如何将页面和程序设计分开制作?即用DW或Frontpage制作页面,用vs.net开发工具设计程序,两者如何来结合?
- ASP.NET中TOList转成JSON格式
- 我安装了.net framework正式版后出现错误,请帮忙看看?
- 有偿请人写一段代码,自动登录网站
- 在线等——这段jquery代码单独放在一个JS文件中怎么就不行了?
- 帖子标题不能为空
$(document).ready(function(){
$("按钮ID").click();
})
function rowdata()
{
document.getElementByID("Button4").onclick();
}
</script>
把上面的脚本放在form后面
document.getElementByID("Button4").click();
JS: <script language="javascript" type="text/javascript">
function DbClickEvent(d)
{
window.opener.document.getElementById('帐号').value=d;
window.close();
}
function ClickEvent(d)
{
window.alert("事件类型: OnClick 作用对象: " + d);
}
function GridViewItemKeyDownEvent(d)
{
window.alert("事件类型: GridViewItemKeyDownEvent 作用对象: " + d);
}
function KeyDownEvent()
{
if( event.altKey && event.keyCode > 48 && event.keyCode < 54 )
{
window.alert("事件类型: FormKeyDownEvent 选中记录数: " + ( parseInt(event.keyCode) - 48 ));
}
}
</script>后台:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//鼠标移动到每项时颜色交替效果
e.Row.Attributes.Add("OnMouseOut", "this.style.backgroundColor='White';this.style.color='#003399'");
e.Row.Attributes.Add("OnMouseOver", "this.style.backgroundColor='#6699FF';this.style.color='#8C4510'"); //单击/双击 事件
e.Row.Attributes.Add("OnDblClick", "DbClickEvent('" + e.Row.Cells[1].Text + "')");
// e.Row.Attributes.Add("OnClick", "ClickEvent('" + e.Row.Cells[1].Text + "')"); e.Row.Attributes.Add("OnKeyDown", "GridViewItemKeyDownEvent('" + e.Row.Cells[1].Text + "')"); //设置悬浮鼠标指针形状为"小手"
e.Row.Attributes["style"] = "Cursor:hand"; }
}前台:
<asp:GridView ID="GridView1" runat="server" BackColor="White"
BorderColor="White" BorderStyle="Ridge" BorderWidth="2px" CellPadding="3"
GridLines="None" Width="100%" CellSpacing="1"
onrowdatabound="GridView1_RowDataBound" AllowPaging="True"
onrowcreated="GridView1_RowCreated" onrowcommand="GridView1_RowCommand">
<FooterStyle BackColor="#C6C3C6" HorizontalAlign="Center" ForeColor="Black" />
<RowStyle BackColor="#ECF4F7" HorizontalAlign="Center" ForeColor="Black" />
<EmptyDataRowStyle BackColor="#E3EBEE" BorderStyle="None" />
<PagerStyle BackColor="#C6C3C6" ForeColor="Black" HorizontalAlign="Right" />
<SelectedRowStyle BackColor="#9471DE" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#E7E7FF"
HorizontalAlign="Center" />
<EditRowStyle BorderStyle="Dotted" />
<AlternatingRowStyle HorizontalAlign="Center" />
</asp:GridView>参考
document.getElementByID("<%=Button4.ClientID%>").click();
}
改成document.getElementByID("Button4").click()也无效
放到form后面也不行
<script type="text/javascript">
function rowdata()
{
document.getElementByID("Button4").onclick();
}
</script>
这段是放在head段里的
<%@ Register src="runmenu.ascx" tagname="runmenu" tagprefix="uc1" %>
<%@ Register src="../CustomCalendar.ascx" tagname="CustomCalendar" tagprefix="uc2" %>
<%@ Register src="../textbox_N0.ascx" tagname="textbox_N0" tagprefix="uc3" %>
<%@ Register src="../textbox_f2.ascx" tagname="textbox_f2" tagprefix="uc4" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>无标题页</title>
<link href="../StyleSheet.css" rel="stylesheet" type="text/css" />
<style type="text/css">
#form1
{
width: 981px;
}
#Text1
{
width: 60px;
}
#Button4
{
height: 23px;
width: 59px;
}
</style>
<script language="javascript" type="text/javascript" src="../PlugIn/My97DatePicker/WdatePicker.js"></script>
<script language="javascript" type="text/javascript" src="../PlugIn/JavaScript.js"></script><!--从外部JS文件调用函数-->
<script type="text/javascript">
function rowdata()
{
document.getElementByID("<%=Button4.ClientID%>").click();
}
</script>
</head>
<body>
<form id="form1" runat="server">
.........................
</form>
</body>
</html>
<asp:Panel ID="Panel1" runat="server" BorderStyle="Inset" Height="340px"
ScrollBars="Auto" HorizontalAlign="Center">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="SqlDataSource1"
AllowSorting="True" CellSpacing="1" onrowdatabound="GridView1_RowDataBound">
<Columns>
<asp:TemplateField HeaderText="序号"></asp:TemplateField>
<asp:BoundField DataField="bh" HeaderText="编号" ReadOnly="True"
SortExpression="bh" Visible="False" />
<asp:BoundField DataField="cpmc" HeaderText="产品名称" SortExpression="cpmc" >
<ItemStyle Width="80px" HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="pp" HeaderText="品牌" SortExpression="pp" >
<ItemStyle Width="80px" />
</asp:BoundField>
<asp:BoundField DataField="gg" HeaderText="规格" SortExpression="gg" >
<ItemStyle Width="150px" HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="jhrq" HeaderText="进货日期" SortExpression="jhrq"
DataFormatString="{0:yyyy.MM.dd}" >
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="jhsl" HeaderText="进货数量" SortExpression="jhsl" >
<ItemStyle HorizontalAlign="Right" />
</asp:BoundField>
<asp:BoundField DataField="jhdj" HeaderText="进货单价" SortExpression="jhdj"
DataFormatString="{0:f}" >
<ItemStyle HorizontalAlign="Right" Width="80px" />
</asp:BoundField>
<asp:BoundField DataField="kcsl" HeaderText="库存数量" SortExpression="kcsl" >
<ItemStyle HorizontalAlign="Right" />
</asp:BoundField>
<asp:BoundField DataField="lr" HeaderText="利润" SortExpression="lr"
DataFormatString="{0:f}" >
<ItemStyle HorizontalAlign="Right" />
</asp:BoundField>
<asp:BoundField DataField="xsh" HeaderText="显示" SortExpression="xsh"
Visible="False" />
<asp:BoundField DataField="xg" HeaderText="修改" SortExpression="xg"
Visible="False" />
</Columns>
<HeaderStyle HorizontalAlign="Center" CssClass="gridviewheaderstyle" />
</asp:GridView>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="Button2" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="Button3" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
</asp:Panel>
<div>
<asp:Button ID="Button2" runat="server" Text="保存" CssClass="button"
onclick="Button2_Click" />
<asp:Button ID="Button3" runat="server" Text="删除" CssClass="button"/>
<asp:Button ID="Button4" runat="server" CssClass="button"
onclick="Button4_Click" Text="Button" />
</div>
</div>
<asp:Button ID="Button2" runat="server" Text="保存" CssClass="button"
onclick="Button2_Click" />
<asp:Button ID="Button3" runat="server" Text="删除" CssClass="button"/>
<asp:Button ID="Button4" runat="server" CssClass="button"
onclick="Button4_Click" Text="Button" />
</div>
JS里区分大小的吧!
getElementByID 改成 getElementById