Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Record COunt

Author  Topic 

vnswathi
Starting Member

8 Posts

Posted - 2006-07-18 : 13:56:37
Hi all,

i appreaciate if someone could help me slove the problem i am having.

i am populating a datagrid with some values and there is also a drop down list as one of it's columns.

the ddl is pupolated by a dataset.

but the record count is always displaying as double the number of records , that is if there is one record it says 2, if 16 it displays 32 so on,


	protected void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{

if (e.Item.ItemType == ListItemType.Header)
{
_recordCount = 0;
_casesOverdue = 0;
}
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
_recordCount++;

try
{
DateTime nextRepDate = DateTime.Parse(e.Item.Cells[12].Text);
if (nextRepDate.CompareTo(DateTime.Today) < 0 && e.Item.Cells[15].Text.Trim() == "Open")
{
e.Item.Cells[12].ForeColor = Color.Red;
_casesOverdue++;
}

DateTime startDate = DateTime.Parse(e.Item.Cells[4].Text);
DateTime endDate = (e.Item.Cells[12].Text != " ") ? DateTime.Parse(e.Item.Cells[12].Text) : DateTime.Today;

TimeSpan dateDiff = endDate.Subtract(startDate);
int daysOpen = dateDiff.Days;

((Label) e.Item.Cells[13].FindControl("lblDaysOpen")).Text = daysOpen.ToString();

DataSet Offenselist = ScidData.DDLGetOffensesByCaseID(Convert.ToInt32(e.Item.Cells[0].Text));
/*string[] options = { "OptionA", "OptionB", "OptionC" };*/
DropDownList list = (DropDownList) e.Item.Cells[7].FindControl("ddlGridOffenseList");
list.DataTextField = "pc_Description";
list.DataSource = Offenselist;
list.DataBind();

}
catch (Exception ex) {}
}
if (e.Item.ItemType == ListItemType.Footer)
{
lblResultSummary.Text = String.Format("{0} record(s) found matching search criteria with {1} case(s) overdue.", _recordCount, _casesOverdue);

}
}


i need to display the exact count of the records,

i appreciate your help in advance.

vnswathi.

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2006-07-18 : 14:22:00
I believe that for each row, the DataGridItem Bound event is fired for both Item and AlternatingItem types, even though only one or the other is ever actually created or rendered. The doubling up of the totals would seem to correlate with this. So, I would just accumulate these variables when the ItemType is "Item" and see how that goes.

- Jeff
Go to Top of Page

vnswathi
Starting Member

8 Posts

Posted - 2006-07-19 : 10:32:08
Thank you for the reply, but that did'nt make any difference.

Thanks,
vnswathi.
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2006-07-19 : 12:05:52
I was going to follow the following steps myself to help you out, but I think it might be better for you if you do it:

create a new web project, with a single aspx page. add in a single DataGrid, bind it to some small sample data with like 4 rows, and then play around. See how it works, which events are fired when, when the best time to accumulate your variable (on databinding? or Item created? or some other time?), etc. You'll find that you suddenly know much more about the DataGrid then you ever thought.

Whenever I am working on a large application, and a certain feature isn't working, and I'm really not quite sure why, I always step back and try things in a small, very simple sandbox. It makes it very easy to test and learn and really get the hang of things. this applies to SQL as well, of course.

then, once you have it all figured out, you go back to your application and implement what you've learned.


- Jeff
Go to Top of Page
   

- Advertisement -