内部にネストされた 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」は現在のコンテキストに存在しません