473,511 Members | 16,260 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with DataList and updating data

I'm having a bit of a problem with my DataList when I try to update from the
user's input. I've included relevant excerpts at the end of this message. In
the UpdateCommand code, the "PageLevelTextBox" appears to be found (it isn't
returning null), but the Text property is an empty string ("").

Am I missing something really obvious?

Thanks

Colin

private void DeployList_UpdateCommand(object source,
System.Web.UI.WebControls.DataListCommandEventArgs e)
{
int PageLevel, ZoneID;

ZoneID = int.Parse(e.CommandArgument.ToString());
TextBox PageLevelTB =
(TextBox)e.Item.FindControl("PageLevelTextBox");

try
{
PageLevel = int.Parse(PageLevelTB.Text);

Distribution dist = new
Distribution(appEnv.GetConnection());
dist.InsertAtEnd(cid, ver, ZoneID, PageLevel);

DeployList.EditItemIndex = -1;
Bind();
}
catch(Exception ex)
{
Controls.Add(new LiteralControl(ex.Message));
}
}

<edititemtemplate>
<div class="row">
<span class="label" style="width: 35%; text-align: left; ">
<%# DataBinder.Eval(Container.DataItem, "Title") %>
</span>
<span class="formw" style="width: 10%; ">
<asp:linkbutton
commandname="update"
commandargument='<%# DataBinder.Eval(Container.DataItem,
"ZoneID") %>'
text="update"
runat="server"/>
</span>
<span class="formw">
Page:
<asp:textbox
Text='<%# DataBinder.Eval(Container.DataItem, "PageLevel")
%>'
size="2"
id="PageLevelTextBox"
runat="server" />
</span>
</div>
</EditItemTemplate>
Nov 17 '05 #1
3 1582
Hello Colin,

Thanks for your post. I reviewed your code carefully, however, I did not
find any known issue. In addition, I built a sample web page in Visual
Studio .NET 2002 and it works properly on my side. I post my my test code
below, please check it on your side.

I look forward to your response.

Have a nice day!

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! ¨C www.microsoft.com/security
This posting is provided ˇ°as isˇ± with no warranties and confers no rights.

//------------------------WebForm3.aspx.cs---------------------------
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace WebApplication2
{
/// <summary>
/// Summary description for WebForm3.
/// </summary>
public class WebForm3 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataList DeployList;
protected System.Web.UI.WebControls.Button Button2;

ICollection CreateDataSource()
{
DataTable dt = new DataTable();
DataRow dr;

dt.Columns.Add(new DataColumn("StringValue", typeof(string)));

for (int i = 0; i < 10; i++)
{
dr = dt.NewRow();
dr[0] = "Item " + i.ToString();
dt.Rows.Add(dr);
}

DataView dv = new DataView(dt);
return dv;
}

private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{
DeployList.DataSource = CreateDataSource();
DeployList.DataBind();
}

}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.DeployList.UpdateCommand += new
System.Web.UI.WebControls.DataListCommandEventHand ler(this.DeployList_Update
Command);
this.Button2.Click += new System.EventHandler(this.Button2_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void DeployList_UpdateCommand(object source,
System.Web.UI.WebControls.DataListCommandEventArgs e)
{
int PageLevel, ZoneID;

// ZoneID = int.Parse(e.CommandArgument.ToString());
TextBox PageLevelTB =
(TextBox)e.Item.FindControl("PageLevelTextBox");

if(PageLevelTB == null)
Response.Write("Fail to find control");
else
Response.Write(PageLevelTB.Text );
try
{
PageLevel = int.Parse(PageLevelTB.Text);
}
catch(Exception ex)
{
Controls.Add(new LiteralControl(ex.Message));
}
}

private void Button2_Click(object sender, System.EventArgs e)
{
DeployList.EditItemIndex = 1;
}

}
}
//--------------------------------end of-----------------------------

