By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,868 Members | 1,974 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,868 IT Pros & Developers. It's quick & easy.

How do I use session for RadioButtonList

P: 1
I have a page where user will select an item from RadioButtonList. When the user click next button, in the next page (this page has a GridView with 32 rows. Each row has a description - comes from database table and 3 textboxes) the depending on what he selected, textboxes from all 32 rows will either be enabled or disabled. That is if for example he selected Employee list item, all textboxes associated with employee in page 2 will be enabled. The other 2 will be read only. Then the user can enter a number on enabled textboxes. I also want to calculate Grand Total cost (each row is a service with cost in a table in database)for the services. This will be all textboxes the user entered a number multiplied by the cost of each service. I want to show that total in a different page when the user click next button.
I want to use session because nothing will be saved in the database. How do I do this?
Code for RadioButtonList in PersonalFactors.aspx page
Expand|Select|Wrap|Line Numbers
  1. <asp:RadioButtonList ID="chkPlanCategoryList" runat="server" 
  2.               AutoPostBack="True">
  3.             <asp:ListItem Text="Employee only" Value="0" />
  4.             <asp:ListItem Text="Employee Plus Child(ren)" Value="1" />
  5.             <asp:ListItem Text="Employee Plus Spouse" Value="2" />
  6.             <asp:ListItem Text="Family" Value="3"/>
  7.             </asp:RadioButtonList>
Codebehind for PersonalFactors.aspx page
Expand|Select|Wrap|Line Numbers
  1. Imports System.Data
  2. Imports System.Data.SqlClient
  3. Imports System.Web.UI.WebControls
  4. Public Class PersonalFactors
  5.   Inherits System.Web.UI.Page
  6.  
  7.   Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  8.     Session("parm") = chkPlanCategoryList.SelectedValue
  9.   End Sub
  10.  
  11.   Protected Sub btnNext_Click(sender As Object, e As System.EventArgs) Handles btnNext.Click
  12.     Dim str As String = chkPlanCategoryList.SelectedItem.Text
  13.  
  14.     'Response.Redirect("Result.aspx?parm=" & str)
  15.     'Response.Redirect("Service.aspx?parm=" & str)
  16.   End Sub
  17.  
  18.   Protected Sub btnBack_Click(sender As Object, e As System.EventArgs) Handles btnBack.Click
  19.     Response.Redirect("Home.aspx")
  20.   End Sub
  21.  
  22. End Class
