I'm trying to display multiple rows from a query into a literal in asp.net c#. Here is my code for doing so:
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(WebConfigurationManager.ConnectionStrings["RaiseFantasyLeagueConnectionString"].ConnectionString);
SqlCommand cmd = new SqlCommand("[dbo].[GetUsersLeagues]", conn);
cmd.CommandType = CommandType.StoredProcedure;
string userId = Membership.GetUser().ProviderUserKey.ToString();
SqlParameter userIDParam = new SqlParameter("@userId", userId);
cmd.Parameters.Add(userIDParam);
conn.Open();
SqlDataReader dReader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
while (dReader.Read())
{
usersLeagues.Text = (dReader["LeagueName"].ToString());
}
dReader.Close();
conn.Close();
}
My issue is that the literal is only displaying one of the rows, i've tried this with a list box and all rows were displayed.
Any suggestions?
Thanks in advance!