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();
}
2 回答
You need to create a ItemTemplate for your ListView, so it knows how to display your data when it loads it in.
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#
Somewhere in these links you should find your answer. A simple Google search of the error you are getting will help you. Please try doing some research yourself before posting a question.
您需要将这<ItemTemplate></ItemTemplate>
对标签放在您的 ListView 中,因此请使用以下内容。我还包括了一个 LayoutTemplate 只是为了它。
<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>