如何声明会话 [英] How to declare session

查看:115
本文介绍了如何声明会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很抱歉这个问题,因为我对会议知之甚少以及如何申报,所以如果有人可以给我任何建议......这将是非常有帮助的

因为我正在使用这种代码的和平

< tr> 
< td colspan =4>
< div id =lblEmployeeId><%#Eval(QId)%>    <%#Eval(QText)%>< / div>
< asp:HiddenField ID =QIDrunat =serverValue ='<%#Eval(QId)%>'/>
< br />

< / td>

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


< asp:Repeater ID =Repeater1runat =server>
< ItemTemplate>
< td runat =server> < input type =radioname ='<%#Eval(QID)%>'value ='<%#Eval(AOptions)%>'id =AnswerOptionsstyle =显示:内联 ><%#的eval( AOptions)%>< /输入>< / TD>
<% - < asp:RadioButton ID =RadioButton1runat =servername ='<%#Eval(QID)%>'id ='<%#Eval( ID)%>'value ='<%#Eval(AOptions)%>'/><%#Eval(AOptions)%>< br /> - % >
< / ItemTemplate>
< / asp:Repeater>
< br />
< / tr>







为了使用转发器和我获取问题ID,问题文本和选项想使用会话来填写问题文本和选项。



我尝试过:



我一直在使用这个因为我对会话的了解不多



 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];
}
}
}

解决方案

声明会话变量的一种方法正如你在上面的代码中输入的那样。

类型在这种定义中无关紧要,因为任何类型匹配都将在运行时处理特定的代码行执行时。 :

会话[  QText ] = dt.Rows [ 0 ] [  QText ] 
// 这行代码将变量存储在Session [QText中]
// 通过您在[内指定的名称识别]。
// 为了使用存储在里面的变量,你可以使用它是这样的:
字符串 varA =会话[ QTEXT]的ToString();
// 在这种示例中,您必须确定变量的类型,因为
// 类型将
// 在运行时确定,你不会知道变量的类型
// 存储在



我希望这会帮助你!


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"];
               }
           }
       }

解决方案

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. :

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!


这篇关于如何声明会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