locked
sqldatasource - access data during the databinding event RRS feed

  • Question

  • User887127010 posted

    I have a sqldatasource bound to a control on an asp.net web page.

    What I would like to do is read the data as it is being bound to the control.  There is a specific field that I want to 'intercept' and change before it is bound to the control.

    I am using VS 2010 with .net 3.5.  My back-end database is sql server 2008.

    I'm not sure which event to use or what properties to access for this.

    A code sample would be helpful.

    Thank you in advance. 

    Thursday, August 18, 2011 2:20 PM

Answers

All replies

  • User-821857111 posted

    It depends on the type of control you are binding to, but you can do it in the itemdatabound event or rowdatabound event. Here's an example showing the Repeater's ItemDataBound event being used to intercept a value to alter it: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.repeater.itemdatabound.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, August 18, 2011 2:33 PM
  • User887127010 posted

    Hi Mike,

    Thanks for the very timely response.  I was able to find another event 'appointment_databound' that gave me what I needed.  However, your timely post helped me to know that the data could be manipulated during the 'databound' event.

    One thing that has been confusing in researching this is that 'databound' appears to be past-tense.  Meaning the data has already been written to the control.  However, I was still able to manipulate the data that way without the user 'seeing' the data in the control before it was changed.

    So, what is the difference between the databinding event and the databound event?

    Thanks,

    mlunow

    Thursday, August 18, 2011 3:25 PM
  • User-821857111 posted

    Data being bound to a row just means that the data values have been associated with the controls (labels, cells etc) that form the row. At that point, it's still just an idea. Nothing has been committed to HTML or dispatched to the client.

    Thursday, August 18, 2011 3:36 PM