This code works 100%, it was written by our teacher Muddassar
I would like to list the ctrypopulation variable value that I added to the table and the ctrymultiply value that I added to the table, and the country's population increase as a percentage, in a circular manner. Best regards, my great teacher.
<div>
<table>
<% foreach (var c in this.item())
{ %>
<tr>
<td>
<label><%=c.countryid%></label></td>
<td>
<input type="text" value='<%=c.countryname %>' /></td>
<td>
<input type="text" value='<%=c.photo%>' /></td>
<td>
<input type="radio" <%=c.countryname.ToLower() == "india" ? "checked" : "" %> /></td>
<td>
<input type="checkbox" <%=c.countryname.ToLower() != "india" ? "checked" : "" %> /></td>
<td>
<a href='Details.aspx?idno=<%=c.countryid %>'>Customer Detail</a> </td>
<td>
<button type="submit" name="btnSubmit_<%=c.countryid%>">View</button>
</td>
</tr>
<% } %>
</table>
</div>
<hr />
<div>
<table>
<tr>
<td>
<label><%=countryidx%></label>
</td>
</tr>
<tr>
<td>
<input type="text" value='<%=ulkeismix%>' />
</td>
</tr>
<tr>
<td>
<input type="text" value='<%=photox%>' />
</td>
</tr>
</table>
</div>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
public int ctryresult;
public int countryidx;
public string photox;
public string ulkeismix;
public List<Country> item()
{
string sqlStatment = "select * from Country";
string constr = System.Configuration.ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection(constr))
{
using (System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(sqlStatment, con))
{
cmd.Connection.Open();
System.Data.SqlClient.SqlDataReader reader = cmd.ExecuteReader();
List<Country> emp = new List<Country>();
while (reader.Read())
{
Country country = new Country();
country.countryid = Convert.ToInt32(reader.GetValue(0));
country.countryname = reader.GetValue(2).ToString();
country.photo = reader.GetValue(1).ToString();
country.ctrypopulation = reader.GetValue(3).ToString();
country.ctrymultiply = reader.GetValue(4).ToString();
emp.Add(country);
}
reader.Close();
cmd.Connection.Close();
return emp;
}
}
}
public class Country
{
public int countryid { get; set; }
public string countryname { get; set; }
public string photo { get; set; }
}
public List<Country> Item { get; set; }
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.Item = this.item();
}
else
{
foreach (string item in Request.Form.AllKeys)
{
if (item.Contains("btnSubmit"))
{
string id = item.Split('_')[1].Trim();
string sqlStatment = "SELECT * FROM country WHERE countryid=@Id";
string constr = System.Configuration.ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection(constr))
{
using (System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(sqlStatment, con))
{
cmd.Parameters.AddWithValue("@Id", id);
cmd.Connection.Open();
System.Data.SqlClient.SqlDataReader reader = cmd.ExecuteReader();
if (reader.Read())
{
countryidx = Convert.ToInt32(reader.GetValue(0));
ulkeismix = reader.GetValue(1).ToString();
photox = reader.GetValue(2).ToString();
}
reader.Close();
cmd.Connection.Close();
}
}
break;
}
}
}
}
}
i adds line begin web designer side
<td>
<input type="text" value='<%=c.ctrypopulation%>' /></td>
<td>
<td>
<input type="text" value='<%=c.ctrymultiply%>' /></td>
<td>
<td>
<input type="text" value='<%=c.ctryresult%>' /></td>
<td>
<td>
<input type="text" value='<%=ctryresult=%>'=<%=c.ctrymultiply%* <%=c.ctryresult%> /></td>
<td>