//------------------------------ WebForm3.aspx------------------
<%@ Page language="c#" Codebehind="WebForm3.aspx.cs"
AutoEventWireup="false" Inherits="WebApplication2.WebForm3" %>
<%@ Import Namespace="System.Data" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm2</title>
<meta content="Microsoft Visual Studio 7.0" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="WebForm2" method="post" runat="server">
<FONT face="arial">
<asp:datalist id="DeployList" style="Z-INDEX: 102; LEFT: 91px;
POSITION: absolute; TOP: 21px" runat="server"
AlternatingItemStyle-BackColor="Gainsboro" HeaderStyle-BackColor="#aaaadd"
Font-Size="8pt" Font-Name="Verdana" CellPadding="3" BorderColor="black">
<HeaderTemplate>
Items
</HeaderTemplate>
<AlternatingItemStyle BackColor="Gainsboro"></AlternatingItemStyle>
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "StringValue") %>
</ItemTemplate>
<HeaderStyle BackColor="#AAAADD"></HeaderStyle>
<edititemtemplate>
<div class="row">
<span class="label" style="width: 35%; text-align: left; ">
<%# DataBinder.Eval(Container.DataItem, "Title") %>
</span><span class="formw" style="width: 10%; ">
<asp:linkbutton commandname="update" commandargument='<%#
DataBinder.Eval(Container.DataItem,"ZoneID") %>' text="update"
runat="server" ID="Linkbutton1"/>
</span><span class="formw">Page:
<asp:textbox Text='<%# DataBinder.Eval(Container.DataItem,
"PageLevel")%>' size="2" id="PageLevelTextBox" runat="server" />
</span>
</div>
</edititemtemplate>
</asp:datalist>
<asp:button id="Button2" style="Z-INDEX: 103; LEFT: 290px; POSITION:
absolute; TOP: 37px" runat="server" Text="Button"></asp:button>
</FONT>
</form>
</body>
</HTML>
//------------------------------------------end
of------------------------------

Nov 17 '05 #2
Your sample works. I'm stumped by my code. The trace shows the form
collection containing "DeployList:_ctl1:PageLevelTextBox" with the entered
value and the control tree also contains that control (with that exact
name), however ASP.Net is not properly populating that control with the
entered value.

Any ideas?

Thanks

Colin

"Tian Min Huang" <ti******@online.microsoft.com> wrote in message
news:rL**************@cpmsftngxa06.phx.gbl...
Hello Colin,

Thanks for your post. I reviewed your code carefully, however, I did not
find any known issue. In addition, I built a sample web page in Visual
Studio .NET 2002 and it works properly on my side. I post my my test code
below, please check it on your side.

I look forward to your response.

Have a nice day!

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! ¨C www.microsoft.com/security
This posting is provided ˇ°as isˇ± with no warranties and confers no rights.
//------------------------WebForm3.aspx.cs---------------------------
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace WebApplication2
{
/// <summary>
/// Summary description for WebForm3.
/// </summary>
public class WebForm3 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataList DeployList;
protected System.Web.UI.WebControls.Button Button2;

ICollection CreateDataSource()
{
DataTable dt = new DataTable();
DataRow dr;

dt.Columns.Add(new DataColumn("StringValue", typeof(string)));

for (int i = 0; i < 10; i++)
{
dr = dt.NewRow();
dr[0] = "Item " + i.ToString();
dt.Rows.Add(dr);
}

DataView dv = new DataView(dt);
return dv;
}

private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{
DeployList.DataSource = CreateDataSource();
DeployList.DataBind();
}

}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.DeployList.UpdateCommand += new
System.Web.UI.WebControls.DataListCommandEventHand ler(this.DeployList_Update Command);
this.Button2.Click += new System.EventHandler(this.Button2_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void DeployList_UpdateCommand(object source,
System.Web.UI.WebControls.DataListCommandEventArgs e)
{
int PageLevel, ZoneID;

// ZoneID = int.Parse(e.CommandArgument.ToString());
TextBox PageLevelTB =
(TextBox)e.Item.FindControl("PageLevelTextBox");

if(PageLevelTB == null)
Response.Write("Fail to find control");
else
Response.Write(PageLevelTB.Text );
try
{
PageLevel = int.Parse(PageLevelTB.Text);
}
catch(Exception ex)
{
Controls.Add(new LiteralControl(ex.Message));
}
}

private void Button2_Click(object sender, System.EventArgs e)
{
DeployList.EditItemIndex = 1;
}

}
}
//--------------------------------end of-----------------------------

