Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi friends


How to View my Generic List to a label in a webpage when a button is fired from another page .. or else in gridview


C++
        string itemName;
        int count = GridView1.Rows.Count;
        List<int32> id = new List<int32>();

        foreach (GridViewRow item in GridView1.Rows)
        {
           
            itemName = item.Cells[1].Text;
            id.Add(method to get id from database);


        }
foreach (Int32 txt in id)
        {


            globalvariable+= txt.ToString();
        }


please provide some code
Posted
Updated 17-Dec-12 22:49pm
v5
Comments
Jibesh 18-Dec-12 1:11am    
how you want to display ? a list is nothing but the collection of objects just iterate through the items and add formatted text to label or gridview or any other control as you like.
sreeCoderMan 18-Dec-12 1:16am    
i want to display a label in gridview
Jibesh 18-Dec-12 1:25am    
Please elaborate your question. Also hope you know about what is Generic List? how to iterate the list?

are you using any database?
You may use the 'Improve Question' link at the right bottom of your question of you want to edit your question in future.
sreeCoderMan 18-Dec-12 1:29am    
i have updated the question i this this may help you to view my list to another page from a button click event to display it in label inside gridview
Jibesh 18-Dec-12 3:07am    
Check my solution and reply is that your trying or not

In your c# i'm not sure how to code it,
but its not difficult.

So if i provide it in VB maybe you will understand hopefully?

C#
YOUR CODE C#

for each (GridViewRow item in GridView1.Rows)
 {

 itemName = item.Cells[1].Text;
 id.Add(method to get id from database);
 }



VB
In VB 

For each (GridViewRow item in GridView1.Rows)
  itemName = item.Cells[1].Text
  id.Add(method to get id from database)
  'comment add the data ietem to a string
  strData = strData & itemName & vbcrlf 
  'Comment vbcrlf is same as chr(13) or enter or newline
Next
SomeLabel.Text = strData
 
Share this answer
 
C#
string labelTextData = string.Empty;
int count = GridView1.Rows.Count;
List id = new List();

foreach (GridViewRow item in GridView1.Rows)
{
 labelTextData += item.Cells[1].Text + ",";
 labelTextData += (method to get Id from Database);
}
label.Text = labelTextData;


is that what you want? for this you dont need the list.
 
Share this answer
 
v3
Comments
sreeCoderMan 18-Dec-12 4:16am    
here only one Text data will display right... i need all rows data lets say like this a,b,c for 3 rows
Jibesh 18-Dec-12 4:19am    
it will add the result of all the rows give a try and see the result
sreeCoderMan 18-Dec-12 4:42am    
yeah it will add the result... but displays the last added value only
Jibesh 18-Dec-12 4:45am    
"it will add the result" is that what you want??

"displays the last added value only"
did you check the += operator . double check your code. or please update your question with latest code.

Use Improve Question link at the right bottom of your question to modify the question
sreeCoderMan 18-Dec-12 4:47am    
i need a comma in between this how to do that

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900