【问题标题】:conditional value of hidden field in asp.netasp.net中隐藏字段的条件值
【发布时间】:2014-03-01 18:20:42
【问题描述】:

这是我的单选按钮列表的 ASP 标记

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
    <ContentTemplate>

        <asp:RadioButtonList ID="rbcourse" runat="server" AutoPostBack="True" Height="54px" RepeatDirection="Horizontal" style="text-align: left; font-weight: 700;" Width="385px">
            <asp:ListItem >BA</asp:ListItem>
            <asp:ListItem>BSC</asp:ListItem>
            <asp:ListItem>BSCN</asp:ListItem>
            <asp:ListItem>BCOM</asp:ListItem>
        </asp:RadioButtonList>
   </ContentTemplate>

</asp:UpdatePanel>

这是隐藏字段的标记

<asp:HiddenField ID="hffee" runat="server" Value="122" />

这是hffee的sql添加参数值

cmd.Parameters.AddWithValue("@hffee", Val(hffee.Value))

现在我需要如果用户在 BA 单选列表项上单击说 HFFEE 的值,它是隐藏字段并且其属性值设置为 nill 如果用户选择 BSC,则应说 1200,那么 hffee 的值应为 1500 i nut shell 我需要隐藏字段的动态值,它将在 btn 提交时存储在 sql server 上

我正在更改此单选按钮列表上的复选框,例如启用禁用检查真假等 在事件 rbcourse_selected 索引更改的 v.b 代码上,这是单选按钮列表 我只是在写

Protected Sub rbcourse_SelectedIndexChanged(sender As Object, e As EventArgs) Handles rbcourse.SelectedIndexChanged

    If rbcourse.SelectedIndex = "0" Then (0 is the item value of BA)
        ge.Checked = True  (ge is the text name of check box and it is working)

我需要同样的方式

If rbcourse.SelectedIndex = "0" Then (0 is the item value of BA)
 then 

hffe.value="1200" 这样

【问题讨论】:

  • 我对你的问题有点困惑,你能详细说明一下吗?
  • 我会编辑我的帖子,而不是你会得到我的问题
  • @Ahmed Salman Tahir-我已经详细说明了这个问题请看
  • 您是否总是有固定值要在选择时发送?我的意思是对 BA 总是 1200,对 BSC 1500 等等?或者这些可以改变吗?
  • @Ahmed Salman Tahir - 是的,每次我选择 BA 时它都会改变,如果它会改变,那么它总是只有一个数字。如果有人点击BA,则实际上是入场费,如果是B.Sc,则BSC的入场费必须是2800

标签: asp.net vb.net


【解决方案1】:

这是我尝试并在按钮点击时获得费用:

Enum AdmissionFee
    BA = 1200
    BSC = 1800
    BSCN = 2100
    BCOM = 2500
End Enum

Protected Sub rbcourse_SelectedIndexChanged(sender As Object, e As EventArgs) Handles rbcourse.SelectedIndexChanged
    If rbcourse.SelectedIndex = "0" Then
        Me.hffee.Value = Convert.ToString(AdmissionFee.BA)
    ElseIf rbcourse.SelectedIndex = "1" Then
        Me.hffee.Value = Convert.ToString(AdmissionFee.BSC)
    ElseIf rbcourse.SelectedIndex = "2" Then
        Me.hffee.Value = Convert.ToString(AdmissionFee.BSCN)
    ElseIf rbcourse.SelectedIndex = "3" Then
        Me.hffee.Value = Convert.ToString(AdmissionFee.BCOM)
    End If
End Sub

Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim fee As Integer
    fee = Convert.ToInt32(Me.hffee.Value)

    If Me.RdoGender.SelectedIndex = "1" Then
        fee += 750
    End If

    If Me.FE.Checked Then
        fee += 110
    End If

    If Me.dropboard.SelectedIndex > 0 Then
        fee += 100
    End If
End Sub

这是你要找的吗?

【讨论】:

  • thanx 兄弟,它起作用了,但我需要一些关于该费用价值的逻辑。即如果用户在表格中选择性别=“F”女性,那么每门课程价值750应添加到基值menas,如果BCOM费用为2500且性别为F,则应为3250,将750作为巴士费用添加到它
  • @arshad - 我更新了我的回复并在按钮点击时添加了巴士费用逻辑...请检查
  • 感谢您迄今为止所做的宝贵努力,它没有增加巴士费用的价值,让我为您提供性别 radioButtonlist 的确切 asp 标记
  • 感谢您迄今为止所做的宝贵努力,它没有增加巴士费用的价值,让我给您确切的性别 asp 标记 男性女性。对不起,我忘了提到还有两个东西有一个表(id = artstable),一个表的 td 包含复选框 FE 如果选中 hffee 还应添加 110 以及 adm 费和 busfee,第二个如果 SelectedIndex 不等于“0”,则有一个下拉列表 id= dropboard 将 100 添加到 hffee
  • 感谢您的回复,但您添加的三个条件并未仅添加到 hffee 字段 BA = 1200 BSC = 1800 BSCN = 2100 BCOM = 2500 条件有效我的意思是说条件如果 rdogender 是女性, 复选框 fe 和 dropboard >0 不会添加到 hffee 但
猜你喜欢
  • 1970-01-01
  • 2011-12-24
  • 2013-04-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-11-29
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多