473,323 Members | 1,547 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

Novice question about datalists

I have a datalist that takes two clicks to show the SelectedItem or
UpdateItem. The first click seems to fire the event but does not seem to
change the page, the second click doesn't fire the event but changes the
page. I have noticed people don't bind the data on post back but when i
used if(!Page.IsPostBack) to only bind the date on the first load it seems
to loose everything but the date of things that have been displayed with
SelectedItem or UpdateItem.
=========== My Code (.aspx)===========
<table class="InnerTable" cellSpacing="0" cellPadding="0" border="0">
<tr>
<td class="Table-Header-Cell">Notes</td>
<td class="Table-Empty-Cell">&nbsp;</td>
</tr>
<tr>
<td class="Table-Body-Cell" colSpan="2">
<asp:datalist id="dlNotes" OnEditCommand="dlNotes_EditCommand"
Runat="server">
<SelectedItemTemplate>
<DIV class="Table-Item">
<TABLE class="Table-Item" cellPadding="0" width="99%" border="0">
<TR class="Table-Item-Top">
<TD align="center" width="45%"><%#
DataBinder.Eval(Container.DataItem,
"FirstName")%>&nbsp;<%#DataBinder.Eval(Container.D ataItem,
"LastName")%></TD>
<TD
align="center">&nbsp;&nbsp;<%#DataBinder.Eval(Cont ainer.DataItem,
"Date")%></TD>
</TR>
<TR>
<TD class="StandOut" align="center" width="45%">via:
</TD>
<TD align="center"><%# DataBinder.Eval(Container.DataItem,
"MeetingMethod")%></TD>
</TR>
<TR>
<TD colSpan="2"><%# DataBinder.Eval(Container.DataItem,
"Notes")%></TD>
</TR>
<TR>
<TD class="StandOut" align="center" width="45%">Outcome:</TD>
<TD align="center"><%# DataBinder.Eval(Container.DataItem,
"MeetingOutcome")%></TD>
</TR>
<TR class="Table-Item-Bottom">
<TD colSpan="2">[<A href="#">Shrink</A> |
<asp:LinkButton id="lbNoteUpdate" Runat="server"
CommandName="Edit"> Update </asp:LinkButton>|
<A href="#">Delete</A>]</TD>
</TR>
</TABLE>
</DIV>
</SelectedItemTemplate>
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "Date")%>
&nbsp;&nbsp;&nbsp;
<asp:LinkButton id="Linkbutton5" onmouseover="popup('this is the
note','blue');" onmouseout="kill();"
Runat="server">
<%#ShortenString(DataBinder.Eval(Container.DataIte m,
"Notes").ToString(), 30, "...", "Empty Note")%>
</asp:LinkButton>
</ItemTemplate>
<EditItemTemplate>
<DIV class="Table-Item">
<TABLE class="Table-Item" cellPadding="0" width="99%" border="0">
<TR class="Table-Item-Top">
<TD align="center" width="45%"><%#
DataBinder.Eval(Container.DataItem,
"FirstName")%>&nbsp;<%#DataBinder.Eval(Container.D ataItem,
"LastName")%></TD>
<TD
align="center">&nbsp;&nbsp;<%#DataBinder.Eval(Cont ainer.DataItem,
"Date")%></TD>
</TR>
<TR>
<TD class="StandOut" align="center" width="45%">via:
</TD>
<TD align="center">
<asp:DropDownList id="cmMeetingMethod"
runat="server"></asp:DropDownList></TD>
</TR>
<TR>
<TD colSpan="2">
<asp:TextBox id="txtNote" runat="server" Height="43px"
TextMode="MultiLine" Width="393px">111111111111222</asp:TextBox></TD>
</TR>
<TR>
<TD class="StandOut" align="center" width="45%">Outcome:</TD>
<TD align="center">
<asp:DropDownList id="cbMeetingOutcome"
runat="server"></asp:DropDownList></TD>
</TR>
<TR>
<TD class="StandOut" align="center" width="45%">Restricted:</TD>
<TD align="center">
<asp:DropDownList id="cbRestricted">
</asp:DropDownList></TD>
</TR>
<TR class="Table-Item-Bottom">
<TD colSpan="2">[<A href="#">Shrink</A> |
<asp:LinkButton id="Linkbutton6" Runat="server"
CommandArgument="Edit"> Update </asp:LinkButton><A href="#">Delete</A>]</TD>
</TR>
</TABLE>
</DIV>
</EditItemTemplate>
</asp:datalist></td>
</tr>
<tr>
<td class="Table-Bottom-Cell" colSpan="2">[<A href="#">Shrink All</A> | <A
href="#">Expand
All</A> | <A href="#">Add new note</A>]
</td>
</tr>
</table>
=========== My Code (.cs)===========
public class UserDetails : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.DataList dlNotes;
public string UserInfo;

