我似乎无法让我的代码工作。这是一个用于填充 asp.net GridView 控件的简单应用程序。网格控件没有被填充,我没有收到错误消息。
我在这里想念什么?
代码隐藏
public void DisconnectedDataform()
{
try
{
Initdata();
gvProjectList.DataSource = dsProjectList;
gvProjectList.DataMember = tableName;
}
catch (Exception e)
{
Response.Write(e.ToString());
}
finally
{ }
}
public void Initdata()
{
try
{
string conn = ConfigurationManager.ConnectionStrings["dbProjectManager"].ConnectionString;
dsProjectList = new DataSet();
daProjectList = new SqlDataAdapter("select PersonID, FirstName, LastName from Person", conn);
SqlCommandBuilder cmdBldr = new SqlCommandBuilder(daProjectList);
daProjectList.Fill(dsProjectList, "ProjectList");
}
catch (Exception e)
{
Response.Write(e.ToString());
}
finally
{ }
}
ASP 代码:
<asp:GridView ID="gvProjectList" runat="server" AutoGenerateColumns="true" DataKeyNames="PersonID">
<Columns>
<asp:BoundField DataField="PersonID" HeaderText="PersonID" InsertVisible="False" ReadOnly="True" SortExpression="PersonID" />
<asp:BoundField DataField="FirstName" HeaderText="FirstName" SortExpression="FirstName" />
<asp:BoundField DataField="LastName" HeaderText="LastName" SortExpression="LastName" />
</Columns>
</asp:GridView>