Click here to Skip to main content
15,885,366 members
Home / Discussions / ASP.NET
   

ASP.NET

 
Questionadding validator callout extender programatically Pin
je198024-Jan-10 6:02
je198024-Jan-10 6:02 
QuestionDisplaying totals in rows Pin
AndyASPVB24-Jan-10 5:04
AndyASPVB24-Jan-10 5:04 
QuestionHow to open document in asp.net? Pin
JC.KaNNaN24-Jan-10 2:09
JC.KaNNaN24-Jan-10 2:09 
AnswerRe: How to open document in asp.net? Pin
Not Active24-Jan-10 2:28
mentorNot Active24-Jan-10 2:28 
GeneralRe: How to open document in asp.net? Pin
JC.KaNNaN24-Jan-10 23:18
JC.KaNNaN24-Jan-10 23:18 
GeneralRe: How to open document in asp.net? Pin
Not Active25-Jan-10 1:13
mentorNot Active25-Jan-10 1:13 
QuestionVisual Studio Web Developer 2008 Pin
Roy Shoa24-Jan-10 1:11
Roy Shoa24-Jan-10 1:11 
QuestionProblem showing the correct value in a gridview Pin
AndyASPVB24-Jan-10 0:59
AndyASPVB24-Jan-10 0:59 
In my gridview, I want to count the number of times each value (based of course on a field in my gridview) occurs. For example, if I have a field called Dept, in my result there is the following:

Dept A

Dept A

Dept A

Dept B

Dept B

Dept C

What I am trying to do is to show that for each Dept A, the count is 3, and for Dept B, the count is 2 and for Dept C the count is 1. When I have my count, I want to save them into my hidden field, which I am going to use else where in my code.

Here is my code:-

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)



{



Table tbl = e.Row.Parent as Table;



TableCell cell = new TableCell();



CheckBox chk = new CheckBox();



Label lbl2 = new Label();



HiddenField rowValue = new HiddenField();



if (e.Row.RowType == DataControlRowType.Header)



{



e.Row.Visible = false;



}



else



{



if (e.Row.RowType == DataControlRowType.DataRow)



{



Label lbl = (Label)e.Row.FindControl("lblValue");



string str1 = ((Label)(lbl)).Text;



string prevStr= (string)Session["previousStr"];



if (prevStr== str1)



{



counter = RememberDeptCount(str1)



}



else



{



prevStr= sr1 ;



Session["previousStr"] = prevStr;



counter = RememberDeptCount(prevStr)







if (tbl != null)



{



GridViewRow row = new GridViewRow(-1, -1, DataControlRowType.DataRow, DataControlRowState.Normal);







rowValue.ID = "hdnNumRows";



rowValue.Value = counter;



lbl2.Text = Convert.ToString(counter);



cell.ColumnSpan = this.GridView1.Columns.Count;



cell.Width = Unit.Percentage(100);



cell.BackColor = System.Drawing.Color.Aqua;



HtmlGenericControl span = new HtmlGenericControl("span");



span.InnerHtml = prevStr;



cell.Controls.Add(span);



cell.Controls.Add(chk);



cell.Controls.Add(lbl2);



cell.Controls.Add(rowValue);



row.Cells.Add(cell);



tbl.Rows.AddAt(tbl.Rows.Count - 1, row);











}



}



















}







}







}


public int RememberDeptCount(string dept_name)

{

if (hash_dept.ContainsKey(dept_name))

{

int current_count = Convert.ToInt32(hash_dept[dept_name]);

hash_dept.Remove(dept_name);

current_count+=1

hash_dept.Add(dept_name, current_count);


return current_count;

}

else

{

hash_dept.Add(dept_name, 1);

current_count = 1;

return current_count

}

}


When I run the code in debug mode, and look at my counts being returned for each dept I am seeing the correct results. Unfortunately, when it comes to be shown as labels in each of the groups, I am not seeing the correct results. For example, I am currently seeing 1 for each group, not 3, 2, 1.

Can anyone please help me, I am really stuck?
AnswerRe: Problem showing the correct value in a gridview Pin
Not Active24-Jan-10 2:33
mentorNot Active24-Jan-10 2:33 
QuestionFormsAuthentication.SetAuthCookie not working??? or is my logic wrong? [modified] Pin
wilsonmanmcp24-Jan-10 0:19
wilsonmanmcp24-Jan-10 0:19 
AnswerRe: FormsAuthentication.SetAuthCookie not working??? or is my logic wrong? Pin
Not Active24-Jan-10 2:35
mentorNot Active24-Jan-10 2:35 
AnswerRe: FormsAuthentication.SetAuthCookie not working??? or is my logic wrong? Pin
meeram39524-Jan-10 6:01
meeram39524-Jan-10 6:01 
AnswerRe: FormsAuthentication.SetAuthCookie not working??? or is my logic wrong? Pin
wilsonmanmcp24-Jan-10 12:07
wilsonmanmcp24-Jan-10 12:07 
AnswerRe: FormsAuthentication.SetAuthCookie not working??? or is my logic wrong? Pin
wilsonmanmcp25-Jan-10 0:32
wilsonmanmcp25-Jan-10 0:32 
QuestionASP.NET Cyrilic problem in DB Pin
hed_kandi23-Jan-10 22:29
hed_kandi23-Jan-10 22:29 
AnswerRe: ASP.NET Cyrilic problem in DB Pin
Not Active24-Jan-10 2:31
mentorNot Active24-Jan-10 2:31 
QuestionEncrypting The string Pin
RajpootRohan23-Jan-10 21:26
professionalRajpootRohan23-Jan-10 21:26 
AnswerRe: Encrypting The string [modified] Pin
Garth J Lancaster23-Jan-10 21:51
professionalGarth J Lancaster23-Jan-10 21:51 
Questionmodal popup extender Pin
Hemant Thaker23-Jan-10 7:29
Hemant Thaker23-Jan-10 7:29 
AnswerRe: modal popup extender Pin
Not Active23-Jan-10 8:18
mentorNot Active23-Jan-10 8:18 
GeneralRe: modal popup extender Pin
Hemant Thaker23-Jan-10 9:17
Hemant Thaker23-Jan-10 9:17 
QuestionHow to perform this requirement Pin
Nath23-Jan-10 5:50
Nath23-Jan-10 5:50 
AnswerRe: How to perform this requirement Pin
thatraja23-Jan-10 7:05
professionalthatraja23-Jan-10 7:05 
GeneralRe: How to perform this requirement Pin
Not Active23-Jan-10 8:12
mentorNot Active23-Jan-10 8:12 
GeneralRe: How to perform this requirement Pin
thatraja23-Jan-10 9:14
professionalthatraja23-Jan-10 9:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.