请大家帮忙看下这样给控件属性绑定数据有什么问题?
<asp:Label ID="lblVote1" Text="<%#vote1 %>" runat="server" ></asp:Label>前面已经设定过了 int vote1;了
没有反应.. --------------------编程问答-------------------- 难道不是'<%# Eval("votel")%>' --------------------编程问答--------------------
没用... 不知道这里的EVAL有啥用? --------------------编程问答-------------------- 不能这么绑定。。。
其实你的意思是这样的"<%=votel%>",但这样赋值给服务器端控件也是不行的,直接lblVotel.Text=votel.ToString()
--------------------编程问答-------------------- 前台 <%=vote1 %>
后台
public string vote1 = "Test"; --------------------编程问答--------------------
你说的这个,我懂...(PS. 我试过tostring会报错 convert.tostring 不会)
关键是:放在XTML部分,如何给赋值呢?
我是新手,还请高手解释.. --------------------编程问答--------------------
前台代码不能用 --------------------编程问答--------------------
必须执行一句:
lblVote1.DataBind();--------------------编程问答-------------------- <%# Eval("votel")%>
<%= votel %> --------------------编程问答--------------------
放在LOAD 里面了没用... --------------------编程问答--------------------
不行的都 --------------------编程问答-------------------- 一个IMAGE LABEL BUTTON...实现 点以下BUTTON IMAGE和LABEL长一点..用于看选票结果的
后台
public partial class _Default : System.Web.UI.Page
{
protected static int vote1=0, vote2=0, vote3=0;
protected void Page_Load(object sender, EventArgs e)
{
//lblVote1.Text = Convert.ToString(vote1);
//lblVote1.Text = vote1.ToString;
lblVote1.DataBind();
}
protected void btnVote1_Click(object sender, EventArgs e)
{
vote1 += 1;
this.DataBind();
}
}
前台:
<asp:Image ID="imgVote1" runat="server" Height="12px" Width="<%#vote1 %>"
ImageUrl="~/black.bmp" > </asp:Image>
<asp:Label ID="lblVote1" Text="<%= vote1 %>" runat="server" ></asp:Label> --------------------编程问答--------------------
数据绑定只能在模板控件中使用吧。 你这个直接赋值就行了
<asp:Label ID="lblVote1" Text="<%= vote1 %>" runat="server" ></asp:Label>
--------------------编程问答--------------------
这个后来试过 可以用了 谢谢
补充:.NET技术 , ASP.NET