Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Professional For advanced ASP.NET 1.x coders. Beginning-level questions will be redirected to other forums. NOT for "classic" ASP 3 or the newer ASP.NET 2.0 and 3.5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 3rd, 2004, 09:51 AM
Registered User
 
Join Date: Jul 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Data Binding to List Controls

hi there,

I ve been reading the Book Professional ASP.Net 1.0 more precisely chapter 7. on List controls and data binding. One thing that seems for me obscure I d like pose you . Hope someone can help with this. The book states that <%# DataBinder.Eval(Container.DataItem, "field-name") %> makes a performance hit i.e. an overhead so it should be avoided unless we deal with formatting. In my code I have just have fields that I have defined in ItemTemplate for DataList so there s a hyperlink defined which takes it caption from the datasource field. So there s nothing with formatting . I try to use Container.DataItem("field-name") but it gives error.it says it should expecting a method instead of property..? I just try to avoid from the overhead.. but I can handle.. the code in books reveal it should quite work well.. my great pre-thanx

 
Old July 3rd, 2004, 04:51 PM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 336
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alyeng2000
Default

just bind properties Text,Value fields like this way
DataTextField="CategoryName" DataValueField="CategoryId"

Ahmed Ali
Software Developer
 
Old July 3rd, 2004, 10:54 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
Send a message via Yahoo to melvik
Default

This is a simple linkBox Binding sample using SQL Server 2000 [u]Northwind Database</u>

Code:
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>

<Script Runat="Server">
  void Page_Load( Object s, EventArgs e )
  {
    SqlConnection myConnection;
    SqlCommand myCommand;
    myConnection = new SqlConnection( "Server=Localhost;uid=sa;Database=Northwind" );
    myCommand = new SqlCommand( "Select CategoryName from Categories", myConnection );
    myConnection.Open();
    myDataList.DataSource = myCommand.ExecuteReader();
    myDataList.DataBind();
    myConnection.Close();
  }
</Script>

<html>
<head><title>Categories</title></head>
<body>

<form Runat="Server">
<asp:DataList id="myDataList" Runat="Server">
  <ItemTemplate>
        <%# DataBinder.Eval( Container.DataItem, "CategoryName" ) %>
  </ItemTemplate>
</asp:DataList>
</form>

</body>
</html>
HTH.

Always:),
Hovik Melkomian.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Binding Controls zulf Infopath 0 October 8th, 2007 11:22 PM
Binding controls Boris Kofman VB Databases Basics 1 January 20th, 2007 01:16 PM
BINDING DATA WITH SIMPLE CONTROLS saraswathyrajaram ASP.NET 1.0 and 1.1 Basics 13 August 29th, 2006 03:09 PM
Visible property of controls in data list acko ASP.NET 1.x and 2.0 Application Design 1 December 9th, 2003 10:41 AM
Data list binding Alok Gupta .NET Web Services 0 September 4th, 2003 05:00 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.