using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class WebUserControl : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Class1 aas = new Class1();
// string id= Request.QueryString["id"];
string id = "1";
string str = "select * from member where id>@id";
;
SqlConnection con = new SqlConnection("Data Source=ZH-B0140C4856DE;DataBase=ycw;User ID=sa;PWD=owen2000");
con.Open();
SqlDataAdapter ssd = new SqlDataAdapter(str, con);
SqlParameter[] parms ={ aas.MakeInParam("@id", SqlDbType.BigInt, 50, id) };
ssd.SelectCommand.CommandType = CommandType.Text;
if (parms != null)
{
foreach (SqlParameter pp in parms)
ssd.SelectCommand.Parameters.Add(pp); }
DataSet ds = new DataSet();
ssd.Fill(ds);
DataList1.DataSource = ds.Tables[0].DefaultView;
DataList1.DataKeyField = "id";
DataList1.DataBind();
con.Close(); } }
protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
{
string[] userid ={ "dfd", "123" }; HttpCookie cookie = new HttpCookie("aspcn");
if ("redirect".Equals(e.CommandName))
{
this.Label3.Text = "hahaha"; ImageButton ib = (ImageButton)e.Item.FindControl("ImageButton1");
string id = ((Label)e.Item.FindControl("Label1")).Text;
cookie.Values.Add("id", id);
cookie.Values.Add("userid", userid); Response.AppendCookie(cookie);
Response.Redirect("cookie.aspx?id="+id+"");
} }
}
错误 1 出处
cookie.Values.Add("userid", userid); 中的cookie
错误1
与“System.Collections.Specialized.NameValueCollection.Add(string, string)”最匹配的重载方法具有一些无效参数错误2出处
cookie.Values.Add("userid", userid); 中的userid
错误 2 参数“2”: 无法从“string[]”转换为“string”
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;public partial class cookie : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string id = Request.Cookies["aspcn"]["id"].ToString(); for (int j = 0; j < cookie.Count; j++)
{ Response.Write("子键名=" + Cookies["aspcn"]["userid"] + "<br/>");
}
this.Label1.Text = id;
}
}
}错误3出处 for (int j = 0; j < cookie.Count; j++) 中的 count
错误 3 “cookie”并不包含“Count”的定义
错误4
错误 4 当前上下文中不存在名称“Cookies” 哪位高手帮我看看这几个错误怎么改 帮我把改的代码贴出来
谢谢
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class WebUserControl : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Class1 aas = new Class1();
// string id= Request.QueryString["id"];
string id = "1";
string str = "select * from member where id>@id";
;
SqlConnection con = new SqlConnection("Data Source=ZH-B0140C4856DE;DataBase=ycw;User ID=sa;PWD=owen2000");
con.Open();
SqlDataAdapter ssd = new SqlDataAdapter(str, con);
SqlParameter[] parms ={ aas.MakeInParam("@id", SqlDbType.BigInt, 50, id) };
ssd.SelectCommand.CommandType = CommandType.Text;
if (parms != null)
{
foreach (SqlParameter pp in parms)
ssd.SelectCommand.Parameters.Add(pp); }
DataSet ds = new DataSet();
ssd.Fill(ds);
DataList1.DataSource = ds.Tables[0].DefaultView;
DataList1.DataKeyField = "id";
DataList1.DataBind();
con.Close(); } }
protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
{
string[] userid ={ "dfd", "123" }; HttpCookie cookie = new HttpCookie("aspcn");
if ("redirect".Equals(e.CommandName))
{
this.Label3.Text = "hahaha"; ImageButton ib = (ImageButton)e.Item.FindControl("ImageButton1");
string id = ((Label)e.Item.FindControl("Label1")).Text;
cookie.Values.Add("id", id);
cookie.Values.Add("userid", userid); Response.AppendCookie(cookie);
Response.Redirect("cookie.aspx?id="+id+"");
} }
}
错误 1 出处
cookie.Values.Add("userid", userid); 中的cookie
错误1
与“System.Collections.Specialized.NameValueCollection.Add(string, string)”最匹配的重载方法具有一些无效参数错误2出处
cookie.Values.Add("userid", userid); 中的userid
错误 2 参数“2”: 无法从“string[]”转换为“string”
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;public partial class cookie : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string id = Request.Cookies["aspcn"]["id"].ToString(); for (int j = 0; j < cookie.Count; j++)
{ Response.Write("子键名=" + Cookies["aspcn"]["userid"] + "<br/>");
}
this.Label1.Text = id;
}
}
}错误3出处 for (int j = 0; j < cookie.Count; j++) 中的 count
错误 3 “cookie”并不包含“Count”的定义
错误4
错误 4 当前上下文中不存在名称“Cookies” 哪位高手帮我看看这几个错误怎么改 帮我把改的代码贴出来
谢谢
解决方案 »
- 谁有论坛常见的评价控件。。急急急!!!
- 百度知道追问功能怎么实现,重点是数据库设计结构怎么做!
- 进度条跟数据库交互~~~~
- 有权限判别的无刷新树
- 基础问题请教关于using return
- 急急急急急c#问题
- ado.net read()函数不好使呀,怎么判断有没有数据!
- 如何实现Excel表格的导入??另外就是ASP.net中怎么实现上传文件啊!
- 一个aspx页面里有几个<input type=file>文件框和 AutoPostBack 的服务端客控件,怎样在服务端控件触发 PostBack 之后保持文件框里输入的
- 12点一过,马上来提问,因为又有10分了,高手别嫌少啊
- 安装程序无法复制custsat.dll文件,这是怎么回事?
- 价格区间查询语句。。。。。。。。。。。
Response.Cookies["userinfo1"]["name"].value="1";
Response.Cookies["userinfo1"]["last"].value="1";
Response.Cookies["userinfo1"].Expires=DateTime.MaxValue; //方式2:
HttpCookie cookie = new HttpCookie("userinfo1");
cookie.Values["name"]="mike";
cookie.Values["last"]="a";
cookie.Expires=DateTime.MaxValue;
//cookie.Expires = System.DateTime.Now.AddDays(1);
Response.Cookies.Add(cookie);
//多值Cookie的读取
If ( Request.Cookies["userInfo1"]!=null )
{
string name=Request.Cookies["userInfo1"]["name"];
string last=Request.Cookies["userInfo1"]["last"];
} 你参考一下吧
http://msdn.microsoft.com/en-us/library/system.collections.specialized.namevaluecollection.add.aspx
错误3:cookie被你定义为类名了,System.Web.UI.Page怎么还会有Count属性?
错误4:从来没有见你定义过Cookies,怎么能调用?至于怎么改,你自己研究一下吧。
cookie.Values.Add("userid", userid); 中的cookie
错误1
与“System.Collections.Specialized.NameValueCollection.Add(string, string)”最匹配的重载方法具有一些无效参数
cookie.Values.Add(这里边是两个string的参数),而你的userid是一个string[]错误2出处
cookie.Values.Add("userid", userid); 中的userid
错误 2 参数“2”: 无法从“string[]”转换为“string”Add()方法中是两个string的参数,而你的userid是一个string[] 所以它会报无法从string[]转到string
错误 3 “cookie”并不包含“Count”的定义
错误4
错误 4 当前上下文中不存在名称“Cookies” 修改你的代码为:
string id = Request.Cookies["aspcn"]["id"].ToString(); for (int j = 0; j < Request.Cookies.Count; j++)
{ Response.Write("子键名=" + Request.Cookies["aspcn"]["userid"] + " <br/>");
}