473,403 Members | 2,366 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,403 software developers and data experts.

link data grid edit button

Hello,

In Visual studio .NET 2003,

On datagrid object :
How can I link the button element : edit, to do a some client events (such
as message box,
and do another event just after that to the server (do some manipulation on
the database).

If I cannot - how can I do that anyway in some tricky way ?

Thanks :)

Nov 19 '05 #1
13 1393
There is no limit in programming:)))

Create a web control library named as MyControlLibrary and following code...
And use this control in anywhere... Feel free to built on something on
this....

using System;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace MyControlLibrary
{
[System.ComponentModel.DefaultProperty("Text"),
ToolboxData("<{0}:MyLinkButton runat=server></{0}:MyLinkButton>")]
public class MyLinkButton : System.Web.UI.WebControls.LinkButton
{
string question="?";
[System.ComponentModel.Bindable(true)]
public String Question
{
get
{
return question;
}
set
{
question="";
}
}
protected override void Render(HtmlTextWriter output)
{
Attributes.Add("onClick",String.Format("javascript :return
confirm('{0}')",Question));
base.Render(output);
}
}
}
--

Thanks,
Yunus Emre ALPÖZEN
BSc, MCAD.NET

"John M" <nobody@nospam_please.com> wrote in message
news:OR**************@TK2MSFTNGP15.phx.gbl...
Hello,

In Visual studio .NET 2003,

On datagrid object :
How can I link the button element : edit, to do a some client events (such
as message box,
and do another event just after that to the server (do some manipulation
on
the database).

If I cannot - how can I do that anyway in some tricky way ?

Thanks :)

Nov 19 '05 #2
.... and how can I make a web-control library (file - > new ??? ... )

Thanks :)

"Yunus Emre ALPÖZEN [MCAD.NET]" <ye***@msakademik.net> wrote in message
news:eB**************@TK2MSFTNGP09.phx.gbl...
There is no limit in programming:)))

Create a web control library named as MyControlLibrary and following
code... And use this control in anywhere... Feel free to built on
something on this....

using System;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace MyControlLibrary
{
[System.ComponentModel.DefaultProperty("Text"),
ToolboxData("<{0}:MyLinkButton runat=server></{0}:MyLinkButton>")]
public class MyLinkButton : System.Web.UI.WebControls.LinkButton
{
string question="?";
[System.ComponentModel.Bindable(true)]
public String Question
{
get
{
return question;
}
set
{
question="";
}
}
protected override void Render(HtmlTextWriter output)
{
Attributes.Add("onClick",String.Format("javascript :return
confirm('{0}')",Question));
base.Render(output);
}
}
}
--

Thanks,
Yunus Emre ALPÖZEN
BSc, MCAD.NET

"John M" <nobody@nospam_please.com> wrote in message
news:OR**************@TK2MSFTNGP15.phx.gbl...
Hello,

In Visual studio .NET 2003,

On datagrid object :
How can I link the button element : edit, to do a some client events
(such
as message box,
and do another event just after that to the server (do some manipulation
on
the database).

If I cannot - how can I do that anyway in some tricky way ?

Thanks :)


Nov 19 '05 #3
Hi John,

You can use buttonObject.Attributes.Add method add client-
side javascript method. Following code snippet shows how
to add client-side message box code:

Suppose you have EditCommandColumn as the first column of
the datagrid. In datagrid_ItemDataBound event:

if (e.Item.ItemType == ListItemType.Item ||
e.Item.ItemType == ListItemType.AlternatingItem )
{
LinkButton editBtn = (LinkButton)e.Item.Cells
[0].Controls[0];
editBtn.Attributes.Add("Onclick","alert('Edit
Message');");
}

HTH

Elton Wang
el********@hotmail.com

-----Original Message-----
Hello,

In Visual studio .NET 2003,

On datagrid object :
How can I link the button element : edit, to do a some client events (suchas message box,
and do another event just after that to the server (do some manipulation onthe database).

If I cannot - how can I do that anyway in some tricky way ?
Thanks :)

.

Nov 19 '05 #4
New Web Control Library

--

Thanks,
Yunus Emre ALPÖZEN
BSc, MCAD.NET

"John M" <nobody@nospam_please.com> wrote in message
news:OA**************@TK2MSFTNGP14.phx.gbl...
... and how can I make a web-control library (file - > new ??? ... )

Thanks :)

"Yunus Emre ALPÖZEN [MCAD.NET]" <ye***@msakademik.net> wrote in message
news:eB**************@TK2MSFTNGP09.phx.gbl...
There is no limit in programming:)))

