如何在UI中完全验证单选按钮

如何在UI中完全验证单选按钮

本文介绍了如何在UI中完全验证单选按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<tr>
                    <td align="center">
                        <cc1:iLabel ID="ilbl_BillingType" runat="server" Text="Billing Type" ></cc1:iLabel>
                    </td>
                    <td>
                        <asp:RadioButtonList ID="rb_BillingType" runat="server" RepeatDirection="Horizontal">
                            <asp:ListItem Value="1">Credit Card</asp:ListItem>
                            <asp:ListItem Value="2">Debit Card</asp:ListItem>
                            <asp:ListItem Value="3">By Cash</asp:ListItem>
                        </asp:RadioButtonList>
                    </td>
                </tr>

推荐答案

 <asp:requiredfieldvalidator
	ID="ReqVal_BillingType"
	runat="server"
	ControlToValidate="rb_BillingType"
	ErrorMessage="Select Billing Type!">
</asp:requiredfieldvalidator>


Protected Sub btnOrder_Click(sender As Object, e As System.EventArgs) Handles btnOrder.Click

        Dim con As New SqlConnection("Data Source=ICPU0089\SQL2012;Initial Catalog=AdventureWorks2008;User ID=sa;Password=sa@123")
        Dim Command As String
        Dim newCmd As String
        Dim count As Integer
        '  Dim Cust_id As Integer
        Dim Billing_Type As String
        Dim dt As New DataTable
        Dim Cust_Name As String = itxtCustName.Text
        Dim Address As String = itxtAddress.Text
        Dim City As String = itxtCity.Text
        Dim Country As String = itxtCountry.Text
        Dim Product_ID As Integer = CDbl(ilbl_Product_ID.Text)
        Dim Quantity As Integer = CDbl(itxtQuantity.Text)
        If rb_BillingType.SelectedIndex = 0 Then
            Billing_Type = "C"
        ElseIf rb_BillingType.SelectedIndex = 1 Then
            Billing_Type = "D"
            'ElseIf rb_BillingType.SelectedIndex = 2 Then
            '    Billing_Type = "B"
        Else
            'MsgBox("you ve to select one")
            'con.Close()
            Billing_Type = "B"

        End If

        'Dim Cust_id As Integer = ILookup1.Text

        newCmd = "SELECT COUNT(Cust_ID) FROM Customer_Test WHERE CUST_Name = '" & Cust_Name & "'"

        Dim cmd As New SqlCommand(newCmd, con)
        con.Open()
        count = Convert.ToInt32(cmd.ExecuteScalar())
        'Using(conn = new SqlConnection1 ("Data Source=ICPU0089\SQL2012;Initial Catalog=AdventureWorks2008;User ID=sa;Password=sa@123")
        'Using(select = New SqlCommand(newCmd, conn)
        'Select Case .Parameters.Add("@p1", TextBox.value)
        If count > 0 Then
            MsgBox("Hello!! Old Customer  you  CAN  update order ")
        Else
            'con.Close()

            Command = "insert into dbo.CUSTOMER_TEST (CUST_NAME,BILLING_TYPE,ADDRESS,CITY,COUNTRY,Product_ID,Quantity) values ('" & Cust_Name & "','" & Billing_Type & "','" & Address & "','" & City & "','" & Country & "' , '" & Product_ID & "' , '" & Quantity & "')"
            Dim Com As New SqlCommand(Command, con)
            'con.Open()
            Com.ExecuteNonQuery()
            con.Close()
            MsgBox(" order given  SUCESSFULLY ")
        End If





Public Sub bind()
       If Not ID Is Nothing Then
           Dim strconn = ConfigurationManager.AppSettings("ConnectionString").ToString()
           Dim str_SqlCust_Name As String = "select * from CUSTOMER_TEST "
           'where(CUST_ID = " & ID")
           Dim daCust_Name As New SqlDataAdapter(str_SqlCust_Name, strconn)
           Dim dtCust_Name As New DataTable()
           daCust_Name.Fill(dtCust_Name)
           itxtCustName.Text = dtCust_Name.Rows(0).Item("CUST_NAME")
           Dim billing_type As String = dtCust_Name.Rows(0).Item("BILLING_TYPE")
           itxtAddress.Text = dtCust_Name.Rows(0).Item("ADDRESS")
           itxtCity.Text = dtCust_Name.Rows(0).Item("CITY")
           itxtCountry.Text = dtCust_Name.Rows(0).Item("COUNTRY")
           If billing_type = "C" Then
               rb_BillingType.SelectedValue = 1
           ElseIf billing_type = "D" Then
               rb_BillingType.SelectedValue = 2
           ElseIf billing_type = "B" Then
               rb_BillingType.SelectedValue = 3
           Else
               MsgBox("you ve to select one")
               ' billing_type = "B"
           End If
       End If
   End Sub


这篇关于如何在UI中完全验证单选按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 15:50