You must Sign In to post a response.
  • Category: ASP.NET

    Regarding textbox,radiobutton and listbox

    HI sir
    I have one textbox,two radio button and two listbox. when i will enter some text value in textbox, if i will click Radiobutton1 then the value of textbox will store in Listbox1, if i will click radio Button2 then the value of textbox will store in Listbox2. in asp.net
  • #765083
    Hi
    Prasanta

    Can you follow this code .



    <asp:TextBox ID="TxtOne" runat="server"></asp:TextBox>

    <asp:RadioButton ID="Rad1" runat="server" Text="RadControl1" AutoPostBack="true" OnCheckedChanged="Rad1_CheckedChanged" />
    <asp:RadioButton ID="Rad2" runat="server" Text="RadControl2" AutoPostBack="true" OnCheckedChanged="Rad2_CheckedChanged" />

    <asp:ListBox ID="lst1" runat="server" >

    </asp:ListBox>

    <asp:ListBox ID="lst2" runat="server">

    </asp:ListBox>



    Server Side



    protected void Rad1_CheckedChanged(object sender, EventArgs e)
    {
    if (Rad1.Checked)
    {
    lst1.Items.Add(TxtOne.Text);
    }

    }

    protected void Rad2_CheckedChanged(object sender, EventArgs e)
    {
    if (Rad2.Checked)
    {
    lst2.Items.Add(TxtOne.Text);
    }
    }


    try and let me know if not working means.

    Name : Dotnet Developer-2015
    Email Id :kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #765089
    Hi,

    What you have tried so far?

    as you said when you click on radiobutton you want to show the textbox value in to particular listbox.

    So, you need to wrote code under checkedchanged event of radiobutton and add the textbox value into listbox item.

    Already In response 1, they provide some sample for the same refer that if you still having any queries let us know.

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #765094
    1. You can do this using simple javascript/Jquery.
    Following is for single check box ,list box ... Alter the code based on your requriement

    <asp:ListBox ID="ListBox1" runat="server" Width="150" Height="60"></asp:ListBox>
    <br />
    <hr />
    <asp:TextBox ID="txtValue" runat="server" />
    <input type="checkbox" name="chk1" id="chk1" value="CheckBox1">
    <asp:Button ID="btnAdd" Text="Add" runat="server" OnClientClick="return AddValues()" />



    2. Implement the logic in your javascript

    <script type="text/javascript">
    function AddValues() {
    // Implement your validation (Which check box was checked based on the selection you can add the value
    var txtValue = document.getElementById("<%=txtValue.ClientID %>");
    var listBox = document.getElementById("<%= ListBox1.ClientID%>");
    var option = document.createElement("OPTION");
    option.innerHTML = txtValue.value;
    option.value = txtValue.value;
    listBox.appendChild(option);
    txtValue.value = "";
    return false;
    }
    </script>

    By Nathan
    Direction is important than speed

  • #765110
    it is like a small assignment, you can use javascript or server side code for it
    lets see how javascript will help you
    <script language="Javascript">
    function setValues()
    {
    //check if radio button 1 is selected
    if (document.getElementById("rb1").checked)
    {
    var v = document.form1.txtValue.value;
    // get the TextBox Value and assign it into the variable
    AddOpt = new Option(v, v);
    document.form1.listbox1.options[i++] = AddOpt;
    }
    else
    {
    var v = document.form1.txtValue.value;
    // get the TextBox Value and assign it into the variable
    AddOpt = new Option(v, v);
    document.form1.listbox2.options[i++] = AddOpt;

    }
    }
    </script>

    hope it helps

    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]


Sign In to post your comments