后台给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方法
}
}
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方法
}
}
相关文章推荐
- js-比较两个日期的大小
- JavaScript高级程序设计(读书笔记)(四)
- js中onclick字符串传参问题
- js数组操作大全(pop,push,unshift,splice,shift方法)
- JavaScript学习1
- 使用json文件为当前类文件属性赋值(org.nutz.json.Json)
- 常规功能和模块自定义系统 (cfcmms)—045模块导航功能的重构(3)导航的定义
- Effective JavaScript :第六章
- Effective JavaScript :第五章
- 检测使用 three.js 时的 WebGL 和浏览器兼容性(Detecting WebGL and browser compatibility with three.js)(转)
- 命名函数表达式
- 数据抓包+hijson
- 使用ajaxupload.js插件上传图片不成功问题----RTFSC
- js time
- JavaScript高级程序设计(读书笔记)(三)
- JavaScript高级程序设计(读书笔记)(二)
- 4类 JavaScript 内存泄露及如何避免
- 深入理解JavaScript中为什么string可以拥有方法
- ASP.NET的后台代码和前台JS代码相互调用
- .NET Core计划弃用project.json