GridView
-
Whether it works or not ? You need to declare the variable 'presentCount' as a 'static' variable inorder to retain its value during the Gridview is population.
Regards, Jay
I hope my declaration is correct. public static int presentCount = 0; But yet the footer still show 0. :((
JAY THANKS
-
I am using c#. i have a gridview and one of the column is Category. I have used the objectdatasource to bind the data. I want to count the number of "P" exist in that column and display it at the footer of the gridview.
int presentCount = 0; protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { //if ( # = "P") presentCount++; } else if (e.Row.RowType == DataControlRowType.Footer) { e.Row.Cells[3].Text = presentCount.ToString(); } }
What whould be the correct way. What syntax should be replaced by #? Is there any sample I can follow?thanks in advance. Much appreciated.
Try out this !.............
int presentCount = 0;
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
YourType obj = e.Row.DataItem as YourType;
if ( obj.Property = "P")
presentCount++;
}
else if (e.Row.RowType == DataControlRowType.Footer)
{
e.Row.Cells[3].Text = presentCount.ToString();
}
} -
Try out this !.............
int presentCount = 0;
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
YourType obj = e.Row.DataItem as YourType;
if ( obj.Property = "P")
presentCount++;
}
else if (e.Row.RowType == DataControlRowType.Footer)
{
e.Row.Cells[3].Text = presentCount.ToString();
}
}i am having doubt the data type need to be used. What is the best solution? My Category value is a char data type from the database. :^)
thanks in advance. Much appreciated.
-
I hope my declaration is correct. public static int presentCount = 0; But yet the footer still show 0. :((
JAY THANKS
Believe me it works fine... I think , ur data "P" came from database. It may have some white spaces. use Trim() method to remove that, then the string comparision works properly. Hope it help u... static int count = 0; protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { string tmp=(e.Row.Cells[3].Text).Trim(); if (tmp == "P") { count += 1; } } if (e.Row.RowType == DataControlRowType.Footer) { e.Row.Cells[3].Text = count.ToString(); } } -- modified at 6:27 Thursday 17th August, 2006
Regards, Jay
-
Believe me it works fine... I think , ur data "P" came from database. It may have some white spaces. use Trim() method to remove that, then the string comparision works properly. Hope it help u... static int count = 0; protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { string tmp=(e.Row.Cells[3].Text).Trim(); if (tmp == "P") { count += 1; } } if (e.Row.RowType == DataControlRowType.Footer) { e.Row.Cells[3].Text = count.ToString(); } } -- modified at 6:27 Thursday 17th August, 2006
Regards, Jay
:-D Yes it came from a database. What an awesome solution! Poem for Jay I 1 2 SAY to the person JAY I am so GAY (happy) to finally get the ans... Hip Hip HOORAY!
another brilliant ans from the pro.
-
:-D Yes it came from a database. What an awesome solution! Poem for Jay I 1 2 SAY to the person JAY I am so GAY (happy) to finally get the ans... Hip Hip HOORAY!
another brilliant ans from the pro.
-
:-D Yes it came from a database. What an awesome solution! Poem for Jay I 1 2 SAY to the person JAY I am so GAY (happy) to finally get the ans... Hip Hip HOORAY!
another brilliant ans from the pro.
-
When the user click from the ListBox to view each adminNo, the Show Footer manage to calculate the number of P exist in the gridview. But when the user click another adminNo, the Show Footer number was accumulated with the previous Show Footer. Example: when the user click for the first time Show Footer: 18 second output when user click for the second time, the number of P exist in the gridview is suppose to be 10, but show 38 instead Show Footer: 38
thanks in advance. Much appreciated.
-
When the user click from the ListBox to view each adminNo, the Show Footer manage to calculate the number of P exist in the gridview. But when the user click another adminNo, the Show Footer number was accumulated with the previous Show Footer. Example: when the user click for the first time Show Footer: 18 second output when user click for the second time, the number of P exist in the gridview is suppose to be 10, but show 38 instead Show Footer: 38
thanks in advance. Much appreciated.
-
i think the static variable 'showCount' keeps its old value. So you may declare it properly , in such a way that when u click a item from ur ListBox , the variable is set to zero. hope it helps u
Regards, Jay
X| My flu and cough is really bad, i can't even think. :laugh:
protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e) { count = 0; }
I did this to save my trouble. Hope no more problem.thanks again superjay
-
X| My flu and cough is really bad, i can't even think. :laugh:
protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e) { count = 0; }
I did this to save my trouble. Hope no more problem.thanks again superjay