loop through record in datareader in aspx for textbox other item



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" %>


<!DOCTYPE html>


<html xmlns="http://www.w3.org/1999/xhtml">

<head id="Head1" runat="server">

  <title></title>

</head>

<body>

  <form id="form1" runat="server">


    <table>

      <% foreach (IDataRecord record in ListUrunlers()) { %>

        <tr>

          <td><%= record["countryid"] %> </td>

          <td><%= record["ulkeismi"] %> </td>

          <td><%= record["photo"] %> </td>



       <td>  <asp:TextBox ID="TextBox1" runat="server" text="<%= record["countryid"] %>

"></asp:TextBox></td>


         <td>   <asp:TextBox ID="TextBox2" runat="server" text="<%= record["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?


1 Reply

MK Muthukrishnan Kandasamy Syncfusion Team September 29, 2023 12:08 PM UTC

Hi Omer,


Thanks for contacting Syncfusion support.


We have checked your query with your provided details. Your query is not related to our Syncfusion components, so we suggest to refer the some general blogs for your requirement.


https://stackoverflow.com/questions/8370927/how-do-i-loop-through-rows-with-a-data-reader-in-c


https://learn.microsoft.com/en-us/dotnet/framework/data/adonet/retrieving-data-using-a-datareader


https://stackoverflow.com/questions/22048290/looping-through-rows-with-executereader


Please let us know, if you need any further assistance with Syncfusion components.


Regards,

Muthukrishnan K


Loader.
Up arrow icon