Welcome Guest Search | Active Topics | Members | Log In | Register

FormView doesn't change its mode Options · View
ma
Posted: Monday, October 08, 2007 11:06:16 AM


Rank: Guest
Groups: Guest

Joined: 9/17/2007
Posts: 11,670
Points: -1,200
Date parsed: 08/10/2007 11:06:16
Date: Mon, 8 Oct 2007 10:06:16 +0100

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


Users browsing this topic
Guest


Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Main Forum RSS : RSS

YAFPro Theme Created by Jaben Cargman (Tiny Gecko)
Powered by Yet Another Forum.net version 1.9.1.1 (NET v2.0) - 9/10/2007
Copyright © 2003-2006 Yet Another Forum.net. All rights reserved.
This page was generated in 0.071 seconds.