简体   繁体   English

如何使用vb.net中的pageload事件在gridview中显示记录?

[英]How to display record in gridview using pageload event in vb.net?

How to display record in gridview using pageload event in vb.net ? 如何使用vb.net中的pageload事件在gridview中显示记录?

i wanna use two SqlDatasource1 and sqldatasource 2 to display record in single gridview1 我想使用两个SqlDatasource1和sqldatasource 2在单个gridview1中显示记录

SqlDatasource1 will display all records from tabel where as SqlDatasource will be used to display particuar record search in table 1 but how to do this ? SqlDatasource1将显示表格中的所有记录,其中SqlDatasource将用于显示表1中的特定记录搜索,但是如何执行此操作?

I'm not sure why you want to display all records from a table besides the records that belong to a particaúlar filter on that table. 我不确定为什么要显示该表中除属于该表的特定筛选器的记录之外的所有记录。 How do you want do make clear what is the filtered and what the unfiltered part? 您要如何弄清楚什么是已过滤部分以及哪些未过滤部分?

You could use UNION ALL to combine two resultsets together. 您可以使用UNION ALL将两个结果集组合在一起。 You could also add a column that contains a boolean if it belongs to the filtered set. 您还可以添加一个包含布尔值的列(如果它属于过滤后的集合)。 On this way you would be able to add different CssClass es to the rows according to this column value from RowDataBound in Codebehind. 这样,您将能够根据Codebehind中RowDataBound的此列值向行添加不同的CssClass

For example: 例如:

SELECT Foo.*,0 AS IsFiltered FROM Foo
UNION ALL 
SELECT Foo.*,1 AS IsFiltered FROM Foo
where Name like 's%

You only need one SQL-Datasource on this way. 这样,您只需要一个SQL-Datasource。

To set a different CssClass for the filtered records: 要为过滤的记录设置不同的CssClass:

 Private Sub GridRowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
     If e.Row.RowType = DataControlRowType.DataRow Then
         Dim row As DataRowView = DirectCast(e.Row.DataItem, DataRowView)
         Dim isFiltered As Boolean = CType(row("IsFiltered"), Boolean)
         If isFiltered Then e.Row.CssClass = "FilteredRecords"
     End If
 End Sub

' '

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM