I am returning result of store procedure and put it in the list. I would like to show list element in the label. My list has 1 row and 4 columns. How I can show each element in the label? Thank you for your help.
That is where I call methods to execute the store proc and return the values in the list and list does have value when I debug.
nikoo56
Member
287 Points
204 Posts
Get access to List element and show in lable
Nov 09, 2011 04:52 PM|LINK
I am returning result of store procedure and put it in the list. I would like to show list element in the label. My list has 1 row and 4 columns. How I can show each element in the label? Thank you for your help.
That is where I call methods to execute the store proc and return the values in the list and list does have value when I debug.
List<Tax> taxlist = DataManager.taxcalculation(url, CourseDescription, Session[Config.SESSION_STATE].ToString());
foreach (var item in taxlist)
{
lblTax.Text= ???
}
kushalrdalal
Contributor
7130 Points
1273 Posts
Re: Get access to List element and show in lable
Nov 09, 2011 04:57 PM|LINK
Can you send how your Tax class is?
I mean the structure of Tax class.
My Blog
LinkedIn Profile
nikoo56
Member
287 Points
204 Posts
Re: Get access to List element and show in lable
Nov 09, 2011 05:47 PM|LINK
That is method that return the tax list.
public static List<Tax> taxcalculation(string url, string courseName, string state) { List<Tax> taxList = new List<Tax>(); using (SqlConnection conn = new SqlConnection(Config.ConnectionString)) { conn.Open(); SqlCommand cm = new SqlCommand("sc_get_online_prices", conn); cm.CommandType = CommandType.StoredProcedure; cm.Parameters.Add(new SqlParameter("@url", url)); cm.Parameters.Add(new SqlParameter("@course_name", courseName)); cm.Parameters.Add(new SqlParameter("@state", state)); SqlDataReader reader = cm.ExecuteReader(CommandBehavior.CloseConnection); while (reader.Read()) { taxList.Add(Tax.GetTaxFromDataReader(reader)); } } return taxList; }nikoo56
Member
287 Points
204 Posts
Re: Get access to List element and show in lable
Nov 09, 2011 06:00 PM|LINK
Ok I found out:
foreach (var item in taxlist)
{
lblTax.Text = taxlist[0].tax.ToString();
}