Create a web control library named as MyControlLibrary and following
code... And use this control in anywhere... Feel free to built on
something on this....

using System;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace MyControlLibrary
{
[System.ComponentModel.DefaultProperty("Text"),
ToolboxData("<{0}:MyLinkButton runat=server></{0}:MyLinkButton>")]
public class MyLinkButton : System.Web.UI.WebControls.LinkButton
{
string question="?";
[System.ComponentModel.Bindable(true)]
public String Question
{
get
{
return question;
}
set
{
question="";
}
}
protected override void Render(HtmlTextWriter output)
{
Attributes.Add("onClick",String.Format("javascript :return
confirm('{0}')",Question));
base.Render(output);
}
}
}
--

Thanks,
Yunus Emre ALPÖZEN
BSc, MCAD.NET

"John M" <nobody@nospam_please.com> wrote in message
news:OR**************@TK2MSFTNGP15.phx.gbl...
Hello,

In Visual studio .NET 2003,

On datagrid object :
How can I link the button element : edit, to do a some client events
(such
as message box,
and do another event just after that to the server (do some manipulation
on
the database).

If I cannot - how can I do that anyway in some tricky way ?

Thanks :)



Nov 19 '05 #5
Good,

I have tried the following vb code,
but (I have three columns, one is the "edit").
cn.controls.count is always 0
(I have tried to change e.item.cell(0), e.item.cell(1), e.item.cell(2) )

So I didn't manage running the code.

Thanks :)

Dim editBtn As LinkButton
Dim cn As Control
Dim c As TableCell
If e.Item.ItemType = ListItemType.Item Or ListItemType.AlternatingItem Then
c = e.Item.Cells(0)
cn = c
editBtn = cn.Controls(0)
editBtn.Attributes.Add("Onclick", "Alert('Edit Message')")
End If

"Elton W" <an*******@discussions.microsoft.com> wrote in message
news:1c****************************@phx.gbl...
Hi John,

You can use buttonObject.Attributes.Add method add client-
side javascript method. Following code snippet shows how
to add client-side message box code:

Suppose you have EditCommandColumn as the first column of
the datagrid. In datagrid_ItemDataBound event:

if (e.Item.ItemType == ListItemType.Item ||
e.Item.ItemType == ListItemType.AlternatingItem )
{
LinkButton editBtn = (LinkButton)e.Item.Cells
[0].Controls[0];
editBtn.Attributes.Add("Onclick","alert('Edit
Message');");
}

HTH

Elton Wang
el********@hotmail.com

-----Original Message-----
Hello,

In Visual studio .NET 2003,

On datagrid object :
How can I link the button element : edit, to do a some

client events (such
as message box,
and do another event just after that to the server (do

some manipulation on
the database).

If I cannot - how can I do that anyway in some tricky

way ?

Thanks :)

.

Nov 19 '05 #6
Could you show your html code of datagrid?

Elton

"John M" wrote:
Good,

I have tried the following vb code,
but (I have three columns, one is the "edit").
cn.controls.count is always 0
(I have tried to change e.item.cell(0), e.item.cell(1), e.item.cell(2) )

So I didn't manage running the code.

Thanks :)

Dim editBtn As LinkButton
Dim cn As Control
Dim c As TableCell
If e.Item.ItemType = ListItemType.Item Or ListItemType.AlternatingItem Then
c = e.Item.Cells(0)
cn = c
editBtn = cn.Controls(0)
editBtn.Attributes.Add("Onclick", "Alert('Edit Message')")
End If

"Elton W" <an*******@discussions.microsoft.com> wrote in message
news:1c****************************@phx.gbl...
Hi John,

You can use buttonObject.Attributes.Add method add client-
side javascript method. Following code snippet shows how
to add client-side message box code:

Suppose you have EditCommandColumn as the first column of
the datagrid. In datagrid_ItemDataBound event:

if (e.Item.ItemType == ListItemType.Item ||
e.Item.ItemType == ListItemType.AlternatingItem )
{
LinkButton editBtn = (LinkButton)e.Item.Cells
[0].Controls[0];
editBtn.Attributes.Add("Onclick","alert('Edit
Message');");
}

HTH

Elton Wang
el********@hotmail.com

-----Original Message-----
Hello,

In Visual studio .NET 2003,

On datagrid object :
How can I link the button element : edit, to do a some

client events (such
as message box,
and do another event just after that to the server (do

some manipulation on
the database).

If I cannot - how can I do that anyway in some tricky

way ?

Thanks :)

.


Nov 19 '05 #7
Sorry. I can't find attachment.

"John M" wrote:

See as attached file.

Thanks :)

Nov 19 '05 #8
Hi John,

I suppose index = 2 should work. Anyway, try foolowing code:

Dim editBtn As LinkButton
If e.Item.ItemType = ListItemType.Item OrElse ListItemType.AlternatingItem
Then
editBtn = CType(e.Item.Cells(2).Controls(0), LinkButton)
editBtn.Attributes.Add("Onclick", "Alert('Edit Message')")
End If

HTH

Elton
"John M" wrote:

"Elton W" <El****@discussions.microsoft.com> wrote in message
news:36**********************************@microsof t.com...
Sorry. I can't find attachment.


Maybe your outlook express block the attachment.
Here is again.

Here is the code, as follows :
Thanks :)
----------------------------------------

