How to get a record from the list with button click without using JavaScript.
This code works 100%, but can a record be brought from the list using the classical method without JavaScript?
There are no examples of this, it is always said that it will work with JavaScript.
Is it possible? I have heard that the classical method should work if JavaScript is turned off in the browser settings.
If it is possible, it will be a great thing.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data.SqlClient;
public partial class Default6 : System.Web.UI.Page
{
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();
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)
{
if (!this.IsPostBack)
{
this.Item = this.item();
}
}
}
protected void ON(object sender, EventArgs e)
{
string id = Request.Form[hfCustomerId1.UniqueID].Trim();
// string id = "2";
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();
}
}
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default6.aspx.cs" Inherits="Default6" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id2="form1" runat="server">
<div>
<asp:HiddenField ID="hfCustomerId1" runat="server" />
<table style="width: 1000px">
<% foreach (var c in this.item())
{ %>
<tr>
<td class="style3">
<label><%=c.countryid%></label></td>
<td class="style3">
<input type="text" value='<%=c.countryname %>' /></td>
<td class="style3">
<input type="text" value='<%=c.photo%>' /></td>
<td class="style3">
<input type="radio" <%=c.countryname== "india" ? "checked" : "" %> /></td>
<td class="style3">
<input type="checkbox" <%=c.countryname!= "india" ? "checked" : "" %> /></td>
<td class="style4">
<a href='countrydetail.aspx?idno=<%=c.countryid %>'>country detaıl</a> </td>
<td>
<asp:Button ID="btnView" CssClass="View" runat="server" Text="View" OnClick="ON" />
</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>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
$('.View').on('click', function () {
var id = $(this).closest('tr').find('td').eq(0).text().trim();
$('[id*=hfCustomerId1]').val(id);
});
});
</script>
</form>
</body>
</html>