0

我似乎无法让我的代码工作。这是一个用于填充 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>
4

1 回答 1

4

设置数据源后尝试

gvProjectList.DataBind();
于 2012-04-24T15:03:30.870 回答