帮帮忙,改一条语句!谢谢 onmousedown='window.parent.frames.banner.location.href= "<%# top.aspx?id="+ DataBinder.Eval(Container.DataItem,"id") %>'取不到id的值,语句该怎么写 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 onmousedown= window.parent.frames.banner.location.href=<%# "top.aspx?id="+ DataBinder.Eval(Container.DataItem,"id") %>改成這樣試試. 你把數據顯示在哪個控件中,DataGrid?,沒有控件的話是不支持這種寫法的. <asp:HyperLink ID="HyperLink1" onmousedown=' "window.parent.frames.banner.location.href="+"<%# top.aspx?id="+ DataBinder.Eval(Container.DataItem,"id") %>' onmouseup="window.parent.frames.banner.location.reload()" Text='<%# DataBinder.Eval(Container.DataItem,"md_name")%>' NavigateUrl='<%# "ShowMediaInfo.aspx?id="+ DataBinder.Eval(Container.DataItem,"id")%>' runat="server" Target="main">HyperLink</asp:HyperLink>其中hyperlink是datalist中的 我试了onmousedown= 'window.parent.frames.banner.location.href= "top.aspx?id=2"' 会成功的 可不可以另写一段javascript脚本,把绑定的数据赋给一个变量? onmousedown= 'window.parent.frames.banner.location.href=top.aspx?id=<%# DataBinder.Eval(Container.DataItem,"id") % > ' onmousedown='window.parent.frames.banner.location.href="top.aspx?id= <%# DataBinder.Eval(Container.DataItem,"CategoryID") %>"'刚才的写错了。 CategoryId 换成id,我试了,好用,生成的结果为onmousedown= 'window.parent.frames.banner.location.href= "top.aspx?id=2" ' 如果还不对,就检查一下是不是数据库的问题了。 我试了!onmousedown= 'window.parent.frames.banner.location.href= "top.aspx?id=2" ' 这样可以,但就是那个值绑不上去,谢谢你,我再仔细看看是不是其它问题 对了,使用数据控件绑定时,后台要调用控件的DataBind();方法,前台才能 <%# DataBinder.Eval(Container.DataItem,"CategoryID") % >这样绑定啊。 我是想把id值传到top.aspx页面中,然后根据这个值获得一条数据中的一个字段然后把这个字段显示在页面上~问题就是取不到绑定的id值,后面的NavigateUrl属性都能取到id,就是onmousedown事件下的id取不到,我估计就是语句没写正确,呵呵,也不知道问题出在哪里 部分源程序:left.aspx<asp:DataList ID="DataList1" runat="server" Height="200px"> <ItemTemplate> <a><asp:HyperLink ID="HyperLink1" onmousedown='window.parent.frames.banner.location.href="top.aspx?id=<%# DataBinder.Eval(Container.DataItem,"id")%>"' onmouseup="window.parent.frames.banner.location.reload()" Text='<%# DataBinder.Eval(Container.DataItem,"md_name")%>' NavigateUrl='<%# "ShowMediaInfo.aspx?id="+ DataBinder.Eval(Container.DataItem,"id")%>' runat="server" Target="main">HyperLink</asp:HyperLink></a> </ItemTemplate> <ItemStyle Font-Bold="False" Font-Italic="False" Font-Overline="False" Font-Size="9pt" Font-Strikeout="False" Font-Underline="False" /> </asp:DataList>top.aspx.csprotected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.HyperLink1.Attributes.Add("onclick", "javascript:window.open('left.aspx','left')"); if (Request.QueryString["id"] != null) { string id = Request.QueryString["id"].ToString(); DataConn con = new DataConn(); string sql = "select * from bi_media_info where id='" + id + "'"; DataSet ds = con.GetDataSet(sql); this.Image1.ImageUrl = "upfile/" + ds.Tables[0].Rows[0]["md_logo"]; } } }红色标记的id值取不到 另种方法参考:变换这种方法可以实现:protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e) { if (e.Item.ItemType ==ListItemType.Item||e.Item.ItemType==ListItemType.AlternatingItem) { string name = ((HyperLink)(e.Item.FindControl("HyperLink1"))).Text; Response.Write(((HyperLink)(e.Item.FindControl("HyperLink1"))).Text); ((HyperLink)(e.Item.FindControl("HyperLink1"))).Attributes.Add("onclick", "javascript:window.open('top.aspx?md_name=" + name + "','banner')"); } } asp.net 如何 上传下载超大附件 唯有送分以表谢意 asp.net FreeTextBox 3.2.2 问题 请教大家一个设计思路 FileUpload浏览文件后如何触发事件 为什么我的文件上传会少一个文件呢 htmlfile: 由于该控件目前不可见、未启用或其类型不允许,因此无法将焦点移向它? 关于弹出窗口关闭后更新主窗口的问题? 可行性分析 如何刷新DATAGRID? reteater的重复问题 asp.net控件响应事件的问题 请问这几个有什么区别?
改成這樣試試.
刚才的写错了。
如果还不对,就检查一下是不是数据库的问题了。
这样可以,但就是那个值绑不上去,谢谢你,我再仔细看看是不是其它问题
问题就是取不到绑定的id值,后面的NavigateUrl属性都能取到id,就是onmousedown事件下的id取不到,我估计就是语句没写正确,呵呵,也不知道问题出在哪里
left.aspx
<asp:DataList ID="DataList1" runat="server" Height="200px">
<ItemTemplate>
<a><asp:HyperLink ID="HyperLink1" onmousedown='window.parent.frames.banner.location.href="top.aspx?id=<%# DataBinder.Eval(Container.DataItem,"id")%>"' onmouseup="window.parent.frames.banner.location.reload()" Text='<%# DataBinder.Eval(Container.DataItem,"md_name")%>' NavigateUrl='<%# "ShowMediaInfo.aspx?id="+ DataBinder.Eval(Container.DataItem,"id")%>' runat="server" Target="main">HyperLink</asp:HyperLink></a>
</ItemTemplate>
<ItemStyle Font-Bold="False" Font-Italic="False" Font-Overline="False" Font-Size="9pt"
Font-Strikeout="False" Font-Underline="False" />
</asp:DataList>top.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.HyperLink1.Attributes.Add("onclick", "javascript:window.open('left.aspx','left')");
if (Request.QueryString["id"] != null)
{
string id = Request.QueryString["id"].ToString();
DataConn con = new DataConn();
string sql = "select * from bi_media_info where id='" + id + "'";
DataSet ds = con.GetDataSet(sql);
this.Image1.ImageUrl = "upfile/" + ds.Tables[0].Rows[0]["md_logo"];
}
}
}
红色标记的id值取不到
变换这种方法可以实现:
protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
{
if (e.Item.ItemType ==ListItemType.Item||e.Item.ItemType==ListItemType.AlternatingItem)
{
string name = ((HyperLink)(e.Item.FindControl("HyperLink1"))).Text;
Response.Write(((HyperLink)(e.Item.FindControl("HyperLink1"))).Text);
((HyperLink)(e.Item.FindControl("HyperLink1"))).Attributes.Add("onclick", "javascript:window.open('top.aspx?md_name=" + name + "','banner')");
}
}