-6ren">
gpt4 book ai didi

c# - 将我的代码隐藏变量放在 NavigateUrl 的 Repeater Control 中

转载 作者:太空宇宙 更新时间:2023-11-03 22:27:30 24 4
gpt4 key购买 nike

这是我的中继器

<asp:Repeater ID="blogRepeater" runat="server">
<ItemTemplate>
<br />
<asp:Image ID="Image1" runat="server" Height="56px" ImageUrl='<%= string.Format( My_Variable) %>' Width="64px" />
<asp:HyperLink ID="HyperLink2" runat=server NavigateUrl='<%#Eval("Company_ID", "CompanyProfile.aspx?ID={0}")%>'><%#Eval("Name")%></asp:HyperLink>
<br />
</ItemTemplate>
<SeparatorTemplate>
<hr />
</SeparatorTemplate>
</asp:Repeater>

这是我在页面加载中隐藏的代码

' Define data objects
Dim conn As Data.SqlClient.SqlConnection
Dim Comm As Data.SqlClient.SqlCommand
Dim reader As Data.SqlClient.SqlDataReader

conn = New Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)

Comm = New Data.SqlClient.SqlCommand( _
("SELECT Company_ID, Name FROM CompanyTable ORDER BY Name"), conn)

Dim My_Variable As String

My_Variable = "~/createthumb.ashx?gu=/images/Logo.bmp" + "&xmax=75&ymax=75"

' Open the connection
conn.Open()
' Execute the category command
reader = Comm.ExecuteReader()

' Bind the reader to the repeater.......................
blogRepeater.DataSource = reader

blogRepeater.DataBind()

' Close the reader
reader.Close()
' Close the connection
conn.Close()

现在我有一个名为 My_Variable 的变量。如何将变量 My_Variable 放入上面的 Repeater 中?

最佳答案

通过这种方式,您可以将变量绑定(bind)到转发器:

<a href='<%= string.Format("CompanyProfile.aspx?ID={0}", My_Variable) %>'>
<%# Eval("Name") %>
</a>

编辑:您正在使用不需要成为服务器控件的静态控件。所以你可以像这样为你的全局变量使用 HTML 元素和 response.write :

<img id="Image1" style="height:56px;width:64px;" src='<%= My_Variable %>' />

关于c# - 将我的代码隐藏变量放在 NavigateUrl 的 Repeater Control 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/790629/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com