CodeVerge.Net Beta


   Explore    Item Entry    Members      Register  Login  
NEWSGROUP
.NET
Algorithms-Data Structures
Asp.Net
C Plus Plus
CSharp
Database
HTML
Javascript
Linq
Other
Regular Expressions
VB.Net
XML

Free Download:




Zone: > NEWSGROUP > Asp.Net Forum > starter_kits_and_source_projects.internet_explorer_web_controls Tags:
Item Type: NewsGroup Date Entered: 1/18/2007 9:30:15 AM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
(NR, 0)
XPoints: N/A Replies: 0 Views: 56 Favorited: 0 Favorite
Can Reply:  No Members Can Edit: No Online: Yes
10 Items, 1 Pages 1 |< << Go >> >|
Julio34
Asp.Net User
Using click event with datalist1/18/2007 9:30:15 AM

0/0

Hi, I'm trying to do a web application where an icon list is needed, something like the ListView in C#. I use datalist with it, displaying the text with a label, but, unlike C#, the label has no click event implemented. I need to display a context menu or, at least, get the label's text selected. Can someone help me to do that?

 thanks!!!

Hope4sun
Asp.Net User
Re: Using click event with datalist1/18/2007 2:05:47 PM

0/0

Not sure if this covers exactly what your looking for, but may well get you started in the right direction: http://www.codeproject.com/aspnet/DataListHighlightingClick.asp
Julio34
Asp.Net User
Re: Using click event with datalist1/18/2007 2:50:47 PM

0/0

Hi,

No, it doesn't. I create the DataList, ItemTemplate and all the structure from code-behind. However, the topic has changed a little because I switched the Label for the LinkButton, the display is the same and linkbutton does have onclick event implemented.

My problem now is when I click the button inside the DataList, instead of firing the event, everything disappears :S. Any ideas?

bstinson
Asp.Net User
Re: Using click event with datalist1/18/2007 3:44:44 PM

0/0

Sounds like the datalist is not being re-bound in the code for your click event.


Brett Stinson
[email protected]
Hope4sun
Asp.Net User
Re: Using click event with datalist1/18/2007 3:45:15 PM

0/0

Ah yes, thats the good old event bubbling in the datalist control, the DataList control supports the following five events:

? ItemCommand

? UpdateCommand

? EditCommand

? DeleteCommand

? CancelCommand

When a child control is created in the control, the type of event to be raised in the containing control can be indicated by using the CommandName property.

Les say for example, you want to raise an UpdateCommand event, you would specify the CommandName property like this:

 
<asp:LinkButton Text="Update this data!" CommandName="update" Runat="Server" />

 this would call the update routine you had defined, i hope this sorts the problem out for you Smile
 

 

Julio34
Asp.Net User
Re: Using click event with datalist1/18/2007 4:36:13 PM

0/0

 

 

public

class WebForm1 : System.Web.UI.Page

