I have 5 records in my Database and the below code is working fine to retrieve all the 5 records and write them.
while (dr.Read())
{
String a1 = dr[0].ToString();
Response.Write(a1);
}
but, when I remove Resonse.Write(a1); and using repvals = a1; the output is displaying only last one record but not all records.
while (dr.Read())
{
String a1 = dr[0].ToString();
repvals = a1;
}
In the above code repvals is a server side HTML control declared <%=repvals%> and declared as protected string repvals in code page.
You need to concatenate the new string in repvals in each itiration, So Try this instead