<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm1.aspx.vb"
Inherits="WebApplication1.WebForm1" debug="False"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm1</title>
<meta content="False" name="vs_showGrid">
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
</HEAD>
<body bgColor="#ffccff" MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">

<asp:datagrid id="DataGrid1" style="Z-INDEX: 105; LEFT: 488px; POSITION:
absolute; TOP: 40px"
runat="server" HorizontalAlign="Left" ShowFooter="True" CellSpacing="2"
CellPadding="3" BorderWidth="1px"
BorderStyle="None" AutoGenerateColumns="False" Caption="a list"
BorderColor="#C0FFC0" BackColor="#FFFFC0"
AllowPaging="True">
<FooterStyle ForeColor="#8C4510" BackColor="#F7DFB5"></FooterStyle>
<SelectedItemStyle Font-Bold="True" Wrap="False" ForeColor="White"
BackColor="#738A9C"></SelectedItemStyle>
<ItemStyle Wrap="False" HorizontalAlign="Right" ForeColor="#8C4510"
BackColor="#FFF7E7"></ItemStyle>
<HeaderStyle Font-Bold="True" HorizontalAlign="Right" ForeColor="White"
BackColor="#A55129"></HeaderStyle>
<Columns>
<asp:BoundColumn DataField="firstname" HeaderText="first name">
<HeaderStyle Wrap="False" HorizontalAlign="Right"
Width="0px"></HeaderStyle>
<ItemStyle Wrap="False" HorizontalAlign="Right"></ItemStyle>
<FooterStyle Wrap="False" HorizontalAlign="Right"></FooterStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="lastname" HeaderText="last name">
<HeaderStyle Wrap="False" Width="0px"></HeaderStyle>
<ItemStyle Wrap="False"></ItemStyle>
</asp:BoundColumn>
<asp:EditCommandColumn ButtonType="LinkButton" UpdateText="update"
CancelText="cancel" EditText="delete">
<HeaderStyle Wrap="False" Width="0px"></HeaderStyle>
<ItemStyle Wrap="False"></ItemStyle>
<FooterStyle Wrap="False"></FooterStyle>
</asp:EditCommandColumn>
</Columns>
<PagerStyle HorizontalAlign="Center" ForeColor="#8C4510"
Mode="NumericPages"></PagerStyle>
</asp:datagrid></form>
</body>
</HTML>

Nov 19 '05 #9

"Elton W" <El****@discussions.microsoft.com> wrote in message
news:78**********************************@microsof t.com...
Hi John,

I suppose index = 2 should work. Anyway, try foolowing code:

Dim editBtn As LinkButton
If e.Item.ItemType = ListItemType.Item OrElse ListItemType.AlternatingItem
Then
editBtn = CType(e.Item.Cells(2).Controls(0), LinkButton)
editBtn.Attributes.Add("Onclick", "Alert('Edit Message')")
End If

HTH

Elton
"John M" wrote:

I did as your advise.

Still,
controls.count is 0,
so the code run of exception outofrange.
(Maybe not "controls", but something else).

Thanks :)
Nov 19 '05 #10
Ignore the last,

I found it (itemIndex = -1, and that's why controls.count = 0),
so I add in the code :
If e.Item.ItemIndex <> -1 Then ...

Another thing is that I see that the page is refreshing (page_load event
occurs),
but the command editBtn.Attributes.Add("Onclick", "Alert('Edit Message')")
is not doing anything.
(There is no message box).
Why ?

Thanks :)
Nov 19 '05 #11
did you mean : new web user control ?

Thanks :)

"Yunus Emre ALPÖZEN [MCAD.NET]" <ye***@msakademik.net> wrote in message
news:e%****************@TK2MSFTNGP10.phx.gbl...
New Web Control Library

--

Thanks,
Yunus Emre ALPÖZEN
BSc, MCAD.NET

