Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > Dataset

Reply
Thread Tools

Dataset

 
 
anonymous
Guest
Posts: n/a
 
      01-07-2005
When grdSearch.ItemDataBound occurs is it possible to know
dataset name I am working with?
 
Reply With Quote
 
 
 
 
Elton Wang
Guest
Posts: n/a
 
      01-07-2005
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
http://www.velocityreviews.com/forums/(E-Mail Removed)

>-----Original Message-----
>When grdSearch.ItemDataBound occurs is it possible to

know
>dataset name I am working with?
>.
>

 
Reply With Quote
 
 
 
 
anonymous
Guest
Posts: n/a
 
      01-07-2005
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
 
Reply With Quote
 
anonymous
Guest
Posts: n/a
 
      01-07-2005
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

 
Reply With Quote
 
Elton Wang
Guest
Posts: n/a
 
      01-07-2005

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

>-----Original Message-----
>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
>
>.
>

 
Reply With Quote
 
anonymous
Guest
Posts: n/a
 
      01-10-2005
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

 
Reply With Quote
 
Elton Wang
Guest
Posts: n/a
 
      01-10-2005
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

>-----Original Message-----
>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
>
>.
>

 
Reply With Quote
 
anonymous
Guest
Posts: n/a
 
      01-11-2005
thanks. I was not assigning the dataset name.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DataSet and dataSet JimO ASP .Net 2 03-08-2006 02:39 PM
copying a datatable content from an untyped dataset into a table which is inside a typed dataset Nedu N ASP .Net 2 10-31-2003 01:05 PM
Ccopying a datatable content from an untyped dataset into a table which is inside a typed dataset Nedu N ASP .Net 1 10-31-2003 02:39 AM
DataSet to DataSet Joseph D. DeJohn ASP .Net 1 08-04-2003 03:25 AM



Advertisments