{

protected System.Web.UI.WebControls.DataList DataList1;

protected System.Web.UI.WebControls.LinkButton lb;

override protected void OnInit(EventArgs e)

{

InitializeComponent();

ConectarBBDD();

base.OnInit(e);

}

 

private void InitializeComponent()

{

this.DataList1.UpdateCommand +=new DataListCommandEventHandler(DataList1_UpdateCommand);

}

private

void DataList1_UpdateCommand(object source, DataListCommandEventArgs e)

{

//code to run when the event is fired

}

private void FillDataSet()

{

//Code to fill DataSet

private

void FillDatalistDisp(DataSet ds)

{

DataList1.ItemTemplate =

new DatalistLabelColumn();

DataList1.DataSource = ds.Tables[

"VEND"].DefaultView;

DataList1.DataBind();

}

 

//This class creates the ItemTemplate at runtime

public class DatalistButtonColumn : ITemplate

{

protected LinkButton lb;

public void InstantiateIn(Control container)

{

LinkButton lb = new LinkButton();

lb.CommandName = "DataList1_UpdateCommand";

lb.DataBinding += new EventHandler(this.BindButtonColumn);

container.Controls.Add(lb);

}

 

private void BindButtonColumn(object sender, EventArgs e)

{

LinkButton lbl = (LinkButton)sender;

DataListItem container = (DataListItem)lbl.NamingContainer ;

String strVals =Convert.ToString(DataBinder.Eval(((DataListItem)container).DataItem, "vend"));

lbl.Text = strVals;

}

}

Julio34
Asp.Net User
Re: Using click event with datalist1/18/2007 4:40:07 PM

0/0

It doesn't work, there's something obviously wrong there. Could you please help me, I posted the code above. (I misclicked enter, sorry)
 
Julio34
Asp.Net User
Re: Using click event with datalist1/18/2007 4:46:27 PM

0/0

Sorry, I messed that up, I'll repost it again better I hope

 

	public class WebForm1 : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.DataList DataList1;
		protected System.Web.UI.WebControls.LinkButton lb;



		private void LlenarDatalistVend(DataSet ds)
		{
	
			DataList1.ItemTemplate = new DatalistButtonColumn("vnsdes"); 
			DataList1.DataSource = ds.Tables["VEND"].DefaultView;
			DataList1.DataBind(); 
		}


		#region C?digo generado por el Dise?ador de Web Forms
		override protected void OnInit(EventArgs e)
		{
			InitializeComponent();
			ConectarBBDD();			
			base.OnInit(e);
		}
		
		private void InitializeComponent()
		{    
			this.DataList1.UpdateCommand +=new DataListCommandEventHandler(DataList1_UpdateCommand);
		}

private

void DataList1_UpdateCommand(object source, DataListCommandEventArgs e)

{

//Event code

}#endregion }
	public class DatalistButtonColumn : ITemplate 
	{ 
		string sCamp = "";
		protected LinkButton lb;
 
		public void InstantiateIn(Control container) 
		{ 
			LinkButton lb = new LinkButton();
			lb.CommandName = "DataList1_UpdateCommand";
			lb.DataBinding += new EventHandler(this.BindLabelColumn); 
			container.Controls.Add(lb);
		} 
 
		private void BindLabelColumn(object sender, EventArgs e)
		{ 
			LinkButton lbl = (LinkButton)sender; 
			DataListItem container = (DataListItem)lbl.NamingContainer ; 
			String strVals =Convert.ToString(DataBinder.Eval(((DataListItem)container).DataItem, sCamp)); 
			lbl.Text = strVals;

		} 
	} 
 
Hope4sun
Asp.Net User
Re: Using click event with datalist1/18/2007 6:40:36 PM

0/0

I've recreated some of your code and sorted out your issue on my machine at lease Smile

All i've done in the end is to make sure that the controls are added to the datalist during the page_init, also lb.CommandName needs to be lb.CommandName = "Update";

 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default8.aspx.cs" Inherits="Default8" %>

<!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">
    <div>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:TestConnectionString %>" SelectCommand="SELECT * FROM [Contacts]"></asp:SqlDataSource>
        <asp:DataList ID="DataList1" runat="server" DataKeyField="ID" DataSourceID="SqlDataSource1" OnUpdateCommand="DataList1_UpdateCommand">
            <ItemTemplate>
             
            </ItemTemplate>
        </asp:DataList>
    </div>
       
    </form>
</body>
</html>


public partial class Default8 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

       
        //DataList1.DataSource = SqlDataSource1();
       
    }

    protected void Page_Init()
    {
        DataList1.ItemTemplate = new DatalistButtonColumn();
    }
   

    protected void DataList1_UpdateCommand(object source, DataListCommandEventArgs e)
    {
        LinkButton txt = (LinkButton)e.CommandSource;
        Response.Write(txt.Text);
    }

    public class DatalistButtonColumn : ITemplate
    {
        protected LinkButton lb;

        public void InstantiateIn(Control container)
        {
            LinkButton lb = new LinkButton();
            lb.CommandName = "Update";
            lb.DataBinding += new EventHandler(this.BindButtonColumn);
            container.Controls.Add(lb);
           
              
       
        }

       


        private void BindButtonColumn(object sender, EventArgs e)
        {
            LinkButton lbl = (LinkButton)sender;
            DataListItem container = (DataListItem)lbl.NamingContainer;
            String strvals = Convert.ToString(DataBinder.Eval(((DataListItem)container).DataItem, "id"));
            lbl.Text = strvals;
           
        }


    }

}

Julio34
Asp.Net User
Re: Using click event with datalist1/19/2007 10:58:49 AM

0/0

It works!! yeah, the problem was that the controls we're not initialized on the page_init, but don't you have problems with postback if the controls are loaded at the begining?

thx for the answers!!!

