必须在列表视图“列表视图 1”上定义项模板.任何人都可以帮助我解决此错误
本文关键字:列表 视图 都可以 任何人 帮助 解决 错误 定义 列表视图 | 更新日期: 2023-09-27 18:37:02
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
如何在 C# 中将列表视图与目录和文件绑定
http://msdn.microsoft.com/en-us/library/bb398790%28v=vs.100%29.aspx#CreatingTemplatesForTheListViewControl
在这些链接中的某个地方,您应该找到答案。对你得到的错误进行简单的谷歌搜索会帮助你。在发布问题之前,请尝试自己做一些研究。
您需要
将<ItemTemplate></ItemTemplate>
对标记放在ListView中,因此如下所示。我也包括了一个布局模板,只是为了它。
<asp:ListView ID="ListView1" runat="server">
<LayoutTemplate>
<table runat="server" id="table1" >
<tr runat="server" id="itemPlaceholder" ></tr>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr runat="server">
<td runat="server">
<%-- Data-bound content. --%>
<asp:Label ID="NameLabel" runat="server" Text='<%#Eval("Name") %>' />
</td>
</tr>
</ItemTemplate>
</asp:ListView>