Dataset

Discussion in 'ASP .Net Datagrid Control' started by anonymous, Jan 7, 2005.

  1. anonymous

    anonymous Guest

    When grdSearch.ItemDataBound occurs is it possible to know
    dataset name I am working with?
     
    anonymous, Jan 7, 2005
    #1
    1. Advertising

  2. anonymous

    Elton Wang Guest

    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


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

    know
    >dataset name I am working with?
    >.
    >
     
    Elton Wang, Jan 7, 2005
    #2
    1. Advertising

  3. anonymous

    anonymous Guest

    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
     
    anonymous, Jan 7, 2005
    #3
  4. anonymous

    anonymous Guest

    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
     
    anonymous, Jan 7, 2005
    #4
  5. anonymous

    Elton Wang Guest

    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
    >
    >.
    >
     
    Elton Wang, Jan 7, 2005
    #5
  6. anonymous

    anonymous Guest

    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
     
    anonymous, Jan 10, 2005
    #6
  7. anonymous

    Elton Wang Guest

    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
    >
    >.
    >
     
    Elton Wang, Jan 10, 2005
    #7
  8. anonymous

    anonymous Guest

    thanks. I was not assigning the dataset name.
     
    anonymous, Jan 11, 2005
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Nedu N
    Replies:
    1
    Views:
    1,839
    Chris Taylor
    Oct 31, 2003
  2. JimO

    DataSet and dataSet

    JimO, Mar 1, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    558
    Mary Chipman [MSFT]
    Mar 8, 2006
  3. Joseph D. DeJohn

    DataSet to DataSet

    Joseph D. DeJohn, Aug 4, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    429
  4. Nedu N
    Replies:
    2
    Views:
    2,209
  5. William Gower
    Replies:
    2
    Views:
    4,199
    Brian Baker [MVP]
    Jul 26, 2004
Loading...

Share This Page