Code for Service.aspx page
Expand|Select|Wrap|Line Numbers
  1. <div id="container">
  2.     <div id="header">Employee Estimated Annual Medical Usage</div>
  3.  
  4.     <div id="instructions">
  5.         Enter the number of times you or people in your family will use 
  6.     the following medical services during the year. When finished click next button to continue.
  7.         </div>
  8.   <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
  9.   DataSourceID="SqlDataSource1" Width="957px" GridLines="Vertical" 
  10.     CellPadding="3" BackColor="White" BorderColor="#999999" BorderStyle="None" 
  11.     BorderWidth="1px">
  12.     <AlternatingRowStyle BackColor="#DCDCDC" />
  13.     <Columns>
  14.       <asp:TemplateField HeaderText="Medical Service Description" 
  15.         SortExpression="hcs_Description">
  16.         <EditItemTemplate>
  17.           <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("hcs_Description") %>'></asp:TextBox>
  18.         </EditItemTemplate>
  19.         <ItemTemplate>
  20.           <asp:Label ID="Label1" runat="server" Text='<%# Bind("hcs_Description") %>'></asp:Label>
  21.         </ItemTemplate>
  22.         <ControlStyle CssClass="smalllabel" />
  23.         <HeaderStyle HorizontalAlign="Left" />
  24.         <ItemStyle HorizontalAlign="Left" />
  25.       </asp:TemplateField>
  26.       <asp:TemplateField HeaderText="Employee">
  27.         <ItemTemplate>
  28.           <asp:TextBox ID="txtEmployee" runat="server" maxlength="2" size="3" class="numberinput"></asp:TextBox>
  29.           <cc2:FilteredTextBoxExtender ID="FilteredTextBoxExtender1" runat="server"
  30.           FilterType="Numbers" TargetControlID="txtEmployee" />
  31.         </ItemTemplate>
  32.         <HeaderStyle HorizontalAlign="Left" />
  33.       </asp:TemplateField>
  34.        <asp:TemplateField HeaderText="Spouse">
  35.         <ItemTemplate>
  36.         <asp:TextBox ID="txtSpouse" runat="server" maxlength="2" size="3" class="numberinput"></asp:TextBox>
  37.         <cc2:FilteredTextBoxExtender ID="FilteredTextBoxExtender2" runat="server"
  38.           FilterType="Numbers" TargetControlID="txtSpouse" />
  39.         </ItemTemplate>
  40.          <HeaderStyle HorizontalAlign="Left" />
  41.       </asp:TemplateField>
  42.        <asp:TemplateField HeaderText="Child">
  43.         <ItemTemplate>
  44.           <asp:TextBox ID="txtChild" runat="server" maxlength="2" size="3" class="numberinput"></asp:TextBox>
  45.           <cc2:FilteredTextBoxExtender ID="FilteredTextBoxExtender3" runat="server"
  46.           FilterType="Numbers" TargetControlID="txtChild" />
  47.         </ItemTemplate>
  48.          <HeaderStyle HorizontalAlign="Left" />
  49.       </asp:TemplateField>
  50.     </Columns>
  51.  
  52.     <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
  53.  
  54.     <HeaderStyle BorderStyle="Groove" BackColor="#000084" Font-Bold="True" 
  55.       ForeColor="White" />
  56.  
  57.     <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
  58.  
  59.     <RowStyle BorderStyle="Groove" CssClass="grayservicebackground" 
  60.       BackColor="#EEEEEE" ForeColor="Black" />
  61.  
  62.     <SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
  63.     <SortedAscendingCellStyle BackColor="#F1F1F1" />
  64.     <SortedAscendingHeaderStyle BackColor="#0000A9" />
  65.     <SortedDescendingCellStyle BackColor="#CAC9C9" />
  66.     <SortedDescendingHeaderStyle BackColor="#000065" />
  67.  
  68.   </asp:GridView>
  69.  
  70. <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
  71.   ConnectionString="<%$ ConnectionStrings:ConnectionString3 %>" 
  72.   ProviderName="<%$ ConnectionStrings:ConnectionString3.ProviderName %>" 
  73.   SelectCommand="  SELECT hcs_Description, hcs_Employee, hcs_Spouse, hcs_Child FROM [HealthCareEstimator].[hce].[HealthCareService]" >
  74. </asp:SqlDataSource>
  75. </div>
Codebehind for Service.aspx page
Expand|Select|Wrap|Line Numbers
  1. Public Class Service
  2.     Inherits System.Web.UI.Page
  3.  
  4.     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  5.  
  6.     End Sub
  7.  
  8.   Protected Sub GridView1_SelectedIndexChanged(sender As Object, e As GridViewRowEventArgs) Handles GridView1.RowDataBound
  9.     If e.Row.RowType = DataControlRowType.DataRow Then
  10.       Dim txtemployee As TextBox = CType(e.Row.FindControl("txtemployee"), TextBox)
  11.       Dim txtspouse As TextBox = CType(e.Row.FindControl("txtspouse"), TextBox)
  12.       Dim txtChild As TextBox = CType(e.Row.FindControl("txtchild"), TextBox)
  13.       Select Case Session("parm")
  14.         Case "0"   ' Employee only
  15.  
  16.           txtemployee.Visible = True
  17.           txtspouse.Visible = False
  18.           txtChild.Visible = False
  19.         Case "1"   ' Employee Plus Child(ren)
  20.           txtemployee.Visible = True
  21.           txtspouse.Visible = False
  22.           txtChild.Visible = True
  23.         Case "2"   ' Employee Plus Spouse
  24.           txtemployee.Visible = True
  25.           txtspouse.Visible = True
  26.           txtChild.Visible = False
  27.         Case "3"   ' Family
  28.           txtemployee.Visible = True
  29.           txtspouse.Visible = True
  30.           txtChild.Visible = True
  31.       End Select
  32.     End If
  33.   End Sub
  34.  
  35.   Protected Sub btnNext_Click(sender As Object, e As EventArgs) Handles btnNext.Click
  36.     Response.Redirect("~/Users/EstimatedHealthBenefitCost")
  37.   End Sub
  38. End Class
Sep 24 '13 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.