GridView
-
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.
-
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.
Hi, Please check wether you can write e.Row["Category"] = "P" instead of # = "P". I think this will help !
"A good programmer is someone who looks both ways before crossing a one-way street." -- Doug Linder
Anant Y. Kulkarni
-
Hi, Please check wether you can write e.Row["Category"] = "P" instead of # = "P". I think this will help !
"A good programmer is someone who looks both ways before crossing a one-way street." -- Doug Linder
Anant Y. Kulkarni
There was an error when I compiled. Error Cannot apply indexing with [] to an expression of type 'System.Web.UI.WebControls.GridViewRow' C:\WebSites\Attendance\Admin\frm_Report.aspx.cs 322 17 C:\WebSites\Attendance\
thanks in advance. Much appreciated.
-
There was an error when I compiled. Error Cannot apply indexing with [] to an expression of type 'System.Web.UI.WebControls.GridViewRow' C:\WebSites\Attendance\Admin\frm_Report.aspx.cs 322 17 C:\WebSites\Attendance\
thanks in advance. Much appreciated.
Hi, Sorry about that but i dont know about the GridView. You can use the cells collection of the row - r.Row.Cells(0) where the '0' is column number of your desired column. I am not sure about it but you can atleast try ! check this - http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.tablerow.cells.aspx[^]
"A good programmer is someone who looks both ways before crossing a one-way street." -- Doug Linder
Anant Y. Kulkarni
-
Hi, Sorry about that but i dont know about the GridView. You can use the cells collection of the row - r.Row.Cells(0) where the '0' is column number of your desired column. I am not sure about it but you can atleast try ! check this - http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.tablerow.cells.aspx[^]
"A good programmer is someone who looks both ways before crossing a one-way street." -- Doug Linder
Anant Y. Kulkarni
Thanks for the link, I have yet to understand. Anyone there who can help? :((
-
Thanks for the link, I have yet to understand. Anyone there who can help? :((
-
Hi Blur Member .... u may use ," e.Row.Cells[index].Text " to get the value on that Particular Cell ( index th position, zero indexing) of the current row. Hope It works..
Regards, Jay
There was an error. Error 1 Cannot implicitly convert type 'string' to 'bool' C:\WebSites\Attendance\Admin\frm_Report.aspx.cs 322 17 C:\WebSites\Attendance\
protected void GridView4_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { if (e.Row.Cells[3].Text = "P") { presentCount++; } } else if (e.Row.RowType == DataControlRowType.Footer) { e.Row.Cells[3].Text = presentCount.ToString(); }
thanks for your help so far Jay
-
There was an error. Error 1 Cannot implicitly convert type 'string' to 'bool' C:\WebSites\Attendance\Admin\frm_Report.aspx.cs 322 17 C:\WebSites\Attendance\
protected void GridView4_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { if (e.Row.Cells[3].Text = "P") { presentCount++; } } else if (e.Row.RowType == DataControlRowType.Footer) { e.Row.Cells[3].Text = presentCount.ToString(); }
thanks for your help so far Jay
-
Basically I have a dropdownlist which filter adminNo and then display each record at the gridview. So user can see how many P exists in column Category for each adminNo. the result display at the footer is 0. i hope it is not due to me filtering records by dropdownlist.
jay thanks
-
Basically I have a dropdownlist which filter adminNo and then display each record at the gridview. So user can see how many P exists in column Category for each adminNo. the result display at the footer is 0. i hope it is not due to me filtering records by dropdownlist.
jay thanks
-
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