您的位置:首页 > Web前端 > JavaScript

后台给GridView绑定数据时给每一行添加一个JS方法

2016-05-24 10:16 288 查看
--------JS

function ReturnDictionaryValues(srcElement)
{
top.document.getElementById("_DialogFrame_a1").contentWindow.document.getElementById('txt_CAR_ID').value=srcElement.cells[0].innerText;
top.document.getElementById("_DialogFrame_a1").contentWindow.document.getElementById('CAR_NO').innerText=srcElement.cells[3].innerText;
top.document.getElementById("_DialogFrame_a1").contentWindow.document.getElementById('txt_Unit').innerText=srcElement.cells[1].innerText;
top.document.getElementById("_DialogFrame_a1").contentWindow.gongmu();//执行上一个页面的gongmu()方法
top.Dialog.close();//关闭当前页面
}

--------GridView

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" class="tableStyle" DataKeyNames="CAR_ID" border="0" Style="width: 100%" ToolTip="双击进行选择" OnRowDataBound="gv_RowDataBound">
<Columns>
<asp:BoundField DataField="CAR_NUM" HeaderText="车牌号">
<ItemStyle HorizontalAlign="Center" Width="10%" />
<HeaderStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:TemplateField HeaderText="所属单位">
<ItemTemplate><%#new AS_Services.BLL.PU_STATION().GetModel(Eval("STATION_ID").ToString()).STATION_NAME%> </ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="汽车类型">
<ItemTemplate><%#new AS_Services.BLL.PB_DZ_KIND().GetModel(Eval("KIND_ID").ToString()).KIND_NAME%> </ItemTemplate>
</asp:TemplateField>
</Columns>
<EmptyDataTemplate>
暂无记录!</EmptyDataTemplate>
</asp:GridView>

---------GridView页面的后台

protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("ondblclick", "ReturnDictionaryValues(this);");//每行添加一个ReturnDictionaryValues()的JS方法
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: