如何在会话中传递多个值并将其捕获到另一个页面并将其分配给下拉列表... [英] how to pass more than one value in session and catch it in anothe page and assign it to dropdownlist...

查看:84
本文介绍了如何在会话中传递多个值并将其捕获到另一个页面并将其分配给下拉列表...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

im在会话中传递了三个值,例如employeecode,month和year.并且还在另一个页面中捕获了三个变量的值.但是当我将这些值分配给drpempcode,drpmonth,drpyear这三个不同的下拉列表时,发生错误一个对象引用未设置为对象的实例".
请帮助我.....解决此问题.....

i m passing three values like employeecode,month and year in session.And also catch the value of three variable in another page.but when i m assigning these values to three different dropdownlist like drpempcode,drpmonth,drpyear a error occures "an object reference not set to instance of an object".
please help me.....to solve this.....

推荐答案

如果您希望我们对其进行修复,则需要发布代码.如果您有三个相关的值,请创建一个类并将其存储在会话中.如果您从会话中拉出值,请始终先检查它们是否为空.一个好技巧是创建一个像
这样的静态类.
静态类SessionStrings
{
公共静态字符串UserId ="UserId";
}

现在,当您访问会话时,请执行以下操作:

字符串s = Session [SessionStrings.UserId]作为字符串;

现在您不能打错字.
You need to post code if you want us to fix it. If you have three values that are related, create a class and store it in the session. If you pull values out of the session, always check if they are null first. A good trick is to create a static class like

static class SessionStrings
{
public static string UserId = "UserId";
}

Now when you access the session, do:

string s = Session[SessionStrings.UserId] as string;

Now you can''t make typos.


使用查询字符串将值从一页传递到另一页.您可以从查询字符串访问值.

像这样将所需的值发送到目标页(设为Default2.aspx)
Use Query strings to pass value from one page to another.And you can access the values from the query string.

Send the required value to the target page(Let it be Default2.aspx) like this
Response.Redirect("Default2.aspx?pid=" +txtData.Text);



您可以在目标页(Default2.aspx)上访问这些值.
例如:



You can access the values at the target page(Default2.aspx).
eg:

string projectid = Request.QueryString["pid"];



您可以使用''?''和''&''
通过查询字符串发送多个值



You can send multiple values throug query string like this using ''?'' and ''&''

Response.Redirect("Default2.aspx?pid=" +txtData.Text + "&fid=" + txtcountry.Text);



并以相同的方式访问值.



and access the values in same way.

string projectid = Request.QueryString["pid"];
string FeatureId= Request.QueryString["fid"];


这篇关于如何在会话中传递多个值并将其捕获到另一个页面并将其分配给下拉列表...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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