怎么解决:未能找到objectdatasource的typename属性
后台两个方法
protected void search(object sender, EventArgs e)
{
GridView1.DataSourceID = this.ObjectDataSource1.ID;
GridView1.DataBind();
}
public DataTable searchcontact()
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = " Data Source=DELL-PC;Initial Catalog=yangweiQ;Integrated Security=True";
conn.Open();
string str="select* from admin";
SqlDataAdapter sda=new SqlDataAdapter();
SqlCommand comm=new SqlCommand(str,conn);
DataTable da=new DataTable();
sda.Fill(da);
conn.Close();
return da;
}
前台
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="search" />
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" TypeName="WebForm1" SelectMethod="searchcontact">
</asp:ObjectDataSource>
------解决方案--------------------this.ObjectDataSource1.ID;
你想出来的?
如果你要用 ObjectDataSource 数据源,你在GridView1直接选择数据源就可以了。