【问题标题】:Displaying TextBox and Label when CheckBox selected in RadioButtonList在 RadioButtonList 中选择 CheckBox 时显示 TextBox 和 Label
【发布时间】:2018-03-13 07:24:03
【问题描述】:

所以我在 RadioButtonList 上显示了我的数据列表。 它不是单选按钮,而是单选按钮列表。

<asp:RadioButtonList Font-Size="X-Small" OnSelectedIndexChanged="radioBtn_SelectedIndexChange" onclick="ShowHide(this)"  RepeatDirection="Vertical" RepeatColumns="2" ID="rediobtn" runat="server">

Radiobuttonlist display

我现在要做的是显示一个 QTY 文本框,我可以在其中输入金额并将其提交到数据库中。

所以我创建了它们:

<asp:Label ID="lbrQty" Text="QTY" runat="server" Visible="false" />
<asp:TextBox ID="textQtyInput" runat="server" Visible="false"  />

在后面的代码中,我想知道如何编写代码,以便它可以检测到选择了 RadioButton。如果可能的话,我需要知道选择了哪个,因为我需要将数据上传到 SQL 中。

protected void radioBtn_SelectedIndexChange(object sender, EventArgs e)
{
    //if radiobutton is selected change  lbrQty and textQtyInput visible to true
}

更新

感谢您添加 AutoPostBack 的帮助。

那么让我来看看发生了什么:

  1. 输入条码
  2. 单选按钮列表出现
  3. 选择并出现数量标签和文本框
  4. 输入无效的条形码,数量标签和文本框仍然存在。我该如何摆脱它们?

Invalid barcode image

【问题讨论】:

    标签: c# asp.net


    【解决方案1】:

    您需要将RadioButtonList 的AutoPostBack 属性添加并设置为true 以触发您的radioBtn_SelectedIndexChange:

    <asp:RadioButtonList
           ID="rediobtn"
           AutoPostBack="true"
           Font-Size="X-Small" 
           OnSelectedIndexChanged="radioBtn_SelectedIndexChange" 
           onclick="ShowHide(this)" 
           RepeatDirection="Vertical" 
           RepeatColumns="2" 
           runat="server">
    

    选择收音机后,让您的 lbrQty 和 textQtyInput 可见:

    protected void rediobtn_SelectedIndexChanged(object sender, EventArgs e)
    {
        lbrQty.Visible = true;
        textQtyInput.Visible = true;
    }
    

    验证条形码时,如果条形码无效,请隐藏您的 lbrQty 和 textQtyInput:

    lbrQty.Visible = false;
    textQtyInput.Visible = false;
    

    【讨论】:

    • 谢谢先生,它似乎有效.. 在 If 语句中,我唯一的条件是必须选择 rationbutton 仅此而已。还有一个问题要麻烦。
    • 请查看我的更新:验证条形码时,如果条形码无效,请隐藏控件。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-06-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多