c# - 必须在 ListView 'ListView1' 上定义 ItemTemplate。有人帮我解决这个错误

标签 c# .net

 protected void Button1_Click(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(str);
        SqlCommand cmd = new SqlCommand("insert into empoffice(empname,department,designation,empstatus,reportingto,grade,emplevel,doj) values('" + TextBox1.Text + "','" + DropDownList1.SelectedItem.Text + "','" + DropDownList2.SelectedItem.Text + "','" + DropDownList3.SelectedItem.Text + "','" + DropDownList4.SelectedItem.Text + "','" + DropDownList5.SelectedItem.Text + "','" + DropDownList6.SelectedItem.Text + "','" + TextBox2.Text + "')", con);

        con.Open();
        cmd.ExecuteReader();

        con.Close();
        SqlDataAdapter da = new SqlDataAdapter("select *from empoffice",con);

        DataSet ds = new DataSet();

        da.Fill(ds);

        ListView1.DataSource = ds;

        ListView1.DataBind();

     }

最佳答案

您需要为 ListView 创建一个 ItemTemplate,以便它知道在加载数据时如何显示数据。

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listview.itemtemplate.aspx

http://highoncoding.com/Articles/396_Getting_Started_with_the_ListView_Control.aspx

How to bind a ListView with Directories and Files in C#

http://msdn.microsoft.com/en-us/library/bb398790%28v=vs.100%29.aspx#CreatingTemplatesForTheListViewControl

您应该在这些链接中的某处找到您的答案。对您遇到的错误进行简单的 Google 搜索会对您有所帮助。在发布问题之前,请尝试自己做一些研究。

关于c# - 必须在 ListView 'ListView1' 上定义 ItemTemplate。有人帮我解决这个错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19628945/

相关文章:

c# - 重复的控件 ID 导致异常

c# - 如何设置 Connection.Closed 事件以使其在 SignalR 中重新连接?

c# - 我应该有多少个 GC 线程?

c# - Task.Yield 是否真的在当前上下文中运行延续?

c# - picturebox 图像随机化 C#

c# - 回滚由 Fluent NHibernate 中的 PersistenceSpecifications 创建的记录

c# - 使用 Entity Framework 6 流式传输 varbinary(max) 数据

c# - 使用ParseExact解析DateTime,我缺少什么?

c# - 文本框填充

c# - 将 XML 反序列化为 Dictionary<string, string>