private void Page_Load(object sender, System.EventArgs e)
{
string SQL;
Data DObject = new Data(); // this is my own class that seems to work
correctly
SQL = "SELECT ContactMeet.Date, ContactMeet.MeetingMethod,
ContactMeet.Notes, ContactMeet.MeetingOutcome, Contacts.FirstName,
Contacts.LastName "
+ "FROM Contacts INNER JOIN ContactMeet ON Contacts.ContactID =
ContactMeet.ContactedBy ";
System.Data.DataSet dsNotes = Data.GetDataSetNow(SQL);
dlNotes.DataSource = dsNotes;
dlNotes.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.dlNotes.ItemCommand += new
System.Web.UI.WebControls.DataListCommandEventHand ler(this.dlNotes_ItemComma
nd);
this.dlNotes.EditCommand += new
System.Web.UI.WebControls.DataListCommandEventHand ler(this.dlNotes_EditComma
nd);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

public void dlNotes_EditCommand(object source,
System.Web.UI.WebControls.DataListCommandEventArgs e)
{
dlNotes.EditItemIndex=e.Item.ItemIndex;

}

private void dlNotes_ItemCommand(object source,
System.Web.UI.WebControls.DataListCommandEventArgs e)
{
dlNotes.SelectedIndex = e.Item.ItemIndex;

}
public string ShortenString(string s, int len, string trailing, string
emptyResponse)
{
if(s.Length > len)
s = s.Substring(0,len-trailing.Length)+trailing;
else if(s.Length == 0)
s = emptyResponse;
return s;
}

}
======================================
if anyone knows of a good tutorial or sample code that dimenstrates how to
use a datalist to display, update, add and delete items that would be
wonderful.

Thanks in advance,
~Logan
Nov 18 '05 #1
0 963

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

Similar topics

5
by: Marian | last post by:
Hi, I am totaly novice in .NET and I am studying a book about this. There was mentioned "assembly". I did not understand, how function does it has . I would like to know the exact run of code...
2
by: Greg Fischer | last post by:
I need to access the properties of a control that is nested in 2 datalists. How do you use findcontrol method to do that? what I have is like this: <asp:datalist id="dlist" runat="server">...
1
by: tshad | last post by:
I am trying understand when DataLists ItemCreated is called. I put function that attaches a popup to my delete button: Sub DataList_ItemCreated(Sender As Object, e As DataListItemEventArgs)...
5
by: Chumley Walrus | last post by:
I'm trying to display two different datalists on the same page; only the first datalist displays, while the second does not display (and it does have data matching the where clause): <%@ Page...
2
by: Nathan Sokalski | last post by:
I have a page on which I want to display several sections each of which contain a list of names. I have two database tables, one of which contains the section headings, and the other contains the...
0
by: schapopa | last post by:
I have two nested datalists and I am using percentage to make the width of the row: So my header of the parent datalist looks like this... <table><tr> <td width = 5%> <td width = 12%>...
1
by: TheHach | last post by:
Hi. (For information, i'm working in VB.NET) In our company, we have material that is divided into 3 parts : - a system - a batch - an article In each system are different batches, and in...
2
by: Diffident | last post by:
Hello All, I have a question on datalists. I have 5 datalists on a page and when I try to view the "ViewSource", the value for the __VIEWSTATE is empty. How do datalists persist their values? ...
2
by: Ole V.-M. | last post by:
Greetings, i have a UserControl, that contains a DataList. That DataList contains as items other DataLists. example: DataList A Row 1 Nested DataList 1 Row 1
5
by: =?ISO-8859-2?Q?Istv=E1n?= | last post by:
Could somebody suggest me a novice Python list, please? Thanks, Istvan
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.