vijay

welcome Netizen

Share Your Knowledge.It is a way to achieve immortality

Monday, June 4, 2012

How to use radio button(single selection) inside listview in asp.net


Introduction:
Article about to use radio button inside listview..Recently i had an option work with radio button inside listview, Normally i always prefer to use JavaScript to make single selection
in radio button, in my case listview control unable to find in javascript really i got frustrated to make to find listview in script. Finally i done the code in server side and accomblish my needs.
Here i share the code to make single selection as radio button inside listview

Code:

Radiobutton inside listview..
<ItemTemplate>
<asp:RadioButton ID="rdb" runat="server" Text='<%#Eval("CARDESC")%>' AutoPostBack="true"   OnCheckedChanged="rdbSelect_Changed"/>
</ItemTemplate>

Server code onchecked change event..
Protected Sub rdb_Changed(ByVal sender As Object, ByVal e As System.EventArgs)

        Dim rb1 As RadioButton = CType(sender, RadioButton)

        For Each row As ListViewItem In lstvwdet.Items
            Dim rb As RadioButton = row.FindControl("rdb")
            If rb IsNot Nothing AndAlso rb.Checked Then
                rb.Checked = False
            End If
        Next
        rb1.Checked = True
    End Sub

In case if you have need to get the selected radio button text  in outside button use the below code to find the selected radio button text
For Each row As ListViewItem In lstvwdet.Items
            Dim rb As RadioButton = row.FindControl("rdb")
            If rb.Checked = True Then
                Str = rb.Text
            End If
        Next

Keep reading……..

0 comments:

Post a Comment