tags:

views:

70

answers:

3

is it possible to get a single row in ASP.NET? i always used dataList but this destroys my design with the item template, i need somethink that has no template only the Eval() statements

A: 

First of all: your problem is realy very basic and you should consider reading a book ;-).

What you can do is to use the normal binding on the page...

If you are using plain old sql your code might look like this. But if you are using Linq-To-Sql or event Entity Framework it is a different story.

Attention: in this example is realy straight forward.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Default" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Configuration" %>

<script runat="server" type="text/C#">

    protected DataRow _currentRow = null;

    protected void Page_Load(object sender, EventArgs e)
    {
        using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["pubs"].ConnectionString))
        {
            using (SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM authors", connection))
            {
                DataTable table = new DataTable();
                adapter.Fill(table);

                _currentRow = table.Rows[0];
            }
        }

        Page.DataBind();
    }

</script>

<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head runat="server">
    <title>Testpage</title>
</head>
    <body>
        <form id="form1" runat="server">
            <asp:TextBox ID="TextBox1" runat="server" Text='<%# _currentRow["Name"] %>'></asp:TextBox>
        </form>
    </body>
</html>
Yves M.
can you make a bigger example please?i dont know what to do
mullek
A: 

if you are looking only for <%# Eval() %>

then take a literal palace a binding expression like #Eval and from your code behind bind it using mylietral.DataBind();

ajay_whiz
A: 

is it possible to get a single row in ASP.NET? ... i need somethink that has no template

In that case I suggest you simply either use a Literal or Label control instead.

XIII