DataBinding:“System.Data.DataRowView”不包含名为“Tasklist”的属性

您所在的位置:网站首页 databinding不包含名为的属性 DataBinding:“System.Data.DataRowView”不包含名为“Tasklist”的属性

DataBinding:“System.Data.DataRowView”不包含名为“Tasklist”的属性

2024-07-11 02:39| 来源: 网络整理| 查看: 265

我正在制作一个包含两个网格视图的页面,其中一个上的事件负责另一个上的内容。(例如,如果您有一个任务,而您的任务有一些步骤,所以当您单击任务列表中的任务时,您可以看到与该任务关联的步骤表),但我面临如上所述的异常。有谁能帮我解决这个问题吗?

index.aspx

代码语言:javascript复制 td, th { border-color: rgb(222, 226, 230); } ; No available tasklists! Create a new one? Name Description Prerequisites ; Tag ; No available objectives for the selected tasklist! Create a new one? Name ; window.jQuery || document.write('') feather.replace() var tables = document.getElementsByTagName('table'); for (var i = 0; i < tables.length; i++) { document.getElementsByTagName('table')[i].className += " table-hover"; document.getElementsByTagName('table')[i].className += " thead-dark"; document.getElementsByTagName('table')[i].className += " table-responsive-sm"; }

index.aspx.cs

