【问题标题】:accessing information of inputs type radio in c# page在 c# 页面中访问输入类型无线电的信息
【发布时间】:2018-04-16 11:41:39
【问题描述】:

大家好,我想从 c# 文件中的无线电类型输入中获取信息,我该怎么做?我想将评分值保存在我的 sql 数据库服务器中。

这是我的 aspx/html 代码:

<li><fieldset class="rating">
        <legend>Please rate:</legend>
        <input type="radio" id="star5" name="rating" value="5" /><label for="star5" title="Rocks!">5 stars</label>
        <input" type="radio" id="star4" name="rating" value="4" /><label for="star4" title="Pretty good">4 stars</label>
        <input type="radio" id="star3" name="rating" value="3" /><label for="star3" title="Meh">3 stars</label>
        <input type="radio" id="star2" name="rating" value="2" /><label for="star2" title="Kinda bad">2 stars</label>
        <input type="radio" id="star1" name="rating" value="1" /><label for="star1" title="Sucks big time">1 star</label>
    </fieldset>
                    <asp:Button ID="Rating_btn" runat="server" Text="Rate" OnClick="Rating_btn_Click"/>
                    </li>

css代码:

.rating {
    float:left;
}
.rating:not(:checked) > input {
    position:absolute;
    top:-9999px;
    clip:rect(0,0,0,0);
}

.rating:not(:checked) > label {
    float:right;
    width:1em;
    padding:0 .1em;
    overflow:hidden;
    white-space:nowrap;
    cursor:pointer;
    font-size:200%;
    line-height:1.2;
    color:#ddd;
    text-shadow:1px 1px #bbb, 2px 2px #666, .1em .1em .2em rgba(0,0,0,.5);
}

.rating:not(:checked) > label:before {
    content: '★ ';
}

.rating > input:checked ~ label {
    color: #f70;
    text-shadow:1px 1px #c60, 2px 2px #940, .1em .1em .2em rgba(0,0,0,.5);
}

.rating:not(:checked) > label:hover,
.rating:not(:checked) > label:hover ~ label {
    color: gold;
    text-shadow:1px 1px goldenrod, 2px 2px #B57340, .1em .1em .2em rgba(0,0,0,.5);
}

.rating > input:checked + label:hover,
.rating > input:checked + label:hover ~ label,
.rating > input:checked ~ label:hover,
.rating > input:checked ~ label:hover ~ label,
.rating > label:hover ~ input:checked ~ label {
    color: #ea0;
    text-shadow:1px 1px goldenrod, 2px 2px #B57340, .1em .1em .2em rgba(0,0,0,.5);
}

.rating > label:active {
    position:relative;
    top:2px;
    left:2px;
}

感谢大家的帮助!!! 我试图添加 runat=server 但它破坏了我的风格并且无法正常工作

【问题讨论】:

    标签: c# sql asp.net sql-server input


    【解决方案1】:

    这是因为 WebForms 无法识别输入是文本、支票还是单选,以将其转换为正确的类。您使用的所有元素不是来自&lt;asp:something&gt;(或除 asp 之外的任何其他目录)都被读取为 HtmlControl。
    您不能在 HtmlControl 中使用特定的东西,例如 Checked 属性,只能使用通用的。

    Asinput 仅供客户端使用,要在代码上阅读它,您应该改用&lt;asp:RadioButton/&gt;System.Web.UI.WebControls.RadioButton

    此外,您需要runat="server",因为您在服务器上运行它。
    如果它正在改变它,也许你需要检查你的 css 逻辑

    然后你就可以使用它了:

    if (star5.Checked)
    {
        DoSomething()
    }
    

    观察:我们的答案取决于您使用“哪个 asp.net 框架”来使其运行。 MVC 的方法将完全不同。
    请将其标记为 WebForms。

    您使用的数据库也无关紧要,因为您只询问如何读取值,而不是如何在数据库上写入

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-06-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-20
      • 1970-01-01
      • 1970-01-01
      • 2020-03-31
      相关资源
      最近更新 更多