gpt4 book ai didi

c# - 嵌套数据列表的问题

转载 作者:太空宇宙 更新时间:2023-11-03 11:28:12 25 4
gpt4 key购买 nike

我在 DataList1 中有一个嵌套的 DataList 结构 DataList2,其中我在 DataList2 中有两个 Buttons 执行某些操作命令。

我想调用一个过程,它将 DataList1datakeyfieldDataList2datakeyfield 作为输入。但是,读取 DataList2datakeyfield 时出现问题。这是我的代码:

.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();
}

错误

The name "DataList2" does not exist in the current context

最佳答案

假设你的数据在DataList1中产生不止一行,那么DataList2就不止一个。因此,ASP.NET 不会使 DataList2 成为页面(代码隐藏)类的成员。

幸运的是,在这种情况下,发送者(你称之为源,同样的东西)应该是你想要的 DataList2。尝试将其转换为 DataList,看看会发生什么。

关于c# - 嵌套数据列表的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8689635/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com