62,046
社区成员
发帖
与我相关
我的任务
分享
<section class="featured">
<div>
<asp:GridView ID="Grid1" runat="server" OnSelectedIndexChanged="Grid1_SelectedIndexChanged" DataKeyNames="ID" AutoGenerateColumns="False" OnRowDataBound="Grid1_RowDataBound">
<Columns>
<asp:TemplateField ControlStyle-CssClass="desc">
<ItemTemplate>
<a><%# Eval("ID") %></a>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<a><%# Eval("Name") %></a>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</section>
<script>
function thisID(id) {
alert(id);
}
</script>
protected void Grid1_SelectedIndexChanged(object sender, EventArgs e)
{
GridViewRow GridR = Grid1.SelectedRow;
string S = Grid1.DataKeys[GridR.DataItemIndex].Value.ToString();
Page.ClientScript.RegisterStartupScript(this.GetType(), "tk", "thisID(" + S + ")", true);
}
protected void Grid1_RowDataBound(object sender, GridViewRowEventArgs e)
{
e.Row.Attributes["style"] = "cursor:hand";
PostBackOptions myPostBackOptions = new PostBackOptions(this);
myPostBackOptions.AutoPostBack = false;
myPostBackOptions.PerformValidation = false;
myPostBackOptions.RequiresJavaScriptProtocol = true; //加入javascript:头
String evt = Page.ClientScript.GetPostBackClientHyperlink(sender as GridView, "Select$" + e.Row.RowIndex.ToString());
e.Row.Attributes.Add("onclick", evt);
}
页头page 里面加上EnableEventValidation="false"
e.Row.Attributes.Add("onclick", "showFancyBox('" + ((GridView)sender).DataKeys[e.Row.RowIndex].Value.ToString() + "');");
加个引号
<script type="text/javascript">
$(document).ready(function(){
$("#openUrl").fancybox({
'width':'75%',
'height':'75%',
'autoScale':false,
'transitionIn':'none',
'transitionOut':'none',
'type':'iframe'
});
});
function showFancyBox(id)
{
$("#openUrl").attr("href","b.aspx?id="+id);
$("#openUrl").click();
}
</script>
这个隐藏的a标签,你放在body,随便什么地方,反正看不到。
<a id="openUrl" href="#" style="display:none;"></a>
后台cs
protected void gv1_RowDataBound(object sender, GridViewRowEventArgs e)
{
//首先判断是否是数据行
if (e.Row.RowType == DataControlRowType.DataRow)
{
//鼠标移动到某行上,该行变色
e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#CCCCFC'");
//鼠标移开后,恢复
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
//就这儿了
e.Row.Attributes.Add("onclick", "showFancyBox("+((GridView)sender).DataKeys[e.Row.RowIndex].Value.ToString()+")");
}
}
$(document).ready(function () {
$(".fb").click(function () {
var id = $(this).find("a").attr("xid");
//alert(id); //得到ID之后 弹窗....
$.fancybox.open({
'width': 600,
'height': 380,
'autoScale': false,
'transitionIn': 'none',
'transitionOut': 'none',
'type': 'iframe'
/*'href': 'yhqktx.aspx',
'onClosed': function() {
window.location.href='yhqdsc.aspx';
}*/
});
});
});
<Columns>
<asp:TemplateField ItemStyle-CssClass="fb">
<HeaderTemplate>选择</HeaderTemplate>
<ItemTemplate>
<a class="fb" href="yhqktx.aspx?id=<%# Eval("dm")%>" xid='<%# Eval("dm")%>' >养护</a>
</ItemTemplate>
</asp:TemplateField>
“/zl_yhxt”应用程序中的服务器错误。
无法找到资源。
说明: HTTP 404。您正在查找的资源(或者它的一个依赖项)可能已被移除,或其名称已更改,或暂时不可用。请检查以下 URL 并确保其拼写正确。
请求的 URL: /zl_yhxt/undefined
<script type="text/javascript">
function showFancyBox(iid) {
$(".test").fancybox({
'width': 600,
'height': 380,
'autoScale': false,
'transitionIn': 'none',
'transitionOut': 'none',
'type': 'iframe',
'href': 'yhqktx.aspx?id=' + iid,
'onClosed': function () {
window.location.href = 'yhqdsc.aspx';
}
});
}
</script>
protected void gv1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.CssClass = "test";
e.Row.Attributes.Add("onclick", "showFancyBox(" + ((GridView)sender).DataKeys[e.Row.RowIndex].Value.ToString() + ")");
}
}
datakeynames也设置了,貌似弹不出来,不知道为什么[/quote]
弹不出就是is的问题咯
<script type="text/javascript">
function showFancyBox(iid) {
$(".test").fancybox({
'width': 600,
'height': 380,
'autoScale': false,
'transitionIn': 'none',
'transitionOut': 'none',
'type': 'iframe',
'href': 'yhqktx.aspx?id=' + iid,
'onClosed': function () {
window.location.href = 'yhqdsc.aspx';
}
});
}
</script>
protected void gv1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.CssClass = "test";
e.Row.Attributes.Add("onclick", "showFancyBox(" + ((GridView)sender).DataKeys[e.Row.RowIndex].Value.ToString() + ")");
}
}
datakeynames也设置了,貌似弹不出来,不知道为什么$('#GridView1 tr').click(function () {
var $fb = $(this).find('a.fb');
if ($fb.length > 0) {
$.fancybox.open({
href: 'b.aspx?id=' + $fb.attr('dm'),
type: 'iframe',
padding: 5
});
}
});
<a class="fb" dm='<%#Eval(id"")%>'>详细信息</a>
<asp:GridView runat="server" ID="g1" Width="100%" AutoGenerateColumns="false" EnableViewState="false">
<Columns>
<asp:TemplateField ItemStyle-CssClass="ooxx">
<HeaderTemplate>查看</HeaderTemplate>
<ItemTemplate>
<a class='xxoo' href='xxxx.aspx?id=<%#Eval("id")%>' xid='<%#Eval("id")%>'>查看</a>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<script type="text/javascript">
$(document).ready(function () {
$(".ooxx").click(function () {
var id = $(this).find("a").attr("xid");
alert(id);//得到ID之后 弹窗....
});
});
</script>
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e) { GridViewRow GridR = GridView1.SelectedRow; string S = GridR.Cells[2].Text.ToString(); Response.Redirect("b.aspx?EmployeeID=" +S); }
<Columns>
<asp:TemplateField ItemStyle-CssClass="xxoo" href='b.aspx?id=<%#Eval("id")%>'>
<HeaderTemplate></HeaderTemplate>
<ItemTemplate>
<a class="xxoo" href='b.aspx?id=<%#Eval("id")%>'>详细信息</a>
</ItemTemplate>
</asp:TemplateField>
</Columns>
$(".xxoo").fancybox({
'width':'75%',
'height':'75%',
'autoScale':false,
'transitionIn':'none',
'transitionOut':'none',
'type':'iframe'
});