473,778 Members | 1,901 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Web - Buttons In A DataGrid or DataList

If I have a DataGrid or DataList on a webpage with an ItemTemplate that
includes a button server control, how can I set it in the ItemTemplate
so that all the buttons populated in the grid/list will call a specified
function in my code-behind. Also, from that function, how can I access
the properties of the button that called it?
Regards,
David P. Donahue
dd******@ccs.ne u.edu
Nov 16 '05 #1
3 1254
Create the event handler for your button as follows, take note that the
accessibility of the method is set to protected and not to the usual private
setting.

protected void ButtonClick(obj ect sender, System.EventArg s e)

{

Response.Write( "Button: " + ((Button)sender ).ClientID + " was clicked!");

}

In your aspx file, where you declare the button in the item template,
include this in the button declaration tag:

ONCLICK="Button Click"
The ClientID property will return a value like "_ctl1_btn1 " for the first
button, "_ctl2_btn1 " for the second, and so on.

HTH

DalePres
MCAD, MCDBA, MCSE
"David P. Donahue" <dd******@ccs.n eu.edu> wrote in message
news:uc******** ******@TK2MSFTN GP15.phx.gbl...
If I have a DataGrid or DataList on a webpage with an ItemTemplate that
includes a button server control, how can I set it in the ItemTemplate so
that all the buttons populated in the grid/list will call a specified
function in my code-behind. Also, from that function, how can I access
the properties of the button that called it?
Regards,
David P. Donahue
dd******@ccs.ne u.edu

Nov 16 '05 #2
Perfect :) Casting the "sender" object to an ImageButton was precisely
what I needed to do. Thanks!
Regards,
David P. Donahue
dd******@ccs.ne u.edu

DalePres wrote:
Create the event handler for your button as follows, take note that the
accessibility of the method is set to protected and not to the usual private
setting.

protected void ButtonClick(obj ect sender, System.EventArg s e)

{

Response.Write( "Button: " + ((Button)sender ).ClientID + " was clicked!");

}

In your aspx file, where you declare the button in the item template,
include this in the button declaration tag:

ONCLICK="Button Click"
The ClientID property will return a value like "_ctl1_btn1 " for the first
button, "_ctl2_btn1 " for the second, and so on.

HTH

DalePres
MCAD, MCDBA, MCSE
"David P. Donahue" <dd******@ccs.n eu.edu> wrote in message
news:uc******** ******@TK2MSFTN GP15.phx.gbl...
If I have a DataGrid or DataList on a webpage with an ItemTemplate that
includes a button server control, how can I set it in the ItemTemplate so
that all the buttons populated in the grid/list will call a specified
function in my code-behind. Also, from that function, how can I access
the properties of the button that called it?
Regards,
David P. Donahue
dd******@ccs. neu.edu


Nov 16 '05 #3
I didn't even notice that both these threads were by the same person. I
just figured a coincidence that I was sending basically the same code twice
in one night. LOL

DalePres

"David P. Donahue" <dd******@ccs.n eu.edu> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
Perfect :) Casting the "sender" object to an ImageButton was precisely
what I needed to do. Thanks!
Regards,
David P. Donahue
dd******@ccs.ne u.edu

DalePres wrote:
Create the event handler for your button as follows, take note that the
accessibility of the method is set to protected and not to the usual
private setting.

protected void ButtonClick(obj ect sender, System.EventArg s e)

{

Response.Write( "Button: " + ((Button)sender ).ClientID + " was clicked!");

}

In your aspx file, where you declare the button in the item template,
include this in the button declaration tag:

ONCLICK="Button Click"
The ClientID property will return a value like "_ctl1_btn1 " for the first
button, "_ctl2_btn1 " for the second, and so on.

HTH

DalePres
MCAD, MCDBA, MCSE
"David P. Donahue" <dd******@ccs.n eu.edu> wrote in message
news:uc******** ******@TK2MSFTN GP15.phx.gbl...
If I have a DataGrid or DataList on a webpage with an ItemTemplate that
includes a button server control, how can I set it in the ItemTemplate so
that all the buttons populated in the grid/list will call a specified
function in my code-behind. Also, from that function, how can I access
the properties of the button that called it?
Regards,
David P. Donahue
dd******@ccs .neu.edu



Nov 16 '05 #4

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

Similar topics

2
1258
by: Jim Heavey | last post by:
I have 2 datalist each has 3 buttons in the datalist. One Datalist, only 2 of the three buttons work in the other one is dead (no postback, not nothing). I have another Datalist and on this one, all three buttons are dead (not postback, not nothing). To get a button to work on the DataList...here are the rules that I know of
3
2784
by: CVerma | last post by:
Hi, I have an embedded datagrid within a datalist. I am not able to perfrom paging in the datagrid. Any ideas? Here is my code: Here is my Simplegrid.cs file: using System; using System.Collections; using System.ComponentModel; using System.Data;
9
5066
by: tshad | last post by:
How do I find (and set) a couple of labels in the Footer after a DataGrid is filled? I have a bunch of DataGrids that get displayed nested inside a DataList. The datagrid looks like: ******************************************************************************* <asp:DataGrid visible="False" border=1
0
1703
by: Chris | last post by:
I've been searching all over and think I am close, but keep getting the error "Index out of range" when trying to reference a nested datagrid when an OnEditCommand event is raised. When the OnEditCommand event is raised, I try to do the following: 1. Find the selected datalist item in which the nested datagrid raised the event. (by calling getDataGridReference and returning the DataList's selectedIndex)
0
1092
by: Pugi! | last post by:
I am studying the book ASP.NET Data Web Controls. Very interesting, and I try to put everything in runtime (VB.NET) code instead of in the page. I got very far but now I am stuck. I found examples of how to create a TemplateColumn in a DataGrid with a hyperlink with two parameters at runtime (http://www.c-sharpcorner.com/Code/2003/June/AddItemTemplateDynamically.asp). But now I want to create a templatecolumn in a datalist with some...
8
10841
by: GaryDean | last post by:
I have a Wizard page and need to affect the next and previous buttons from my code-behind. I've googled around and found two solutions, and neither appear to work. I can access the SideBarList steps successfully with the following code... Control myContainer = (Control)Wizard1.FindControl("SideBarContainer"); DataList mySideBarList = (DataList)myContainer.FindControl("SideBarList");
1
1888
by: Brock | last post by:
First note that I am using Framework 1.1. I have an .aspx page that is displaying a list of employees, but only the Employee Number, First Name, Last Name, and Title. It is working great. I recessed it in a <Div></Divto allow scrolling of just the data, not the page. What I need to do is place a DataList (also in a <Div></Divto allow scrolling of just the data) to the right of the Datagrid to show 40 Employee Detail fields (listed top to...
1
1921
by: Brock | last post by:
Thanks in advance... (you can see a screenshot of what my form looks like currently at http://www.juggernautical.com/DataGrid.jpg - the Datalist is super-imposed in 'design view' but the DataGrid is the actual running of the page) I've almost got this working (?) but need a little help. I have an .aspx page that has a DataGrid listing employees with a "Select" button that is to be used to populate the DataList to the right of the DataGrid...
17
2555
lee123
by: lee123 | last post by:
I know this is a free site and the moderators or anybody don't have to answer if they don't want to.. but if there is someone who knows how to answer this question please help with this one. i have changed my project so many times to try to get the results i want but can't seem to get this one thing to work the datagrid and datalist to work right. i have looked on the web to see if i could do it another way. and read so many books but there...
0
9629
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10298
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10127
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9923
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6723
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5370
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5500
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4033
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2865
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.