locked
Vb.net question RRS feed

  • Question

  • User1298215938 posted
    protected Sub Submit_Click(sender As Object, e As EventArgs) Handles Submit.Click
    Dim Billpp As String = String.Empty
    If rbYes.Checked Then
    Billpp = "Y"
    ElseIf rbNo.Checked Then
    Billpp = "N"
    End If
    Dim constr As String = ConfigurationManager.ConnectionStrings("Cong").ConnectionString
    Using con As New SqlConnection(constr)
    Using cmd As New SqlCommand("INSERT INTO Tbillpp(Billpp,ClaimID,JobID) VALUES(@Billpp,@ClaimID,@JobID)")
    cmd.Connection = con
    cmd.Parameters.AddWithValue("@Billpp", Billpp)
    cmd.Parameters.AddWithValue("@ClaimID", Request.QueryString("ClaimID"))
    cmd.Parameters.AddWithValue("@JobID", Request.QueryString("JobID"))
    con.Open()
    cmd.ExecuteNonQuery()
    con.Close()
    End Using
    End Using
    End Sub
    End Class

    how can I change the code so it deplays the current radio button valve?
    Wednesday, February 28, 2018 9:08 PM

Answers

  • User475983607 posted

    how can I change the code so it deplays the current radio button valve?

    The way the code is written it appears you have two different radio button.  You should use a radio button list.

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="default.aspx.cs" Inherits="WebFormsDemo._default" %>
    
    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Default</title>
    </head>
    <body>
        <form id="form1" runat="server" method="post">
    
            <asp:RadioButtonList ID="YesNo" runat="server">
                <asp:ListItem Text="Yes" Value="Y"></asp:ListItem>
                <asp:ListItem Text="No" Value="N"></asp:ListItem>
            </asp:RadioButtonList>
            <hr /> 
            <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
            <div>
                <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
            </div>
        </form>
    
    </body>
    </html>
    
    
    
    
    namespace WebFormsDemo
    {  
        public partial class _default : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
    
    
            }
    
            protected void Button1_Click(object sender, EventArgs e)
            {
                Label1.Text = "You selected " + YesNo.Text;
            }
        }
    
    
    }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, February 28, 2018 9:40 PM

All replies

  • User475983607 posted

    how can I change the code so it deplays the current radio button valve?

    The way the code is written it appears you have two different radio button.  You should use a radio button list.

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="default.aspx.cs" Inherits="WebFormsDemo._default" %>
    
    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Default</title>
    </head>
    <body>
        <form id="form1" runat="server" method="post">
    
            <asp:RadioButtonList ID="YesNo" runat="server">
                <asp:ListItem Text="Yes" Value="Y"></asp:ListItem>
                <asp:ListItem Text="No" Value="N"></asp:ListItem>
            </asp:RadioButtonList>
            <hr /> 
            <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
            <div>
                <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
            </div>
        </form>
    
    </body>
    </html>
    
    
    
    
    namespace WebFormsDemo
    {  
        public partial class _default : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
    
    
            }
    
            protected void Button1_Click(object sender, EventArgs e)
            {
                Label1.Text = "You selected " + YesNo.Text;
            }
        }
    
    
    }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, February 28, 2018 9:40 PM
  • User283571144 posted

    Hi MOHIIMRAN,

    As mgebhard says, I suggest you could try to use radiobutton list.

    If you use two radio button, we could select both two button.

    More details, you could refer to below codes:

            <asp:RadioButtonList ID="YesNo" runat="server">
                <asp:ListItem Text="Yes" Value="Y"></asp:ListItem>
                <asp:ListItem Text="No" Value="N"></asp:ListItem>
            </asp:RadioButtonList>

    Codebehind:

        Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Response.Write(YesNo.SelectedItem.Value.ToString())
        End Sub

    Result:

    Best Regards,

    Brando

    Thursday, March 1, 2018 2:27 AM