Click here to Skip to main content
15,909,827 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I am sorry to as you this question, As i know little about the session and how to declare, So if any one can give me any suggestion regarding it...it would be very helpful
as I am using this peace of code
<tr>
                       <td colspan="4">
                            <div id="lblEmployeeId" ><%# Eval("QId")%>    <%# Eval("QText")%></div>
                           <asp:HiddenField ID="QID" runat="server" Value='<%# Eval("QId")%>'/>
                           <br />

                       </td>

                   </tr>
                   <tr class="table-row">


                           <asp:Repeater ID="Repeater1" runat="server">
                                    <ItemTemplate>
                                <td runat="server"> <input type="radio" name='<%#Eval("QID")%>'  value='<%#Eval("AOptions")%>' id="AnswerOptions" style="display:inline"><%#Eval("AOptions")%></input></td>
                                     <%--   <asp:RadioButton ID="RadioButton1" runat="server" name='<%#Eval("QID")%>' id='<%#Eval("ID")%>' value='<%#Eval("AOptions")%>' /><%#Eval("AOptions")%><br />--%>
                                    </ItemTemplate>
                               </asp:Repeater>
                           <br />
                   </tr>



In order to get Question ID,Question Text And Options using repeater and i wanna fatch the Question Text and Options using session.

What I have tried:

I have been using this because of less knowledge i have about session

private void BindEmployeeData()
   {
       string connection = ConfigurationManager.AppSettings["Connection"].ToString();
       using (SqlConnection con = new SqlConnection(connection))
       {
           using (SqlCommand objCommand = new SqlCommand("SELECT * FROM t_Question", con))
           {
               using (SqlDataAdapter objSqlDataAdapter = new SqlDataAdapter(objCommand))
               {
                   DataTable dt = new DataTable();
                   dt.Columns.Add("QId");
                   dt.Columns.Add("QText");
                   objSqlDataAdapter.Fill(dt);
                   Repeater0.DataSource = dt;
                   Repeater0.DataBind();
                   Session["QText"] = dt.Rows[0]["QText"];
               }
           }
       }
Posted
Updated 2-Jul-17 20:36pm

1 solution

One way to declare the Session Variable is exactly how you typed it in the code above.
The type does not matter in this kinda of definition since any type match will be handled during runtime when the specific line of code will execute. :
C#
Session["QText"] = dt.Rows[0]["QText"]
//This line of code will store the variable inside the Session["QText"] which will be
//recognized through the name you have assigned inside the [" "].
//In order to use the variable that is stored inside you can just use it like this:
String varA = Session["QText"].ToString();
//In this kind of example you have to be sure on what type the variable is , since
// the type will be
//determined during runtime and you will not know what type of variable will be
//stored inside

I Hope this will help you out!
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900