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

    How to connect radiobutton and listbox in asp.net vb

    Hi I have 3radio buttons 1.open 2.confidential to department 3.selected to restricted users and I have a list below where all the users name will display in that list box. How to connect those radio buttons with users list for example I select restricted to selected users and select 2users in list box those users cannot see the data but what my problem is when I select users and restricted to selected users but still they can view the data how to link this radiobuttons and list. can anyone help me to fix this issue. Below is the code for radio buttons.

    asp:radiobuttonlist id="rbSecurityLevel" runat="server">
    <asp:listitem id="option1" runat="server" value="Open" />
    <asp:listitem id="option2" runat="server" value="Confidential to Department" />
    <asp:listitem id="option3" runat="server" value="Restricted to Selected Users" />
    </asp:radiobuttonlist >
  • #763998
    Hai samyuktha,
    I think you are not resetting the list-box when you change the option.
    While binding the data to the list-box, first you need to clear it and then bind it based on the selection of the radio-button.
    Hope it will resolve your issue.

    Regards,
    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)
    pawansoftit@gmail.com

  • #764000
    Hi

    I assume your issue this try this piece of code


    Aspx Code.



    <asp:RadioButtonList id="rbSecurityLevel" runat="server" AutoPostBack="true" OnSelectedIndexChanged="rbSecurityLevel_SelectedIndexChanged">
    <asp:listitem id="option1" runat="server" value="1">Open</asp:listitem>
    <asp:listitem id="option2" runat="server" value="2">Confidential to Department</asp:listitem>
    <asp:listitem id="option3" runat="server" value="3">Restricted to Selected Users</asp:listitem>
    </asp:RadioButtonList>



    Server side Code -> c#

    protected void rbSecurityLevel_SelectedIndexChanged(object sender, EventArgs e)
    {
    string ss = rbSecurityLevel.SelectedValue;
    }

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

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

  • #764006
    Hi pawan can you please help me how to bind list box with radio button

  • #764007
    Hi Prasad no change still the same issue I just want to check with you did you understand my question??

  • #764008
    Hi

    If you need asp:RadioButtonList based load to listbox for users from database means use this piece of code

    Client Side -> Aspx Code


    <form id="form1" runat="server">
    <asp:RadioButtonList id="rbSecurityLevel" runat="server" AutoPostBack="true" OnSelectedIndexChanged="rbSecurityLevel_SelectedIndexChanged">
    <asp:listitem id="option1" runat="server" value="1">Open</asp:listitem>
    <asp:listitem id="option2" runat="server" value="2">Confidential to Department</asp:listitem>
    <asp:listitem id="option3" runat="server" value="3">Restricted to Selected Users</asp:listitem>
    </asp:RadioButtonList>

    <h1>List Box</h1>
    <asp:ListBox ID="lstemployee" runat="server"></asp:ListBox>

    </form>


    Server Side C# Code

    protected void rbSecurityLevel_SelectedIndexChanged(object sender, EventArgs e)
    {
    if (rbSecurityLevel.SelectedValue == "1")
    {
    lstemployee.Items.Clear();
    BindRecords();
    }
    else if (rbSecurityLevel.SelectedValue == "2")
    {
    lstemployee.Items.Clear();
    BindRecords();
    }
    else if (rbSecurityLevel.SelectedValue == "3")
    {
    lstemployee.Items.Clear();
    BindRecords();
    }
    }

    private void BindRecords()
    {
    DataTable Dt = new DataTable();
    SqlDataAdapter sqlad = new SqlDataAdapter("Select * from EmpDetails", sqlcon);
    sqlad.Fill(Dt);
    lstemployee.DataSource = Dt;
    lstemployee.DataTextField = "EmpName";
    lstemployee.DataValueField = "EmpId";
    lstemployee.DataBind();
    }



    Refer below image for output snapshot

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

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

    Delete Attachment

  • #764009
    Hi

    If you did not got solution in my response means share your code here

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

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

  • #764010
    Hi kumar can I code in vb.net

  • #764011
    Hi

    I converted for vb.net try this code .

    Client Side same server side this

    But if you did not solution means share your code


    Protected Sub rbSecurityLevel_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
    If rbSecurityLevel.SelectedValue = "1" Then
    lstemployee.Items.Clear()
    BindRecords()
    Else If rbSecurityLevel.SelectedValue = "2" Then
    lstemployee.Items.Clear()
    BindRecords()
    Else If rbSecurityLevel.SelectedValue = "3" Then
    lstemployee.Items.Clear()
    BindRecords()
    End If
    End Sub

    Private Sub BindRecords()
    Dim Dt As DataTable = New DataTable()
    Dim sqlad As SqlDataAdapter = New SqlDataAdapter("Select * from EmpDetails",sqlcon)
    sqlad.Fill(Dt)
    lstemployee.DataSource = Dt
    lstemployee.DataTextField = "EmpName"
    lstemployee.DataValueField = "EmpId"
    lstemployee.DataBind()
    End Sub


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

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

  • #764018
    Hi Prasad it dint work below is the screen shot may be you can understand clearly

    Delete Attachment

  • #764019
    Hi

    What is your issue ?

    Option based load users to the list box?

    I mention above vb.net code like this

    can you explain more

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

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

  • #764020
    Hi Prasad it dint work below is the screen shot may be you can understand clearly

    Delete Attachment

  • #764021
    Hi when I select selectedUers radiobutton and select some users it should be access to selected persons but not connected to radiobuttons and list box

  • #764048
    Hai Samyuktha,
    This should be easy to implement. I think your desing is not as per the requirements.
    First you need to select the users from the listbox and then you need to select the radio button to restrict the users who are selected in the listbox.
    So the issue which i am thinking is postback in the radiobutton list.
    If you want it to be in the same design, first remove the postback implementation for the radiobutton list.
    So when you click on the restricted users checkbox, and then you will select few users from the list and then click on the > button to move the selected users to the right side with the flag as restricted users.
    So in the > button, you need to write the code which will have the users as well as the flag for the restricted users. and save in the database.
    Try to implement as this is easy. If you don't get, just reply to the thread.
    Hope it will be helpful to you.

    Regards,
    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)
    pawansoftit@gmail.com

  • #764189
    Hi pawan can you send code


Sign In to post your comments