Results 1 to 9 of 9

Thread: Change data in gridview when retrieved with SQLDatasource?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Oct 2000
    Posts
    1,463

    Question Change data in gridview when retrieved with SQLDatasource?

    Hi Everyone,

    When the data is retrieved through a stored procedure using the SQLDatasource control that is binded to a gridview control, I want to change some data that is in some of the columns. Can i do this in one of the events either in the gridview or data control?

    I know you can do some formatting on the aspx page side such as dates, etc. but was wondering if I can do it on the vb code side?

    Thanks!

    Warren

  2. #2
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Change data in gridview when retrieved with SQLDatasource?

    Hey,

    Can you be more specific about what you are trying to do?

    Both the GridView and the SqlDataSource have events that can you used to manipulate the data before it is shown on the screen. For instance, the RowDataBound event of the GridView.

    Gary

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Oct 2000
    Posts
    1,463

    Re: Change data in gridview when retrieved with SQLDatasource?

    Thanks, that's what I'm trying to do is manipulate the data coming in before it is written to a cell in the gridview. Probably doing it at the gridview is the best place. The date coming is is in a wierd format of yyyy-mm-dd and I need to convert it to mm/dd/yyyy. I don't know if the date format on the aspx page will read this right and change it. So I was going to do it manually in the gridview event. Also, the table I am using has a specific date that is supposed to be null - not sure why they did this but if I see that date I want to replace it with a blank rather than display that data.

    I was trying to find an example of how to change a cell's data in the gridview event but could not find it.

    Thanks for the help!

    Warren

  4. #4
    Hyperactive Member dnanetwork's Avatar
    Join Date
    Oct 2007
    Location
    Mumbai
    Posts
    349

    Re: Change data in gridview when retrieved with SQLDatasource?

    RowDataBound Event.

    also you can change it in aspx page using

    <&#37;# DataBinder.Eval(Container.DataItem, "ProdDate", "{0:dd MMM yyyy}")%>

  5. #5
    Hyperactive Member dnanetwork's Avatar
    Join Date
    Oct 2007
    Location
    Mumbai
    Posts
    349

    Re: Change data in gridview when retrieved with SQLDatasource?

    RowDataBound Event.

    also you can change it in aspx page using

    <&#37;# DataBinder.Eval(Container.DataItem, "ProdDate", "{0:dd MMM yyyy}")%>

    http://peterkellner.net/2006/05/24/h...code-property/

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Oct 2000
    Posts
    1,463

    Re: Change data in gridview when retrieved with SQLDatasource?

    Thanks! How would I go about it to change it in the RowDataBound event? Wouild I do the following?

    Code:
    e.Row.Cells(0).Text = "123"
    Warren

  7. #7
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Change data in gridview when retrieved with SQLDatasource?

    Hey,

    Yip, that would be the better way to do it. You can find an example here:

    http://msdn.microsoft.com/en-us/libr...databound.aspx

    Gary

  8. #8
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Change data in gridview when retrieved with SQLDatasource?

    In the RowDataBound, you could first get the datarowview, get the date out, then format:

    vb Code:
    1. Dim thisRow As DataRowView = CType(e.Row.DataItem, DataRowView)
    2. Dim badDateTime As DateTime = DateTime.Parse(thisRow("datecolumn").ToString())
    3. e.Row.Cells(0).Text = badDateTime.ToString("MM/dd/yyyy")

  9. #9
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Change data in gridview when retrieved with SQLDatasource?

    DateTime.Parse or DateTime.TryParse....

    You decide.

    Gary

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width