why does this formview not appear?

Discussion in 'ASP .Net Datagrid Control' started by Cliff, Feb 14, 2007.

  1. Cliff

    Cliff Guest

    Hi,

    I expect with this code to see the FormView in the browser but nothing
    appears (no error, no formview).
    I checked with variable 'x' and i know there is one record in the dataset.
    The formview must be editable.

    Did i forget something?
    Thanks for help.


    code-behind:
    -----------
    Dim ds As DataSet
    Dim d As SqlDataAdapter
    Dim sql As String
    Dim sConnectionString As String
    Dim x As Integer

    sConnectionString =
    System.Configuration.ConfigurationManager.ConnectionStrings("aspnetdb").ToString()
    'in web.config
    sql = "SELECT field1, field2 FROM table1 where ....
    d = New SqlDataAdapter(sql, sConnectionString)
    ds = New DataSet()
    x = d.Fill(ds) 'this gives 1 record
    FormView1.DataSource = ds
    FormView1.DataBind()

    aspx file:
    ---------
    <form id="form1" runat="server">
    <asp:FormView ID="FormView1" runat="server">
    <EditItemTemplate>
    <asp:Label ID="Label1" runat="server"
    Text="username:"></asp:Label>
    <asp:TextBox runat="server" Text='<%# Eval("field1") %>' >
    </asp:TextBox>
    <br />
    <asp:Label ID="Label2" runat="server" Text="your age:"></asp:Label>
    <asp:TextBox ID="TextBox2" runat="server" Text='<%# Eval("field2")
    %>'>
    </asp:TextBox>
    </EditItemTemplate>
    </asp:FormView>
    </form>
    Cliff, Feb 14, 2007
    #1
    1. Advertising

  2. from the code, that will never show you the editable part !
    cause, and please see the code, where is the line that you say the FormView
    to be in EDIT mode ???
    by default it always show the ITEM mode!

    <asp:FormView ID="FormView1" runat="server" DefaultMode="Edit">

    and by the way, please write a proper code (this s just a sugestion to build
    a cleaner code):

    Imports System.Data
    Imports System.Data.SqlClient

    ---

    Using Connection As New
    SqlConnection(ConfigurationManager.ConnectionStrings("aspnetdb").ConnectionString)
    Dim ad As New SqlDataAdapter("SELECT * FROM TableName... ",
    Connection)
    Dim ds As New DataSet()
    ad.Fill(ds, "TableName")

    FormView1.DataSource = ds
    FormView1.DataBind()
    End Using

    The Using will close all the open objects so you do not need to close after
    using them.

    --

    Bruno Alexandre
    Stroby, Danmark

    "a Portuguese in Denmark"


    "Cliff" <> wrote in message
    news:%...
    > Hi,
    >
    > I expect with this code to see the FormView in the browser but nothing
    > appears (no error, no formview).
    > I checked with variable 'x' and i know there is one record in the dataset.
    > The formview must be editable.
    >
    > Did i forget something?
    > Thanks for help.
    >
    >
    > code-behind:
    > -----------
    > Dim ds As DataSet
    > Dim d As SqlDataAdapter
    > Dim sql As String
    > Dim sConnectionString As String
    > Dim x As Integer
    >
    > sConnectionString =
    > System.Configuration.ConfigurationManager.ConnectionStrings("aspnetdb").ToString()
    > 'in web.config
    > sql = "SELECT field1, field2 FROM table1 where ....
    > d = New SqlDataAdapter(sql, sConnectionString)
    > ds = New DataSet()
    > x = d.Fill(ds) 'this gives 1 record
    > FormView1.DataSource = ds
    > FormView1.DataBind()
    >
    > aspx file:
    > ---------
    > <form id="form1" runat="server">
    > <asp:FormView ID="FormView1" runat="server">
    > <EditItemTemplate>
    > <asp:Label ID="Label1" runat="server"
    > Text="username:"></asp:Label>
    > <asp:TextBox runat="server" Text='<%# Eval("field1") %>' >
    > </asp:TextBox>
    > <br />
    > <asp:Label ID="Label2" runat="server" Text="your
    > age:"></asp:Label>
    > <asp:TextBox ID="TextBox2" runat="server" Text='<%# Eval("field2")
    > %>'>
    > </asp:TextBox>
    > </EditItemTemplate>
    > </asp:FormView>
    > </form>
    >
    >
    Bruno Alexandre, Feb 14, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mr. SweatyFinger

    why why why why why

    Mr. SweatyFinger, Nov 28, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    837
    Mark Rae
    Dec 21, 2006
  2. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,655
    Smokey Grindel
    Dec 2, 2006
  3. Bill Nicholson
    Replies:
    0
    Views:
    308
    Bill Nicholson
    Dec 24, 2006
  4. Cliff
    Replies:
    1
    Views:
    461
    Bruno Alexandre
    Feb 14, 2007
  5. Bob
    Replies:
    3
    Views:
    312
    Barry Schwarz
    Nov 28, 2005
Loading...

Share This Page