10 Items, 1 Pages 1 |< << Go >> >|


Free Download:

Books:
ASP.NET Kick Start: Kick Start Authors: Stephen Walther, Pages: 608, Published: 2002
ASP.NET Unleashed Authors: Stephen Walther, Pages: 1488, Published: 2003
Build Your Own ASP.NET 2.0 Web Site Using C# & VB: The Ultimate ASP.NET Begginner's Guide Authors: Cristian Darie, Zak Ruvalcaba, Pages: 689, Published: 2006
Programming ASP.NET: Building Web Applications and Services with ASP.NET 2.0 Authors: Jesse Liberty, Dan Hurwitz, Pages: 930, Published: 2005
Building Web Solutions with ASP.NET and ADO.NET Authors: Dino Esposito, Pages: 379, Published: 2002
ASP.NET: Tips, Tutorials, and Code Authors: Scott Mitchell, Pages: 878, Published: 2002
Sams Teach Yourself ASP.NET in 21 Days Authors: Chris Payne, Pages: 1104, Published: 2002
Excel 2007 VBA Programmer's Reference Authors: John Green, Stephen Bullen, Rob Bovey, Michael Alexander, Pages: 1143, Published: 2007
Programming Data-driven Web Applications with ASP.NET Authors: Donny Mack, Doug Seven, Pages: 704, Published: 2002
MCAD Developing and Implementing Web Applications with Microsoft Visual C#(TM) . NET and Microsoft Visual Studio(R) . NET Exam Cram 2 (Exam Cram 70-315): Exam Cram 2, McAd Exam 70-315 Authors: Kirk Hausman, Amit Kalani, Priti Kalani, Ed Tittel, Pages: 555, Published: 2003

Web:
CodeProject: Enable DataList Row Highliting and Click Event ... Aug 14, 2004 ... NET DataList row highlighting and row click event response using combination of non-display button and some advanced databinding techniques. ...
Using click event with datalist - ASP.NET Forums
Expertrating - ASP.Net Tutorial, DataList Controls When a child control is created in a DataList or DataGrid, the type of event to be raised in the containing control can be indicated by using the ...
How to: Respond to Button Events in DataList, Repeater, or ... The following example shows how you can respond to a button click in a DataList ... For an example using the DataList Web server control, see How to: Allow ...
DataList ImageButton Click event when i click on linkbuttons itemcommand event of datalist raised but when i click on imagebutton of datalist, itemcommand event was not ...
InformIT: Safari Books Online - 067232542X - ASP.NET Unleashed ... Download "Using the DataList and DataGrid Controls" Using the DataList and ... Instead of writing code to handle the Click event for each LinkButton ...
datalist control row click event - technical discussion ... Sep 19, 2008 ... Hi I have a datalist control in my aspx page. I want to get the values of the colums for a row selected by the user and pass them to a ...
Asp.Net GridView Manipulation Inside DataList Control - Sample ... This article explores the concept of using a GridView control inside the ... Step 2: In ItemDataBound Event of DataList control, bind the GridView control. ...
The DataList Control :: Data Bound .NET Controls :: Part I: Data ... Figure 1-5. A button bar generated using DataList. The ItemCommand event is the only way you can handle the click event for buttons. ...
How to get Control value in DataList ItemTemplate after Button ... In the source code below, i have a DataList with ItemTemplates, ... to get Control value in DataList ItemTemplate after Button click event ...




Search This Site:










post about building custom controls in asp.net 2.0

wat and create user

how do determine current login status and the login userid?

how to access network files - urgent help!

dynamic usercontrols within a user control?

error when editing module container…

sql server web data administrator info ..

treeview menu

dnn 3.0.12 deployment????

relative linking issue

it's running on design time but not run time.

the image handler (handler.ashx) in the personal web site starter kit

problem with internet explorer

another (little) masterpage problem

how to detect(tst) primary keys violation

does asp .net support javascript?

knowing items added/removed in itemtemplate in design mode

connect two textboxes, master and content???

login controls

unhandled error on dnn v4 install

help!! security in dnn

html page redesgin: throwing tables out the window

programmatically set the selected menu item in the menu control

2 host users

3.08 adding new module definition error

is there a current module developers guide for dnn 4.0

digging into the events calendar - event info not in viewstate?

default dnn3 skins re-distribution?

setting up user and roles

can't add users with a scheduler task

 
All Times Are GMT