2009-09-17 132 views
1

GridView控件上的rows.count屬性僅告訴我屏幕上顯示的行數,而不是可用的總數。如何獲取我的分頁GridView控件中的行數?

下面的解決方案不起作用。我有一個SqlDataSource和一個GridView,都不能被轉換成數據集或數據表。

+0

**您的數據源的Count **屬性(可能是DataTable)。 – adatapost 2009-09-17 09:45:18

+0

在回發之後,我將哪些事件或方法放入? – NibblyPig 2009-09-17 09:48:00

+0

哪個是您正在參考的「解決方案」? – Marcel 2013-01-21 16:28:07

回答

1

的SqlDataSource的具有稱爲事件OnSelected可以設置到類似下面的方法 -

protected void OnSelectedData(object sender, SqlDataSourceStatusEventArgs e) 
{ 
    // Set the record count label 
    RecordCountLabel.Text = "Total Records: " + e.AffectedRows; 
} 

注意,e.AffectedRows包含選定行的總數。

3

我想你需要得到數據源的行數。

如果數據源是數據表然後

dt.Rows.Count 

會給行的總數,其中dt是DataTable對象。

如果它是一個數據集,那麼獲取相應的數據表,然後將行計數。

ds.Tables["tablename"].Rows.Count; // give the datatable name 

ds.Tables[tableIndex].Rows.Count; // give the datatable index 

其中,ds是該數據集的對象。