Loop through record in datareader in aspx for textbox other item

Joined
Sep 26, 2023
Messages
1
Reaction score
0
back end side



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;
using System.Data.SqlClient;
public partial class Default3 : System.Web.UI.Page
{



protected void Page_Load(object sender, EventArgs e)
{

}


public IEnumerable<IDataRecord> ListUrunlers()
{
SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["constr"].ToString());
SqlCommand command = new SqlCommand("SELECT * FROM country", connection);
connection.Open();
SqlDataReader dr = command.ExecuteReader();

while (dr.Read())
{
yield return dr;
}
}

}


web designer side



<%@ Page Language = "C#" AutoEventWireup = "true" CodeFile = "Default3.aspx.cs" Inherits = "Default3" %>


<%@ Import Namespace="System.Data" %>

<!DOCTYPEhtml>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id = "Head1" runat = "sunucu">
<title></title>
</head>
<gövde>
<form id = "form1" runat = "sunucu">

<tablo>
<% foreach (ListUrunlers()'daki IDataRecord kaydı) { %>
<tr>
<td><%= kayıt["ülkekimliği"] %> </td>
<td><%= Record["ulkeismi"] %> </td>
<td><%= kayıt["fotoğraf"] %> </td>


<td> <asp:TextBox ID = "TextBox1" runat = "sunucu" text = "<%= kayıt["ülke kimliği"] %>
"></asp:TextBox></td>

<td> <asp:TextBox ID = "TextBox2" runat = "sunucu" text = "<%= kayıt["ulkeısmı"] %>
"></asp:TextBox></td>

</tr>
<% } %>
</table>
</form>
</body>
</html>

-----------------
When I added the textbox to the web designer html section of the code above, I could not accept the dbase variable in it. My code works fine without this textbox line, but I wanted to have a textbox element as well. I want to perform the loop on the web designer side. I do not want to use repeater datagridview datalist buildingstring or similar structures. The code should be returned in the web designer section. I couldn't make the dbase variable, which is specified with special signs, work for the textbox in the web designer section. I couldn't run it. Do I need to define a puclic variable on the back end? Is it necessary to pass it to the web designer side? I couldn't figure it out. Thank you, sir. I respectfully ask, how to assign a value for this textbox?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,717
Messages
2,569,381
Members
44,699
Latest member
ChristaBya

Latest Threads

Top