代码语言:javascript复制using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using System.Data.SqlClient; using System.Configuration; public partial class index : System.Web.UI.Page { SqlConnection connection = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"].ToString()); SqlDataAdapter adapter = new SqlDataAdapter(); SqlCommand command = new SqlCommand(); DataTable table = new DataTable(); protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { showTasklists(); } } private void showTasklists() { try { command.Connection = connection; command.CommandText = "select * from tasklist"; adapter = new SqlDataAdapter(command); adapter.Fill(table); tasklistsGridView.DataSource = table; tasklistsGridView.DataBind(); } catch (Exception x) { Response.Write("Exception: " + x.Message); } } protected void tasklistsGridView_PageIndexChanging(object sender, GridViewPageEventArgs e) { tasklistsGridView.PageIndex = e.NewPageIndex; showTasklists(); } protected void tasklistsGridView_RowDeleting(object sender, GridViewDeleteEventArgs e) { try { command.Connection = connection; command.CommandText = "delete from tasklist where Id='" + tasklistsGridView.DataKeys[e.RowIndex].Values[0].ToString() + "'"; connection.Open(); command.ExecuteNonQuery(); connection.Close(); showTasklists(); } catch (Exception x) { Response.Write("Exception: " + x.Message); } } protected void tasklistsGridView_RowEditing(object sender, GridViewEditEventArgs e) { tasklistsGridView.EditIndex = e.NewEditIndex; showTasklists(); } protected void tasklistsGridView_RowUpdating(object sender, GridViewUpdateEventArgs e) { try { TextBox txtName = (TextBox)tasklistsGridView.Rows[e.RowIndex].FindControl("txtName"); TextBox txtDescription = (TextBox)tasklistsGridView.Rows[e.RowIndex].FindControl("txtDescription"); TextBox txtPrerequisites = (TextBox)tasklistsGridView.Rows[e.RowIndex].FindControl("txtPrerequisites"); DropDownList ddlWorkgroup = (DropDownList)tasklistsGridView.FooterRow.FindControl("DropDownList1"); TextBox txtTag = (TextBox)tasklistsGridView.Rows[e.RowIndex].FindControl("txtTag"); command.Connection = connection; command.CommandText = "update tasklist set name ='" + txtName.Text + "',description ='" + txtDescription.Text + "',prerequisites ='" + txtPrerequisites.Text + "',workgroup ='" + ddlWorkgroup.SelectedItem.ToString() + "',tag ='" + txtTag.Text + "' WHERE Id='" + tasklistsGridView.DataKeys[e.RowIndex].Values[0].ToString() + "'"; connection.Open(); command.ExecuteNonQuery(); tasklistsGridView.EditIndex = -1; showTasklists(); connection.Close(); } catch (Exception x) { Response.Write("Exception: " + x.Message); } } protected void tasklistsGridView_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e) { tasklistsGridView.EditIndex = -1; showTasklists(); } protected void tasklistsGridView_RowCommand(object sender, GridViewCommandEventArgs e) { try { if (e.CommandName.Equals("AddNew")) { TextBox txtName = (TextBox)tasklistsGridView.FooterRow.FindControl("txtName"); TextBox txtDescription = (TextBox)tasklistsGridView.FooterRow.FindControl("txtDescription"); TextBox txtPrerequisites = (TextBox)tasklistsGridView.FooterRow.FindControl("txtPrerequisites"); DropDownList ddlWorkgroup = (DropDownList)tasklistsGridView.FooterRow.FindControl("DropDownList1"); TextBox txtTag = (TextBox)tasklistsGridView.FooterRow.FindControl("txtTag"); command.Connection = connection; command.CommandText = "insert into tasklist(name, description,prerequisites,workgroup,tag) Values('" + txtName.Text + "', '" + txtDescription.Text + "', '" + txtPrerequisites.Text + "', '" + ddlWorkgroup.SelectedItem.ToString() + "', '" + txtTag.Text + "')"; connection.Open(); command.ExecuteNonQuery(); showTasklists(); connection.Close(); } } catch (Exception x) { Response.Write("Exception: " + x.Message); } } protected void tasklistsGridView_SelectedIndexChanged(object sender, EventArgs e) { ViewState["tasklistid"] = tasklistsGridView.SelectedRow.Cells[0].Text; try { //2. Open Connection connection.Open(); //3. Create and Execute Command string query = "select Id, objective from objectives where tasklistId='" + Convert.ToInt32(ViewState["tasklistid"]) + "';"; SqlCommand command = new SqlCommand(); command.Connection = connection; command.CommandText = query; SqlDataReader reader = command.ExecuteReader(); DataTable Table = new DataTable(); Table.Load(reader); objectivesGridView.DataSource = Table; objectivesGridView.DataBind(); //4. Close connection connection.Close(); } catch (Exception x) { Response.Write("exception: " + x.Message); } } private void showObjectives() { try { command.Connection = connection; command.CommandText = "select * from objectives"; adapter = new SqlDataAdapter(command); adapter.Fill(table); objectivesGridView.DataSource = table; objectivesGridView.DataBind(); } catch (Exception x) { Response.Write("showObjectivesException: " + x.Message); } } protected void objectivesGridView_PageIndexChanging(object sender, GridViewPageEventArgs e) { objectivesGridView.PageIndex = e.NewPageIndex; showObjectives(); } protected void objectivesGridView_RowDeleting(object sender, GridViewDeleteEventArgs e) { try { command.Connection = connection; command.CommandText = "delete from objectives where Id='" + objectivesGridView.DataKeys[e.RowIndex].Values[0].ToString() + "'"; connection.Open(); command.ExecuteNonQuery(); connection.Close(); showObjectives(); } catch (Exception x) { Response.Write("objectivesGridView_RowDeletingException: " + x.Message); } } protected void objectivesGridView_RowEditing(object sender, GridViewEditEventArgs e) { objectivesGridView.EditIndex = e.NewEditIndex; showObjectives(); } protected void objectivesGridView_RowUpdating(object sender, GridViewUpdateEventArgs e) { try { TextBox txtObjective = (TextBox)objectivesGridView.Rows[e.RowIndex].FindControl("txtObjective"); DropDownList ddlObjectives = (DropDownList)objectivesGridView.FooterRow.FindControl("DropDownList2"); command.Connection = connection; command.CommandText = "update objectives set objective ='" + txtObjective.Text + "',tasklistId ='" + ddlObjectives.SelectedItem + "' WHERE Id='" + objectivesGridView.DataKeys[e.RowIndex].Values[0].ToString() + "'"; connection.Open(); command.ExecuteNonQuery(); objectivesGridView.EditIndex = -1; showObjectives(); connection.Close(); } catch (Exception x) { Response.Write("objectivesGridView_RowUpdatingException: " + x.Message); } } protected void objectivesGridView_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e) { objectivesGridView.EditIndex = -1; showObjectives(); } protected void objectivesGridView_RowCommand(object sender, GridViewCommandEventArgs e) { try { if (e.CommandName.Equals("AddNew")) { TextBox txtObjective = (TextBox)objectivesGridView.FooterRow.FindControl("txtObjective"); DropDownList ddlObjective = (DropDownList)objectivesGridView.FooterRow.FindControl("DropDownList2"); command.Connection = connection; command.CommandText = "insert into objectives(objective,tasklistId) Values('" + txtObjective.Text + "', '" + ddlObjective.SelectedItem + "')"; connection.Open(); command.ExecuteNonQuery(); showObjectives(); connection.Close(); } } catch (Exception x) { Response.Write("objectivesGridView_RowCommandException: " + x.Message); } } }

Here's the output snap (you might want to look at that red arrow on the top)



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3