服务器标签格式不正确 [英] Server Tag is not well formed
问题描述
这是该死的愚蠢的,但驾驶我绝对疯狂Fing头
This is so damn stupid but driving me absolutely fing crazy.
<input type="radio" name="OptGroup" id="<%#"rbEmail" + ((Action)Container.DataItem).ID %>" value="<%#((Action)Container.DataItem).ID %>" runat="server" /><label for="<%#"rbEmail" + ((Action)Container.DataItem).ID %>"><%#((Action)Container.DataItem).Action %></label>
好吧,跆拳道我做错了这里!我也试过:
ok, wtf am I doing wrong here! I've also tried:
<input type="radio" name="OptGroup" id='<%#"rbEmail" + ((Action)Container.DataItem).ID %>' value='<%#((Action)Container.DataItem).ID %>' runat="server" /><label for='<%#"rbEmail" + ((Action)Container.DataItem).ID %>'><%#((Action)Container.DataItem).Action %></label>
和
<input type="radio" name="OptGroup" id="<%#'rbEmail' + ((Action)Container.DataItem).ID %>" value="<%#((Action)Container.DataItem).ID %>" runat="server" /><label for="<%#'rbEmail' + ((Action)Container.DataItem).ID %>"><%#((Action)Container.DataItem).Action %></label>
我特别不希望使用asp.net单选由于与组名它创建而中继器内的问题。我想用一个光秃秃的单选按钮,其值绑定到我的数据源。
I specifically do not want to use an asp.net radiobutton due to the problems with GroupName it creates while inside a repeater. I want to use a bare radio button and bind its values to my datasource.
推荐答案
你需要访问控制服务器端?如果没有,脱下=服务器,则无法进行数据绑定到ID属性的服务器控件。不知道如果多数民众赞成这个问题,因为这应该给你一个不同的错误
Do you need to access the control server-side? If not, take off the runat="server", you cannot databind to the ID property for a server control. Not sure if thats the problem, since that should give you a different error
编辑:
这样的事情应该满足您的要求。
Something like this should suit your purposes..
<asp:Repeater runat="server">
<ItemTemplate>
<label><input type="radio" name="rbEmail" value='<%# ((Action)Container.DataItem).ID %>' /><%# ((Action)Container.DataItem).Action %></label>
</ItemTemplate>
</asp:Repeater>
然后在回传,可以从得到的Request.Form值[rbEmail]
Then in the postback, you can get the value from Request.Form["rbEmail"]
EDIT2:
经过全面测试简单的页面的例子。
Fully tested simple page example..
Default.aspx的
Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<label><input type="radio" name="rbEmail" value='<%# Container.DataItem %>' /><%# Container.DataItem %></label>
</ItemTemplate>
</asp:Repeater>
<asp:Button ID="submit" runat="server" OnClick="submit_Click" Text="submit" />
</form>
</body>
</html>
Default.aspx.cs
Default.aspx.cs
using System;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Repeater1.DataSource = new string[] { "Hello", "World" };
Repeater1.DataBind();
}
protected void submit_Click(object sender, EventArgs e)
{
Response.Write(Request.Form["rbEmail"]);
}
}
这篇关于服务器标签格式不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!