Changing the Datatype of Datatable Column

Discussion in 'ASP .Net Datagrid Control' started by Kevin Humphreys, Jan 5, 2006.

  1. Hi,
    I need to change the Datatype of Datatable Column when the dataset populates
    the Datatable
    I would like to be able to do this either after the datatable is assigned to
    the dataset or
    before this happens.

    E.G. Convert datatype from Int to String

    Below I want to change the first column to string.

    myTable = ds.Tables("Table1")
    For Each dr1 As DataRow In myTable.Rows
    dr1(0) = "Hi"
    Next

    This will fail because dr(0) is set to int

    Thanks In Advance,
    Kevin.
    Kevin Humphreys, Jan 5, 2006
    #1
    1. Advertising

  2. Kevin,

    This sort of things is rather unusual. May by you want to set the string
    value in the datagrid cell rather than in the data source table? That would
    be a common thing.

    Eliyahu

    "Kevin Humphreys" <> wrote in message
    news:...
    > Hi,
    > I need to change the Datatype of Datatable Column when the dataset
    > populates the Datatable
    > I would like to be able to do this either after the datatable is assigned
    > to the dataset or
    > before this happens.
    >
    > E.G. Convert datatype from Int to String
    >
    > Below I want to change the first column to string.
    >
    > myTable = ds.Tables("Table1")
    > For Each dr1 As DataRow In myTable.Rows
    > dr1(0) = "Hi"
    > Next
    >
    > This will fail because dr(0) is set to int
    >
    > Thanks In Advance,
    > Kevin.
    >
    Eliyahu Goldin, Jan 5, 2006
    #2
    1. Advertising

  3. Eliyahu,
    That method would be good too.
    How can I do this in VB.NET? Im using an unbound datagrid and doing

    DataGrid1.DataSource = ds.Tables("Table1")
    DG_DataGrid1.DataBind()

    when the datatable is populated.
    Are you sayining change to a string value when the databind happens or
    before? if so then how?

    Thanks,
    Kevin.


    "Eliyahu Goldin" <> wrote in message
    news:%...
    > Kevin,
    >
    > This sort of things is rather unusual. May by you want to set the string
    > value in the datagrid cell rather than in the data source table? That
    > would be a common thing.
    >
    > Eliyahu
    >
    > "Kevin Humphreys" <> wrote in message
    > news:...
    >> Hi,
    >> I need to change the Datatype of Datatable Column when the dataset
    >> populates the Datatable
    >> I would like to be able to do this either after the datatable is assigned
    >> to the dataset or
    >> before this happens.
    >>
    >> E.G. Convert datatype from Int to String
    >>
    >> Below I want to change the first column to string.
    >>
    >> myTable = ds.Tables("Table1")
    >> For Each dr1 As DataRow In myTable.Rows
    >> dr1(0) = "Hi"
    >> Next
    >>
    >> This will fail because dr(0) is set to int
    >>
    >> Thanks In Advance,
    >> Kevin.
    >>

    >
    >
    Kevin Humphreys, Jan 5, 2006
    #3
  4. Kevin,

    You should use datagid's ItemDataBound event. The event fires for every item
    (row) after it gets bound. You get a reference to the item as an event
    handler call parameter. Filter out the header, footer etc items (ItemType
    propertu) and use Cells collection to get to the cell values. They are all
    strings. You can read and set them as required.

    Eliyahu

    "Kevin Humphreys" <> wrote in message
    news:...
    > Eliyahu,
    > That method would be good too.
    > How can I do this in VB.NET? Im using an unbound datagrid and doing
    >
    > DataGrid1.DataSource = ds.Tables("Table1")
    > DG_DataGrid1.DataBind()
    >
    > when the datatable is populated.
    > Are you sayining change to a string value when the databind happens or
    > before? if so then how?
    >
    > Thanks,
    > Kevin.
    >
    >
    > "Eliyahu Goldin" <> wrote in message
    > news:%...
    >> Kevin,
    >>
    >> This sort of things is rather unusual. May by you want to set the string
    >> value in the datagrid cell rather than in the data source table? That
    >> would be a common thing.
    >>
    >> Eliyahu
    >>
    >> "Kevin Humphreys" <> wrote in message
    >> news:...
    >>> Hi,
    >>> I need to change the Datatype of Datatable Column when the dataset
    >>> populates the Datatable
    >>> I would like to be able to do this either after the datatable is
    >>> assigned to the dataset or
    >>> before this happens.
    >>>
    >>> E.G. Convert datatype from Int to String
    >>>
    >>> Below I want to change the first column to string.
    >>>
    >>> myTable = ds.Tables("Table1")
    >>> For Each dr1 As DataRow In myTable.Rows
    >>> dr1(0) = "Hi"
    >>> Next
    >>>
    >>> This will fail because dr(0) is set to int
    >>>
    >>> Thanks In Advance,
    >>> Kevin.
    >>>

    >>
    >>

    >
    >
    Eliyahu Goldin, Jan 5, 2006
    #4
    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. jg
    Replies:
    1
    Views:
    712
    =?Utf-8?B?U2hhaWxlc2ggSmFubnU=?=
    Aug 17, 2004
  2. wapsiii
    Replies:
    2
    Views:
    8,267
    Shimon Sim
    Feb 5, 2006
  3. keithb
    Replies:
    2
    Views:
    22,660
    renato.elvis
    Jul 29, 2010
  4. keithb
    Replies:
    1
    Views:
    4,702
  5. Jeff
    Replies:
    2
    Views:
    1,123
    Steve C. Orr [MCSD, MVP, CSM, ASP Insider]
    Apr 16, 2007
Loading...

Share This Page