|
-
Mar 10th, 2010, 03:29 PM
#1
Thread Starter
Frenzied Member
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
-
Mar 11th, 2010, 03:24 AM
#2
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
-
Mar 11th, 2010, 08:48 AM
#3
Thread Starter
Frenzied Member
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
-
Mar 11th, 2010, 02:05 PM
#4
Hyperactive Member
Re: Change data in gridview when retrieved with SQLDatasource?
RowDataBound Event.
also you can change it in aspx page using
<%# DataBinder.Eval(Container.DataItem, "ProdDate", "{0:dd MMM yyyy}")%>
-
Mar 11th, 2010, 02:13 PM
#5
Hyperactive Member
Re: Change data in gridview when retrieved with SQLDatasource?
RowDataBound Event.
also you can change it in aspx page using
<%# DataBinder.Eval(Container.DataItem, "ProdDate", "{0:dd MMM yyyy}")%>
http://peterkellner.net/2006/05/24/h...code-property/
-
Mar 11th, 2010, 02:15 PM
#6
Thread Starter
Frenzied Member
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
-
Mar 11th, 2010, 02:27 PM
#7
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
-
Mar 13th, 2010, 03:46 AM
#8
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:
Dim thisRow As DataRowView = CType(e.Row.DataItem, DataRowView) Dim badDateTime As DateTime = DateTime.Parse(thisRow("datecolumn").ToString()) e.Row.Cells(0).Text = badDateTime.ToString("MM/dd/yyyy")
-
Mar 13th, 2010, 04:36 AM
#9
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|