我有一个嵌套的 DataList 结构DataList2
,其中DataList1
有 2 个执行某些命令,我想调用一个将of和of作为输入的过程,但是读取of时出现问题,这是我的代码:Buttons
DataList2
datakeyfield
DataList1
datakeyfield
DataList2
datakeyfield
DataList2
.aspx.cs 代码
protected void DataList2_ItemCommand(object source, DataListCommandEventArgs e)
{
if ((e.CommandName == "accept") && (e.CommandArgument != null))
{
string connStr = ConfigurationManager.ConnectionStrings["MyDbConn"].ToString();
SqlConnection conn = new SqlConnection(connStr);
int team_ID = (int)DataList1.DataKeys[e.Item.ItemIndex];
SqlCommand cmd = new SqlCommand("accept_member", conn);
string member = (string)DataList2.DataKeys[e.Item.ItemIndex];
cmd.CommandType = CommandType.StoredProcedure;
string email = Session["email"].ToString();
int course_ID = Convert.ToInt32(Request.QueryString["courseID"]);
cmd.Parameters.Add(new SqlParameter("@course_ID", course_ID));
cmd.Parameters.Add(new SqlParameter("@team_ID", team_ID));
cmd.Parameters.Add(new SqlParameter("@myemail", email));
cmd.Parameters.Add(new SqlParameter("@member", member));
cmd.Parameters.Add(new SqlParameter("@respond", 1));
SqlParameter count = cmd.Parameters.Add("@count", SqlDbType.Int);
count.Direction = ParameterDirection.Output;
conn.Open();
cmd.ExecuteNonQuery();
if (@count.Value.ToString().Equals("1"))
{
Response.Write(@member + " " + "joined your team");
}
else
{
Response.Write("team is full or not found");
}
}
else if ((e.CommandName == "reject") && (e.CommandArgument != null))
{
int team_ID = (int)DataList1.DataKeys[e.Item.ItemIndex];
string connStr = ConfigurationManager.ConnectionStrings["MyDbConn"].ToString();
SqlConnection conn = new SqlConnection(connStr);
string member = (string)DataList2.DataKeys[e.Item.ItemIndex];
SqlCommand cmd = new SqlCommand("accept_member", conn);
cmd.CommandType = CommandType.StoredProcedure;
string email = Session["email"].ToString();
int course_ID = Convert.ToInt32(Request.QueryString["courseID"]);
cmd.Parameters.Add(new SqlParameter("@course_ID", course_ID));
cmd.Parameters.Add(new SqlParameter("@team_ID", team_ID));
cmd.Parameters.Add(new SqlParameter("@myemail", email));
cmd.Parameters.Add(new SqlParameter("@member", member));
cmd.Parameters.Add(new SqlParameter("@respond", "0"));
SqlParameter count = cmd.Parameters.Add("@count", SqlDbType.Int);
count.Direction = ParameterDirection.Output;
conn.Open();
cmd.ExecuteNonQuery();
if (@count.Value.ToString().Equals("1"))
{
Response.Write(@member + " " + "has been rejected");
}
else
{
Response.Write("team is full or not found");
}
}
DataList2.DataBind();
}
错误:
当前上下文中不存在名称“DataList2”