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?
 
Joined
Nov 23, 2023
Messages
56
Reaction score
3
You can create new controls (e.g., TableRow, TableCell) and populate them with data from the reader.
 

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

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,059
Latest member
cryptoseoagencies

Latest Threads

Top