Last post Dec 14, 2010 11:36 AM by drewsheneman
Dec 14, 2010 09:40 AM|drewsheneman|LINK
Sorry if this has been asked before but i couldnt find a specific answer to this question, i am relatively new to .net :)
i have a gridview that is displaying data from a sqldatasource in my page_load event. i need to loop through the records and update each value of a particular column BEFORE being set into the GridView.
i have tried converting to a data set and looping through updating the values, however it seems that one i initially run my query the values get set right into the GridView and i can't update them after that.
Do I need to add one of the GridView functions like Databound and do the loop in there? Any help would be appreciated. Thanks!
Dec 14, 2010 11:12 AM|PeteNet|LINK
i need to loop through the records and update each value of a particular column BEFORE being set into the GridView.
you don't need to convert etc. use the RowDataBound event, which is meant for such modifications. see the docs and example here:
that event will allow you to look into each row as it is being bound to data and do your modifications.
Dec 14, 2010 11:24 AM|drewsheneman|LINK
Thanks for the reply Peter.One question about the example:
Do I need to put that RowDataBound function at the top of my aspx page?
I would like to just add it to my cs file if possible. I am running my sql query in my page_load event. When I tried adding the function from the example to the cs file and simply referencing it in the GridView with the OnRowDataBound Binding it did not
Dec 14, 2010 11:26 AM|drewsheneman|LINK
actually its working. missed a small detail which prevented it the first time. thanks so much!
Dec 14, 2010 11:28 AM|PeteNet|LINK
if you're not sure, the best approach would be to let the the designer create it for you: take the GridView, take properties (F4), take the last tab (lightning bolt) - those are the events, double-click RowDataBound ...and it will create the event handler
in the cs file for you.
Dec 14, 2010 11:36 AM|drewsheneman|LINK
ahh i see. this would make life easier. thanks again