Hi Rucha,
Check this example. Now please take its reference and correct your code.
HTML
<asp:DataList ID="dlFeesDetails" runat="server" RepeatColumns="1" CellSpacing="4"
RepeatLayout="Table" RepeatDirection="Vertical" BorderWidth="1px" HorizontalAlign="Center">
<ItemTemplate>
<table class="table">
<tr>
<td colspan="1">
<asp:RadioButton ID="RadioButton1" runat="server" name="rdGroup" GroupName="a" value='<%# Eval("Total") %>'
OnCheckedChanged="RadioButton1_CheckedChanged" AutoPostBack="true" />
</td>
<td colspan="2">
<%# Eval("MainTitle") %>
</td>
<td colspan="2">
<asp:Label ID="lblTotal" Text='<%# Eval("Total") %>' runat="server" />
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
<br />
Total:
<asp:Label ID="lblTotal" runat="server" />
Namespaces
C#
using System.Data;
VB
Imports System.Data
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[2] {
new DataColumn("MainTitle", typeof(string)),
new DataColumn("Total", typeof(double))});
dt.Rows.Add("Symposium", 2950);
dt.Rows.Add("Symposium1", 1500);
dlFeesDetails.DataSource = dt;
dlFeesDetails.DataBind();
}
}
protected void RadioButton1_CheckedChanged(object sender, EventArgs e)
{
RadioButton rb = (sender as RadioButton);
if (rb.Checked)
{
Label total = (rb.NamingContainer).FindControl("lblTotal") as Label;
lblTotal.Text = total.Text;
}
}
VB
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
Dim dt As DataTable = New DataTable()
dt.Columns.AddRange(New DataColumn(1) {New DataColumn("MainTitle", GetType(String)), New DataColumn("Total", GetType(Double))})
dt.Rows.Add("Symposium", 2950)
dt.Rows.Add("Symposium1", 1500)
dlFeesDetails.DataSource = dt
dlFeesDetails.DataBind()
End If
End Sub
Protected Sub RadioButton1_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs)
Dim rb As RadioButton = (TryCast(sender, RadioButton))
If rb.Checked Then
Dim total As Label = TryCast((rb.NamingContainer).FindControl("lblTotal"), Label)
lblTotal.Text = total.Text
End If
End Sub
Screenshot
