Click here to Skip to main content
15,887,267 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am fetching data from database in gridview and trying to take value in string variable or label, but the following code is not working:

VB
For t As Integer = 0 To GridView1.Rows.Count
           lblsubheader.Text = (GridView1.Rows(t).Cells(1).Text)
Posted
Updated 4-May-11 22:57pm
v2
Comments
Sandeep Mewara 5-May-11 4:39am    
Elaborate on "not working". Issue?

BTW, your loop for t should go till count-1.
Mayur Gujrathiii 5-May-11 4:41am    
not working means values are not coming and i correct it to count-1. but still not solved
Dalek Dave 5-May-11 4:58am    
Edited for Grammar and Readability.

VB
for each row as Gridview.Row in Gridview1.Rows

     lblsubheader.Text = row.Cells(1).Text
Next
 
Share this answer
 
v2
Comments
Mayur Gujrathiii 5-May-11 4:46am    
it is giving error on value keyword and after removing it application runs but "System.Web.UI.WebControls.DataControlFieldCell" is getting in lblheader.Text
for(int i=0;i< gridview1.rows.count-1;i++)
{
   label1.text=gridview1.rows[i].cells[0].text;
   label2.text=.....
}
 
Share this answer
 
v3
Comments
Dalek Dave 5-May-11 4:58am    
Code Tag edit.
u can write this

VB
For Each gvr As GridViewRow In GridView1.Rows
                   
                   lblsubheader.Text = gvr.Cells("urColumnName").Text

               Next gvr
 
Share this answer
 
try adding your assignment inside the following if statement

if(theGridViewRow.RowType == DataControlRowType.DataRow)
lblheader.Text = theGridViewRow.Cells(index).Text


probably you are getting error because you are looking into header row and footer row

thanks,
Hemant
 
Share this answer
 
It looks like in the loop always the value of the lable will be replaced. Check the ned of the loop.
 
Share this answer
 

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