link data grid edit button

  • Thread starter Yunus Emre ALPÖZEN [MCAD.NET]
  • Start date
Y

Yunus Emre ALPÖZEN [MCAD.NET]

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);
}
}
}
 
J

John M

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 :)
 
J

John M

.... and how can I make a web-control library (file - > new ??? ... )

Thanks :)

Yunus Emre ALPÖZEN said:
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 said:
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 :)
 
E

Elton W

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
(e-mail address removed)
 
Y

Yunus Emre ALPÖZEN [MCAD.NET]

New Web Control Library

--

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

John M said:
... and how can I make a web-control library (file - > new ??? ... )

Thanks :)

Yunus Emre ALPÖZEN said:
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 said:
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 :)
 
G

Guest

Could you show your html code of datagrid?

Elton

John M said:
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 said:
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
(e-mail address removed)



-----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 :)



.
 
J

John M

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 said:
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
(e-mail address removed)



-----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 :)



.
 
G

Guest

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
 
J

John M

Elton W said:
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 :)
 
J

John M

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 :)
 
J

John M

did you mean : new web user control ?

Thanks :)

Yunus Emre ALPÖZEN said:
New Web Control Library

--

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

John M said:
... and how can I make a web-control library (file - > new ??? ... )

Thanks :)

Yunus Emre ALPÖZEN said:
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

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 :)
 
J

John M

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 :)
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top