"John M" <nobody@nospam_please.com> wrote in message
news:OA**************@TK2MSFTNGP14.phx.gbl...
... and how can I make a web-control library (file - > new ??? ... )

Thanks :)

"Yunus Emre ALPÖZEN [MCAD.NET]" <ye***@msakademik.net> wrote in message
news:eB**************@TK2MSFTNGP09.phx.gbl...
There is no limit in programming:)))

Create a web control library named as MyControlLibrary and following
code... And use this control in anywhere... Feel free to built on
something on this....

using System;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace MyControlLibrary
{
[System.ComponentModel.DefaultProperty("Text"),
ToolboxData("<{0}:MyLinkButton runat=server></{0}:MyLinkButton>")]
public class MyLinkButton : System.Web.UI.WebControls.LinkButton
{
string question="?";
[System.ComponentModel.Bindable(true)]
public String Question
{
get
{
return question;
}
set
{
question="";
}
}
protected override void Render(HtmlTextWriter output)
{
Attributes.Add("onClick",String.Format("javascript :return
confirm('{0}')",Question));
base.Render(output);
}
}
}
--

Thanks,
Yunus Emre ALPÖZEN
BSc, MCAD.NET

"John M" <nobody@nospam_please.com> wrote in message
news:OR**************@TK2MSFTNGP15.phx.gbl...
Hello,

In Visual studio .NET 2003,

On datagrid object :
How can I link the button element : edit, to do a some client events
(such
as message box,
and do another event just after that to the server (do some
manipulation on
the database).

If I cannot - how can I do that anyway in some tricky way ?

Thanks :)




Nov 19 '05 #12
Thank you Elton W.
Thank you Yunus Emre.

I combine your both replies :
The line I correct is :
editBtn.Attributes.Add("onclick", String.Format("alert(""abc"")"))

(Adding string.format ...)

(The another thing is that page need to reload on every click)

But now Everything works fine ...
Thanks :)
Nov 19 '05 #13
itemIndex = -1 means ListItemType.Header.

So you have to use

If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType =
ListItemType.Item = ListItemType.AlternatingItem Then

rather than

If e.Item.ItemType = ListItemType.Item OrElse ListItemType.AlternatingItem
Then

That condition will bypass Header, Footer, Separator, Pager items.

HTH

Elton



"John M" wrote:
Ignore the last,

I found it (itemIndex = -1, and that's why controls.count = 0),
so I add in the code :
If e.Item.ItemIndex <> -1 Then ...

Another thing is that I see that the page is refreshing (page_load event
occurs),
but the command editBtn.Attributes.Add("Onclick", "Alert('Edit Message')")
is not doing anything.
(There is no message box).
Why ?

Thanks :)

Nov 19 '05 #14

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

Similar topics

3
by: pmud | last post by:
Hi, I have a web page (asp.net, code:c#). I havean html table with text boxes. Based on the user input , records are displayed in the data grid below it. Now the datagrid has a large no. of...
5
by: tshad | last post by:
Is there a way to carry data that I have already read from the datagrid from page to page? I am looking at my Datagrid that I page through and when the user says get the next page, I have to go...
2
by: Remy | last post by:
Hi I would like to put a link into the Footer of the first column of an ASP.NET 2.0 GridView. By first column I mean the column where it normally displayes the Edit and Delete link. I've built...
10
by: Corey B | last post by:
I have a data grid that has three columns: First Name, Middle Name, and Last Name. The grid has a list of people with a blank row at the bottom of the grid (in the footer) that allows the user to...
0
by: anwarulhuq | last post by:
I have placed Edit-Update-Cancel Link button from Properties builder of the Data Grid. Its working but the problem what im facing is.. It doesnt work till i click for two times. Link button should...
2
by: Bazza Formez | last post by:
Hello, In my aspx file I have a LinkButton inside a template column, inside a datagrid. I have assigned a CommandName to the button. In my code behind, I attempt to trap the command in the...
3
by: kevinpublic | last post by:
I have an item list for ordered products on a data grid in VS 2003. It's an ASP page running VB behind it. All detail lines display as well as all shipping charges. On the edit screen, we allow...
1
by: rktester | last post by:
Hi, I am trying to implement an editable datagrid in .net 2005 This is how my grid is defined: <asp:DataGrid runat="server" id="dgUser" Font-Name="Verdana" Font-Size="9pt"...
0
by: ravindarjobs | last post by:
hello friends, i am using vb6. i am using a datagrid on my form. i am showing a table data in that grid. i have enabled the grid property " allow to add new rows" and" allow edit" here are my...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
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...
0
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...
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...

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.