4 Replies - 3620 Views - Last Post: 15 January 2009 - 08:32 AM Rate Topic: -----

#1 didgy58  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 246
  • Joined: 23-October 07

grid view and label

Posted 14 January 2009 - 04:22 AM

hi all i have a problem im trying to fix, my god this would be so much easier to do in php but i just cant seem to get it to work in asp.

baiscally i have a grid view on my page, which is pulling information from a access database, at the moment this is all working great i have styled it how i need it to look etc, now the client has come back saying they have added a field to the db for sale date. and the would like some text above the grid saying.

"blah blah blah this is the sale date " and show the date that is in the db file, now ive created the text and tried a multiple different ways to get it to gather the information from the db, just not sure how to do it nothing is working this is the closest i have got but its just returning a space (at least it doesnt throw and error)


CarCatalogue.aspx.cs

  public void cargrid_RowDataBound(Object sender, GridViewRowEventArgs e)
	{
		saledate.Text = e.Row.Cells[3].Text.ToString();
	}




saledate is the label im trying to fill with the information, cargrid is the name of the grid and the field in the select statment that is being returned is SaleDate, im stumpted on this one for sure not sure where to go from here.

thanks

Dan

Is This A Good Question/Topic? 0
  • +

Replies To: grid view and label

#2 dklingman  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 33
  • View blog
  • Posts: 263
  • Joined: 23-December 08

Re: grid view and label

Posted 14 January 2009 - 05:48 AM

first i'm just trying to get a handle on what it is they want, but could there be multiple sales dates and if so how do you know which one you want to display. or are you filtering by the sales date and you want to display that?
Was This Post Helpful? 0
  • +
  • -

#3 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1526
  • View blog
  • Posts: 5,961
  • Joined: 21-March 08

Re: grid view and label

Posted 14 January 2009 - 07:09 AM

the "RowDataBound" event is fired when a row is added to the grid by it's datasource. You are taking a field and writing it to a label for every row in the grid. This will mean that the label will be displaying the last sales date in the grid because that is the last row that fires the event.
Was This Post Helpful? 0
  • +
  • -

#4 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: grid view and label

Posted 14 January 2009 - 12:10 PM

Besides the issue that dklingman and eclipsed4utoo have already mentioned. You need to check whether the RowDataBound event is firing because of a DataRow before trying to access the data. Otherwise you could be capturing the data in the Header/Footer row.

You can also check if the cell contains an HTML space to prevent it from overwriting any actual data. This will only be the case if that column does not contain any data. Remove the space from between the "&" and "nbsp;", I had to include it in order for you to see the HTML that is being checked against.
public void cargrid_RowDataBound(Object sender, GridViewRowEventArgs e)
{
   // Make sure this is a data row and not a header/footer row
   if (e.Row.RowType == DataControlRowType.DataRow)
   {
		//Check if this is an HTML space before getting the data
		if (!e.Row.Cells[3].Text.Equals("& nbsp"))
		   saledate.Text = e.Row.Cells[3].Text.ToString();
   }
}


Was This Post Helpful? 0
  • +
  • -

#5 didgy58  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 246
  • Joined: 23-October 07

Re: grid view and label

Posted 15 January 2009 - 08:32 AM

thanks for all the replies guys, the dates are the same they have an automated system that spits out the db file and it fills in the dates of the sale, and every date will be the same so i dont mind if it catches first or last or anywhere in between i will take a look at what you have down jayman and let you know

thanks

Dan
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1