www.webdeveloper.com
Results 1 to 5 of 5

Thread: Problem with databinding a webform/textboxes

  1. #1
    Join Date
    Jul 2004
    Posts
    43

    Problem with databinding a webform/textboxes

    I have 2 textboxes on my webform (ASP.NET) that are bound to a database. The only line in my load sub (after the page.ispostback line) is:

    page.databind()

    This is the error I get:

    Code:
    Index 0 is not non-negative and below total rows count. 
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
    
    Exception Details: System.IndexOutOfRangeException: Index 0 is not non-negative and below total rows count.
    How do I fix this? I'm using an SQLDataAdapter and connection.

  2. #2
    Join Date
    Nov 2002
    Location
    Auburn, AL
    Posts
    9,224

  3. #3
    Join Date
    Jul 2004
    Posts
    43
    Code:
        Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            'Put user code to initialize the page here
            If Not Page.IsPostBack Then
                'Panel1.DataBind()
                Page.DataBind()
            End If
        End Sub
    Code:
    <%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm1.aspx.vb" Inherits="Testing.WebForm1"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    	<HEAD>
    		<title>WebForm1</title>
    		<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
    		<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
    		<meta name="vs_defaultClientScript" content="JavaScript">
    		<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
    	</HEAD>
    	<body MS_POSITIONING="GridLayout">
    		<form id="Form1" method="post" runat="server">
    			&nbsp;
    			<asp:TextBox id=TextBox1 style="Z-INDEX: 101; LEFT: 248px; POSITION: absolute; TOP: 224px" runat="server" Text='<%# DataBinder.Eval(DataSet11, "Tables[equipment].DefaultView.[0].BAR-CODE") %>'>
    			</asp:TextBox>
    		</form>
    	</body>
    </HTML>

  4. #4
    Join Date
    Jul 2004
    Posts
    43
    Ok, I found out I needed this line: SqlDataAdapter1.Fill(dataset11)

    Now, my next question. How do I navigate through this? (i.e., previous, next, first, last, etc.).

  5. #5
    Join Date
    Nov 2002
    Location
    Auburn, AL
    Posts
    9,224
    its a lot like an array. You use the rows.

    dataset.Tables("table").Rows(0).Item("field")
    that will return the first record
    dataset.Tables("table").Rows.Count()
    will return the total number of rows.
    But it is in essence a big array created by your data.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles