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

How to add imageButtons to DataGrid?

I am dynamically creating my datagrid, building each column in real-time via
code-behind (using c#).

The only way i have read to add ImageButtons to my grid dynamically is by
creating a separate template class. However, a class cannot create server
controls (or at least this is beyond me).

I am able to create HTML <INPUT> form elements, however, these are not wired
to my datagrid and hence, when clicked do not fire the datagrid's events
including ItemCommand.

Is there anyway to add imageButtons as web server controls to the datagrid
dynamically?

Thanks,
Nov 19 '05 #1
2 1943
Forgive my last comment: I can add ImageButton's as web server controls via
my template class. However, how do i wire these controls to my datagrid so
that when clicked they fire the ItemCommand event?

"charliewest" wrote:
I am dynamically creating my datagrid, building each column in real-time via
code-behind (using c#).

The only way i have read to add ImageButtons to my grid dynamically is by
creating a separate template class. However, a class cannot create server
controls (or at least this is beyond me).

I am able to create HTML <INPUT> form elements, however, these are not wired
to my datagrid and hence, when clicked do not fire the datagrid's events
including ItemCommand.

Is there anyway to add imageButtons as web server controls to the datagrid
dynamically?

Thanks,

Nov 19 '05 #2
Here is a sample that adds 2 image buttons for edit and delete.
The delete is wrapped in a client side confirmation dialog.

Add this to the asp:datagrid section:
OnItemCommand="GetRowInfo"
<ASP:TEMPLATECOLUMN HeaderText="Actions">
<HEADERSTYLE CssClass="DataGridRowTitleCenter"></HEADERSTYLE>
<ITEMSTYLE CssClass="DataGridCellCenter"></ITEMSTYLE>
<ITEMTEMPLATE>
<ASP:IMAGEBUTTON id="btnEdit" runat="server" ToolTip="Edit"
ImageUrl="~/img/edit.gif" CommandName="btnEdit"></ASP:IMAGEBUTTON>
<SPAN onclick="return confirm('Do you really want to delete
this record from the system?')">
<ASP:IMAGEBUTTON id="btnDelete" runat="server"
ToolTip="Delete" ImageUrl="~/img/delete.gif"
CommandName="btnDelete"></ASP:IMAGEBUTTON>
</SPAN>
</ITEMTEMPLATE>
</ASP:TEMPLATECOLUMN>
Then in your code behind create a method with the same name as defined in
OnItemCommand:
Protected Sub GetRowInfo(ByVal source As Object, ByVal e As
DataGridCommandEventArgs)
'Grid paging causes this event to fire and e.Item.ItemIndex=-1 so we
should avoid an error by coding for this case.
If e.Item.ItemIndex >= 0 Then

Dim mIndex As Integer = CType(source, DataGrid).PageSize *
CType(source, DataGrid).CurrentPageIndex + e.Item.ItemIndex

If e.CommandName = "btnDelete" Then
Dim mKey As String = mList(mIndex).code

'after deleting the record, re-load the page.
Response.Redirect("~/Results.aspx")

ElseIf e.CommandName = "btnEdit" Then
'do something here
Response.Redirect("~/Edit.aspx")
End If

End If

End Sub

--
Joe Fallon


"charliewest" <ch*********@discussions.microsoft.com> wrote in message
news:0D**********************************@microsof t.com...
Forgive my last comment: I can add ImageButton's as web server controls
via
my template class. However, how do i wire these controls to my datagrid so
that when clicked they fire the ItemCommand event?

"charliewest" wrote:
I am dynamically creating my datagrid, building each column in real-time
via
code-behind (using c#).

The only way i have read to add ImageButtons to my grid dynamically is by
creating a separate template class. However, a class cannot create server
controls (or at least this is beyond me).

I am able to create HTML <INPUT> form elements, however, these are not
wired
to my datagrid and hence, when clicked do not fire the datagrid's events
including ItemCommand.

Is there anyway to add imageButtons as web server controls to the
datagrid
dynamically?

Thanks,

Nov 19 '05 #3

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

Similar topics

2
by: Martin | last post by:
Hi, I want to use Imagebuttons () to submit a form, as following: <form ....> <Input name="buttonEdit" type=Image onclick="ActionHandle("2")> <Input name="buttonnew" type=Image ...
3
by: David P. Donahue | last post by:
This is a 2-part question: 1) I have a web form with multiple ImageButtons on it. I'd like them all to do the same thing. Basically, in english-code, the function would be as follows: Set...
1
by: Rick | last post by:
Hello all, I hope all is well with you. I am having a seriously difficult time with this problem. Allow me to set up the problem. I have a System.Web.UI.Page with the following controls...
2
by: flyAway | last post by:
HI In my first asp.Net Homepage I have the following problem: There are some ImageButtons, witch ImageURL constantly changes. Now I would like to create an array, so that I can assign the...
3
by: martin | last post by:
I have a page with a imagebuttons on it - works fine on my dev machien IIS5 I ahve deployed to test server IIS6 and button does not fire at all in IE. It has rendered a html input tag. I open...
5
by: Varangian | last post by:
ImageButton ship; ship = new ImageButton; for (int i=0; i<5; i++) { ship.ImageUrl = pathofImage; ship.ID = "ShipNo" + i.ToString(); ship.Click += new...
1
by: graphicsxp | last post by:
Hi, I have a few ImageButton controls on my form. One of them is the save one, on which I want the form to be submited. Other imageButtons trigger a postback, but they should not cause form...
6
by: rcoco | last post by:
Hi everyone, I'm using smilies in a datagrid so that when a user selects one smiley it is installed into sqlserver how could i go about this? The smiley is an ImageButton. Thanks
0
by: Gileno | last post by:
Hi! I Have a gridView with a TemplateField, with this code: <asp:TemplateField> <ItemTemplate> <img alt="Editar" src="./imagens/icon_editar.gif" /> <%#...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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
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,...
0
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...

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.