//------------------------------ WebForm3.aspx------------------
<%@ Page language="c#" Codebehind="WebForm3.aspx.cs"
AutoEventWireup="false" Inherits="WebApplication2.WebForm3" %>
<%@ Import Namespace="System.Data" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm2</title>
<meta content="Microsoft Visual Studio 7.0" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="WebForm2" method="post" runat="server">
<FONT face="arial">
<asp:datalist id="DeployList" style="Z-INDEX: 102; LEFT: 91px;
POSITION: absolute; TOP: 21px" runat="server"
AlternatingItemStyle-BackColor="Gainsboro" HeaderStyle-BackColor="#aaaadd"
Font-Size="8pt" Font-Name="Verdana" CellPadding="3" BorderColor="black">
<HeaderTemplate>
Items
</HeaderTemplate>
<AlternatingItemStyle BackColor="Gainsboro"></AlternatingItemStyle>
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "StringValue") %>
</ItemTemplate>
<HeaderStyle BackColor="#AAAADD"></HeaderStyle>
<edititemtemplate>
<div class="row">
<span class="label" style="width: 35%; text-align: left; ">
<%# DataBinder.Eval(Container.DataItem, "Title") %>
</span><span class="formw" style="width: 10%; ">
<asp:linkbutton commandname="update" commandargument='<%#
DataBinder.Eval(Container.DataItem,"ZoneID") %>' text="update"
runat="server" ID="Linkbutton1"/>
</span><span class="formw">Page:
<asp:textbox Text='<%# DataBinder.Eval(Container.DataItem,
"PageLevel")%>' size="2" id="PageLevelTextBox" runat="server" />
</span>
</div>
</edititemtemplate>
</asp:datalist>
<asp:button id="Button2" style="Z-INDEX: 103; LEFT: 290px; POSITION:
absolute; TOP: 37px" runat="server" Text="Button"></asp:button>
</FONT>
</form>
</body>
</HTML>
//------------------------------------------end
of------------------------------

Nov 17 '05 #3
Hi Colin,

I did not find any obvious issue that may cause the problem in your code.
Since my sample works, could you post a simple web page which is able to
reproduce the problem? I will be glad to check it on my side.

I look forward to hearing from you.

Have a nice day!

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! ¨C www.microsoft.com/security
This posting is provided ˇ°as isˇ± with no warranties and confers no rights.
Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1455
by: rodneybauer1 | last post by:
hello: thanks in advance for any responses. i dont have a isp at home so have to use public library computer. will check this every couple days though. im using visual basic.Net windows XP with...
0
838
by: Colin Young | last post by:
I'm having a bit of a problem with my DataList when I try to update from the user's input. I've included relevant excerpts at the end of this message. In the UpdateCommand code, the...
0
1754
by: Alex | last post by:
Imports System Imports System.Data Imports System.Data.SqlClient Imports System.Web.UI Imports System.Web.UI.WebControls Imports System.Configuration Public Class Main : Inherits Page ...
1
3329
by: Glenn Owens | last post by:
Here's the scenario: I have a DataList populated from a datatable sitting inside a fieldset. Each element (row) in the Datalist has the following child controls: asp:checkbox, asp:image,...
2
2193
by: Olav Tollefsen | last post by:
I have a Web Form with a DataList. Inside the ItemTemplate, I have a DropDownList control. <asp:DataList ID="ProductDataList" Runat="server"> <ItemTemplate> <asp:DropDownList ID="DropDownList1"...
0
1121
by: Maran | last post by:
We have come across a situation that I thinks not many have. Grateful for all responses. Regards Maran ************* * Scenario A DataList binds to a DataRow, with "RegionName" och...
2
3425
by: scottls | last post by:
Hi All, Thanks for reading my post. I have been working on getting nested datalists working properly wihtin my framework for many days and I think I'm almost there. See if you could help me...
0
1036
by: lamarant | last post by:
OK...I have a datalist that, in each row, has control and a label. What I want to happen is for the text in the label to update when its associated control is clicked. Here's what I have so...
0
1066
by: Bieniu | last post by:
I have DataList control on my own contro land it is bind to SqlDataSource control. My problem is that DataList is getting needed data twice what is for me very strange. I have some code in...
0
7242
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7138
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7418
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7075
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7508
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3222
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
781
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
446
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.