473,414 Members | 1,776 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,414 software developers and data experts.

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.neu.edu
Nov 16 '05 #1
3 1230
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(object sender, System.EventArgs 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="ButtonClick"
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.neu.edu> wrote in message
news:uc**************@TK2MSFTNGP15.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 #2
Perfect :) Casting the "sender" object to an ImageButton was precisely
what I needed to do. Thanks!
Regards,
David P. Donahue
dd******@ccs.neu.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(object sender, System.EventArgs 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="ButtonClick"
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.neu.edu> wrote in message
news:uc**************@TK2MSFTNGP15.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.neu.edu> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Perfect :) Casting the "sender" object to an ImageButton was precisely
what I needed to do. Thanks!
Regards,
David P. Donahue
dd******@ccs.neu.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(object sender, System.EventArgs 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="ButtonClick"
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.neu.edu> wrote in message
news:uc**************@TK2MSFTNGP15.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
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...
3
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...
9
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: ...
0
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...
0
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...
8
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...
1
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...
1
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...
17
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
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...

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.