FormView doesn't change its mode

M

ma

Hello,

After working for several days, I couldn't manage to run this simple web
page that uses FormView. It doesn't change its mode (it stuck in its item
view mode!)

The code is as follow:



The web page:



<%@ Page Language="C#" Codebehind="Default.aspx.cs"
Inherits="test_FormView._Default" %>





<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

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

<head runat="server">

<title>Untitled Page</title>

</head>

<body>

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

<asp:FormView ID="FormView1" runat="server"
OnModeChanging="FormView1_ModeChanging">

<ItemTemplate>

<table width="100%" cellpadding="5" border="0">

<colgroup>

<col width="25%" valign="top" align="right">

</colgroup>

<tr>

<td>

Key:</td>

<td>

<b>

<%# Eval ( "Key" ) %>

</b>

</td>

</tr>

<tr>

<td>

Name:</td>

<td>

<b>

<%# Eval ( "Name" ) %>

</b>

</td>

</tr>

<tr>

<td colspan="2">

<asp:Button ID="editbutton" Text=" Edit "
CommandName="Edit" runat="server" />

</td>

</tr>

</table>

</ItemTemplate>

<EditItemTemplate>

<h5>

To save changes to the database, press Accept.</h5>

<table width="100%" cellpadding="5" border="0">

<col width="25%" valign="top" align="right">

<tr>

<td>

Name:</td>

<td>

<asp:TextBox MaxLength="254" ID="msgFrom"
runat="server" Text='<%# Bind ( "Name" ) %>' />

</tr>

<tr>

<td colspan="2">

<asp:Button ID="updatebutton" Text=" Accept "
CommandName="Update" runat="server" />

&nbsp;

<asp:Button ID="cancelbutton" Text=" Cancel "
CommandName="Cancel" runat="server" />

</td>

</tr>

</table>

</EditItemTemplate>

</asp:FormView>

</form>

</body>

</html>



The C# Code:

using System;

using System.Data;

using System.Configuration;

using System.Collections;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;



namespace test_FormView

{

public partial class _Default : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

if (!IsPostBack)

{

DataTable CompanyInfo = GetTable();

FormView1.DataSource = CompanyInfo;

FormView1.DataBind();

}

}

public DataTable GetTable()

{

int i = 0;

DataTable m_DataTable = new DataTable();

m_DataTable.Columns.Add("Key", Type.GetType("System.Int32"));

m_DataTable.Columns.Add("Name", Type.GetType("System.String"));

{

i++;

DataRow NewRow = m_DataTable.NewRow();

NewRow["Key"] = i;

NewRow["Name"] = "name data " + i.ToString();

m_DataTable.Rows.Add(NewRow);

}

return m_DataTable;

}

protected void FormView1_ModeChanging(object sender,
FormViewModeEventArgs e)

{



}

}

}



The idea is that I create a table and bind it to the form view in page load.
But it doesn't work?



I did a lot of googling and got nothing! The code seems correct but it does
NOT work!

Any help is very appreciating or any clue what I should do or where can I
read more about it.

Regards
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,699
Latest member
AnneRosen

Latest Threads

Top