Tag: 代码隐藏的

在代码隐藏中访问datalist的asp.net控件

我试图在后面的代码中访问asp图像标记,以便在没有其他图像存在的情况下显示默认图像。 我遇到的问题是我得到一个“对象引用未设置为对象的实例”。 错误信息。 aspx页面 <%– –%> <asp:Image ID="ProfileImage" runat="server" ImageUrl='’ /> <asp:Hyperlink runat="server" NavigateUrl='’ Text=” /> 代码背后的方法 profilelist.DataSource = myProfileList; profilelist.DataBind(); Image ProfileImage = profilelist.FindControl(“ProfileImage”) as Image; string profilepic = ProfileImage.ImageUrl.ToString(); if (profilepic == null) { ProfileImage.Visible = false; } 任何帮助表示赞赏

在一次调用中Request.Url.Host和ApplicationPath

有没有办法在一次调用中获取HttpContext.Current.Request.Url.Host和HttpContext.Current.Request.ApplicationPath ? 像“完整的应用程序URL”之类的东西? 编辑:澄清 – 我需要的是[]中的部分: http://[www.mysite.com/mywebapp]/Pages/Default.aspx 我只是出于好奇而问。 编辑2:感谢所有的回复,但没有一个是我正在寻找的。 仅供参考,我以这种方式解决了问题(但我仍然有兴趣知道是否有更顺畅的方式): public string GetWebAppRoot() { if(HttpContext.Current.Request.ApplicationPath == “/”) return “http://” + HttpContext.Current.Request.Url.Host; else return “http://” + HttpContext.Current.Request.Url.Host + HttpContext.Current.Request.ApplicationPath; }

如何在代码中获取ListBox ItemsPanel

我有一个带有ItemsPanel的ListBox 我想使用后面的代码中的TranslateTransform沿X轴移动堆栈面板。 问题是,我找不到Stack Panel。 ThumbListBox.FindName(“ThumbListStack”) 什么都不返回 我想用它: Storyboard.SetTarget(x, ThumbListBox.FindName(“ThumbListStack”)) 如何获取堆栈面板,以便我可以将其与TranslateTransform一起使用 谢谢