datalist disappears on edit bind

R

Robert Sindall

Hi

I have a simple datalist which displays a list of typenames. it will list
from a datasource and let me add.
But on the Edit bind the list disappears without an error message.

see code

----VB----

Public Class CM_AddressTypeList
Inherits System.Web.UI.Page

Protected WithEvents AddressTypeList As
System.Web.UI.WebControls.DataList
Protected WithEvents AddAddressType As System.Web.UI.WebControls.Button

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

If Not IsPostBack Then

BindData()

End If

End Sub

Private Sub BindData()

Dim myAddressDetails As New CM_AddressType()
AddressTypeList.Visible = True
AddressTypeList.DataSource = myAddressDetails.GetAddressTypes
AddressTypeList.DataBind()
AddressTypeList.ShowHeader = True

If AddressTypeList.Items.Count = 0 Then
AddressTypeList.Visible = False
End If

End Sub

Private Sub AddAddressType_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles AddAddressType.Click

Dim dt As New DataTable()
Dim dv As New DataView(dt)
Dim dr As DataRow

'Set Table Columns
dt.Columns.Add(New DataColumn("TypeID", GetType(Integer)))
dt.Columns.Add(New DataColumn("TypeName", GetType(String)))
dt.Columns.Add(New DataColumn("DateCreated", GetType(Date)))
dt.Columns.Add(New DataColumn("DateModified", GetType(Date)))

dr = dt.NewRow()
dr(0) = 0
dr(1) = ""
dr(2) = Date.Now
dr(3) = Date.Now
dt.Rows.Add(dr)

AddressTypeList.DataSource = dv
AddressTypeList.EditItemIndex = 0
AddressTypeList.DataBind()
AddressTypeList.Visible = True
AddressTypeList.ShowHeader = False

End Sub

Private Sub AddressTypeList_UpdateCommand(ByVal source As Object, ByVal
e As System.Web.UI.WebControls.DataListCommandEventArgs) Handles
AddressTypeList.UpdateCommand

Dim TypeID As Integer = CType(e.CommandArgument, Integer)
Dim TypeName As String = CType(e.Item.FindControl("txtTypeName"),
TextBox).Text

Dim myAddressDetails As New CM_AddressType()
TypeID = myAddressDetails.UpdateAddressType(TypeID, TypeName)

If TypeID <> 0 Then

'DO something

End If

AddressTypeList.EditItemIndex = -1
BindData()

End Sub

Private Sub AddressTypeList_CancelCommand(ByVal source As Object, ByVal
e As System.Web.UI.WebControls.DataListCommandEventArgs) Handles
AddressTypeList.CancelCommand

AddressTypeList.EditItemIndex = -1
BindData()

End Sub

Private Sub AddressTypeList_EditCommand(ByVal source As Object, ByVal e
As System.Web.UI.WebControls.DataListCommandEventArgs) Handles
AddressTypeList.EditCommand

Try
AddressTypeList.EditItemIndex = e.Item.ItemIndex
AddressTypeList.DataBind()
AddressTypeList.Visible = True
AddressTypeList.ShowHeader = False

Catch ex As Exception

Throw ex

End Try

End Sub

End Class

-----------

----ASPX-----
<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="CM_AddressTypeList.aspx.vb"
Inherits="zethics.CM_AddressTypeList"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>Address Type List</title>
<LINK href="/Generation.css" type="text/css" rel="stylesheet">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
</HEAD>
<body class="ap">
<form id="Form1" method="post" runat="server">
<table cellSpacing="5" cellPadding="0" width="100%" border="0">
<tr>
<td>
<table class="Admintbl" cellSpacing="2" cellPadding="2" width="100%"
border="0">
<TR>
<TD class="Admintblhdr" colSpan="2">&nbsp;Address Type List</TD>
</TR>
<tr>
<td colSpan="2"><asp:datalist id="AddressTypeList" Runat="server"
Width="100%" ShowHeader="True" CellSpacing="2" CellPadding="2"
GridLines="None" Visible="True" EnableViewState="True"
CssClass="AdminNormal">
<HeaderTemplate>
<table Class="AdminTblHdr" cellpadding="2" cellspacing="0"
border="0" width="100%">
<tr>
<td width="60">TypeID</td>
<td>TypeName</td>
<td width="150">DateCreated</td>
<td width="150">DateModified</td>
<td width="80">Edit</td>
</tr>
</table>
</HeaderTemplate>
<EditItemStyle CssClass="admintblitm"></EditItemStyle>
<AlternatingItemStyle
CssClass="Admintblalt"></AlternatingItemStyle>
<ItemStyle CssClass="admintblitm"></ItemStyle>
<ItemTemplate>
<TABLE class="AdminNormal" id="Table5" cellSpacing="2"
cellPadding="2" width="100%" border="0">
<TR>
<TD width="60"><%# DataBinder.Eval(Container.DataItem,
"TypeID") %></TD>
<TD><%# DataBinder.Eval(Container.DataItem, "TypeName") %></TD>
<TD width="150"><%# DataBinder.Eval(Container.DataItem,
"DateCreated") %></TD>
<TD width="150"><%# DataBinder.Eval(Container.DataItem,
"DateModified") %></TD>
<TD width="80">
<asp:LinkButton id=LnkEdit Runat="server" Text="Edit"
CommandArgument='<%# DataBinder.Eval(Container.DataItem, "TypeID") %>'
CommandName="Edit">
</asp:LinkButton></TD>
</TR>
</TABLE>
</ItemTemplate>
<HeaderStyle CssClass="Admintblhdr"></HeaderStyle>
<EditItemTemplate>
<TABLE class="AdminTbl" cellSpacing="2" cellPadding="2"
width="100%" border="0">
<TR>
<TD class="AdminTblHdr" colSpan="2">&nbsp;Address Type:</TD>
</TR>
<TR>
<TD class="AdminTblAlt" width="120">&nbsp;Type Name:</TD>
<TD><asp:TextBox id=txtTypeName Runat="server" Text='<%#
DataBinder.Eval(Container.DataItem, "TypeName") %>' CssClass="AdminEditBox">
</asp:TextBox></TD>
</TR>
<TR>
<TD></TD>
<TD><asp:Button id=ApplyChanges Runat="server" Text="Apply
Changes" CssClass="AdminButton" CommandArgument='<%#
DataBinder.Eval(Container.DataItem, "TypeID") %>' CommandName="Update">
</asp:Button>&nbsp;
<asp:Button id="BtnCancel" runat="server" Text="Cancel"
CssClass="AdminButton" CommandName="Cancel"></asp:Button></TD>
</TR>
</TABLE>
</EditItemTemplate>
</asp:datalist></td>
</tr>
<tr>
<td><asp:button id="AddAddressType" Runat="server" Text="Add Address
Type" CssClass="AdminButton"></asp:button></td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</body>
</HTML>
----------------
 

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,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top