Dataset

A

anonymous

When grdSearch.ItemDataBound occurs is it possible to know
dataset name I am working with?
 
E

Elton Wang

Use following code

DataGrid dg = (DataGrid)sender;
DataSet ds = (DataSet)dg.DataSource;
string dsName = ds.DataSetName;

You can easily get the DataSet name.

Elton Wang
(e-mail address removed)
 
A

anonymous

I try to rewrite to the Vb.net however the follwing 2 line
compiler doesn't recognoze:
dg = DataGrid.sender
ds= (DataSet)dg.DataSource
Here my code:
Dim dg As DataGrid
dg = DataGrid.sender
Dim ds As DataSet
ds= (DataSet)dg.DataSource
Dim dsName As String = ds.DataSetName
 
A

anonymous

Here is my full code:
Private Sub grdSearch_ItemDataBound(ByVal sender As
System.Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles
grdSearch.ItemDataBound
Dim name as string= sender.dataSource.DataSetName()
End Sub
Private Sub btnSearch_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
btnSearch.Click
With grdSearch
.SelectedIndex = -1
If Not GetData() Is Nothing Then
.DataSource = GetData()
.DataBind()

Else
.DataSource = GetData2()
.DataBind()


End If


End With


End Sub
 
E

Elton Wang

You have to cast sender (Obect Type) to DataGrid first,
like this:
Dim dg As DataGrid = CType(sender, DataGrid)

DataGrid.DataSource is also Object, you also need to cast
it to specified type, i.e. DataSet, DataTable, or
DataView, depending on the object type you bind to
DataGrid.

Elton Wang
 
A

anonymous

Here what I cast. Please correct me where I am wrong:
Dim dg As DataGrid = CType(sender, DataGrid)
Dim name As String = Ctype
(dg.DataSource,DataSet).DataSetName
As a result I am getting this: "NewDataSet"
instead of real dataset name.
Thanks
 
E

Elton Wang

The syntax is correct. The question is how do you assign
DataSetName in the GetData() and GetData2(). It seems you
don't assign DataSetName. If you don't assign DataSetName,
it gives default value, NewDataSet.

Elton Wang
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top