2011-12-15 2 views
1

データベースからDataSetを取得したとします。その後、私はASP.Net C#のListView/GridViewに表示したい。これどうやってするの?私のためのサンプル?ListView/GridViewにDataSetを表示する方法

+2

を試してみてください。 –

+0

ちょうどあなたの質問 –

+0

私は思う質問をするには間違った場所Googleの検索であなたの質問を貼り付け、Google検索をクリックしてください..あなたは十分な答えを見つけるだろう –

答えて

4

は、単純なこの種のことは、膨大な数の例がオンラインにある解決策をグーグルによって解決されなければならない。この

if(datasetObject.tables.count > 0) 
    { 
    GridView.DataSource = datasetObject; 
    GridView.DataBind(); 

    } 
else 
{ 
    lable.Text = "No Record Found"; 
} 
1

これを行うには、GridViewのDataBind()メソッドを使用します。 like

GridView.DataSource = ds; 
GridView.DataBind(); 
1

データセットをグリッドのDataSourceプロパティ値として設定し、DataBind()メソッドを呼び出します。 MSDN

AuthorsGridViewを想定し

http://msdn.microsoft.com/en-us/library/fkx0cy6d.aspx

void Page_Load(Object sender, EventArgs e) 
{ 
// This example uses Microsoft SQL Server and connects 
// to the Northwind sample database. The data source needs 
// to be bound to the GridView control only when the 
// page is first loaded. Thereafter, the values are 
// stored in view state.      
if(!IsPostBack) 
{ 

    // Declare the query string. 
    String queryString = 
    "Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]"; 

    // Run the query and bind the resulting DataSet 
    // to the GridView control. 
    DataSet ds = GetData(queryString); 
    if (ds.Tables.Count > 0) 
    { 
    AuthorsGridView.DataSource = ds; 
    AuthorsGridView.DataBind(); 
    } 
    else 
    { 
    Message.Text = "Unable to connect to the database."; 
    } 

} 
} 

から

は、あなたのGridViewコントロールのIDとGetDataメソッドは、データとデータセットを返します。

関連する問題