Home All Groups Group Topic Archive Search About

Adding "delete" functionality in DataGrid - without a ButtonColumn

Author
17 Feb 2005 1:15 AM
PK9
I have a datagrid that brings back a number of records and I want to allow
the user to click a "delete" button in each row of the datagrid to delete
records.  I originally used a <asp:ButtonColumn> for this and gave it a
CommandName attribute.  This worked great.  However, the client wants to have
a popup when they click on the delete button. 

So now I'm thinking that I have to create a javaScript function and instead
of using an <asp:ButtonColumn>, I'll have to use an <asp:TemplateColumn> with
an embedded <asp:button> inside of the item template.  In this button I'm
imagining I'll be able to do an onclick javascript event handler, but I'm not
sure how to do this.

I'm unsure how to create this type of functionality.   The important piece
is being able to pass the data for the entire row, from which the delete
button was clicked, to the javascript function.  This was easily done with
the button colum because the _ItemCommand event handler for the datagrid took
the input: DataGridCommandEventArgs, which had the data for the entire row. 

Any thoughts?  Your help is greatly appreciated.

--
PK9

Author
17 Feb 2005 2:12 AM
Elton Wang
You can still keep the delete button but change deleting
function to collect data and save data to SessionState.
Then popup delete page, Response.Write("<script>open
('delete.aspx')</script>"). In delete page, retrieve data
from SessionState.

HTH,

Elton Wang

>-----Original Message-----
>I have a datagrid that brings back a number of records
and I want to allow
>the user to click a "delete" button in each row of the
datagrid to delete
>records.  I originally used a <asp:ButtonColumn> for this
and gave it a
>CommandName attribute.  This worked great.  However, the
client wants to have
>a popup when they click on the delete button. 
>
>So now I'm thinking that I have to create a javaScript
function and instead
>of using an <asp:ButtonColumn>, I'll have to use an
<asp:TemplateColumn> with
>an embedded <asp:button> inside of the item template.  In
this button I'm
>imagining I'll be able to do an onclick javascript event
handler, but I'm not
>sure how to do this.
>
>I'm unsure how to create this type of functionality.  
The important piece
>is being able to pass the data for the entire row, from
which the delete
>button was clicked, to the javascript function.  This was
easily done with
>the button colum because the _ItemCommand event handler
for the datagrid took
>the input: DataGridCommandEventArgs, which had the data
for the entire row. 
Show quoteHide quote
>
>Any thoughts?  Your help is greatly appreciated.
>
>--
>PK9
>.
>
Author
17 Feb 2005 2:29 AM
PK9
That was my last option if I couldn't figure out another way.  I don't want
to deal with another aspx page and session variables.
I found my answer on the following website.  This shows examples to do it
with a buttoncolumn and an itemtemplate column!  Great reference!!!
http://authors.aspalliance.com/aldotnet/examples/cd.aspx

Show quoteHide quote
"Elton Wang" wrote:

> You can still keep the delete button but change deleting
> function to collect data and save data to SessionState.
> Then popup delete page, Response.Write("<script>open
> ('delete.aspx')</script>"). In delete page, retrieve data
> from SessionState.
>
> HTH,
>
> Elton Wang
>
> >-----Original Message-----
> >I have a datagrid that brings back a number of records
> and I want to allow
> >the user to click a "delete" button in each row of the
> datagrid to delete
> >records.  I originally used a <asp:ButtonColumn> for this
> and gave it a
> >CommandName attribute.  This worked great.  However, the
> client wants to have
> >a popup when they click on the delete button. 
> >
> >So now I'm thinking that I have to create a javaScript
> function and instead
> >of using an <asp:ButtonColumn>, I'll have to use an
> <asp:TemplateColumn> with
> >an embedded <asp:button> inside of the item template.  In
> this button I'm
> >imagining I'll be able to do an onclick javascript event
> handler, but I'm not
> >sure how to do this.
> >
> >I'm unsure how to create this type of functionality.  
> The important piece
> >is being able to pass the data for the entire row, from
> which the delete
> >button was clicked, to the javascript function.  This was
> easily done with
> >the button colum because the _ItemCommand event handler
> for the datagrid took
> >the input: DataGridCommandEventArgs, which had the data
> for the entire row. 
> >
> >Any thoughts?  Your help is greatly appreciated.
> >
> >--
> >PK9
> >.
> >
>
Author
17 Feb 2005 2:40 AM
Elton Wang
So actually, you want a deleting confirmation.

Elton Wang

>-----Original Message-----
>That was my last option if I couldn't figure out another
way.  I don't want
>to deal with another aspx page and session variables.
>I found my answer on the following website.  This shows
examples to do it
Show quoteHide quote
>with a buttoncolumn and an itemtemplate column!  Great
reference!!!
>http://authors.aspalliance.com/aldotnet/examples/cd.aspx
>
>"Elton Wang" wrote:
>
>> You can still keep the delete button but change
deleting
>> function to collect data and save data to SessionState.
>> Then popup delete page, Response.Write("<script>open
>> ('delete.aspx')</script>"). In delete page, retrieve
data
>> from SessionState.
>>
>> HTH,
>>
>> Elton Wang
>>
>> >-----Original Message-----
>> >I have a datagrid that brings back a number of records
>> and I want to allow
>> >the user to click a "delete" button in each row of the
>> datagrid to delete
>> >records.  I originally used a <asp:ButtonColumn> for
this
>> and gave it a
>> >CommandName attribute.  This worked great.  However,
the
>> client wants to have
>> >a popup when they click on the delete button. 
>> >
>> >So now I'm thinking that I have to create a javaScript
>> function and instead
>> >of using an <asp:ButtonColumn>, I'll have to use an
>> <asp:TemplateColumn> with
>> >an embedded <asp:button> inside of the item template. 
In
>> this button I'm
>> >imagining I'll be able to do an onclick javascript
event
>> handler, but I'm not
>> >sure how to do this.
>> >
>> >I'm unsure how to create this type of functionality.  
>> The important piece
>> >is being able to pass the data for the entire row,
from
>> which the delete
>> >button was clicked, to the javascript function.  This
was
>> easily done with
>> >the button colum because the _ItemCommand event
handler
>> for the datagrid took
>> >the input: DataGridCommandEventArgs, which had the
data
>> for the entire row. 
>> >
>> >Any thoughts?  Your help is greatly appreciated.
>> >
>> >--
>> >PK9
>> >.
>> >
>>
>.
>
Author
17 Feb 2005 3:33 AM
PK9
Yes, sorry if I was unclear.  That's what I was referring to when I said a
javaScript popup when the user clicks on the delete button.

Thanks,
Paul

Show quoteHide quote
"Elton Wang" wrote:

> So actually, you want a deleting confirmation.
>
> Elton Wang
>
> >-----Original Message-----
> >That was my last option if I couldn't figure out another
> way.  I don't want
> >to deal with another aspx page and session variables.
> >I found my answer on the following website.  This shows
> examples to do it
> >with a buttoncolumn and an itemtemplate column!  Great
> reference!!!
> >http://authors.aspalliance.com/aldotnet/examples/cd.aspx
> >
> >"Elton Wang" wrote:
> >
> >> You can still keep the delete button but change
> deleting
> >> function to collect data and save data to SessionState.
> >> Then popup delete page, Response.Write("<script>open
> >> ('delete.aspx')</script>"). In delete page, retrieve
> data
> >> from SessionState.
> >>
> >> HTH,
> >>
> >> Elton Wang
> >>
> >> >-----Original Message-----
> >> >I have a datagrid that brings back a number of records
> >> and I want to allow
> >> >the user to click a "delete" button in each row of the
> >> datagrid to delete
> >> >records.  I originally used a <asp:ButtonColumn> for
> this
> >> and gave it a
> >> >CommandName attribute.  This worked great.  However,
> the
> >> client wants to have
> >> >a popup when they click on the delete button. 
> >> >
> >> >So now I'm thinking that I have to create a javaScript
> >> function and instead
> >> >of using an <asp:ButtonColumn>, I'll have to use an
> >> <asp:TemplateColumn> with
> >> >an embedded <asp:button> inside of the item template. 
> In
> >> this button I'm
> >> >imagining I'll be able to do an onclick javascript
> event
> >> handler, but I'm not
> >> >sure how to do this.
> >> >
> >> >I'm unsure how to create this type of functionality.  
> >> The important piece
> >> >is being able to pass the data for the entire row,
> from
> >> which the delete
> >> >button was clicked, to the javascript function.  This
> was
> >> easily done with
> >> >the button colum because the _ItemCommand event
> handler
> >> for the datagrid took
> >> >the input: DataGridCommandEventArgs, which had the
> data
> >> for the entire row. 
> >> >
> >> >Any thoughts?  Your help is greatly appreciated.
> >> >
> >> >--
> >> >PK9
> >> >.
> >> >
> >>
> >.
> >
>
Author
17 Feb 2005 2:41 PM
Elton Wang
If that, you don't have to change from ButtonColumn to
ItemTemplate + button.

Suppose your delete button (ButtonColumn) is the first
column in the datagrid, just add some code in
datagrid_ItemCreated event:

switch (e.Item.ItemType)
{
    case ListItemType.Header:
    case ListItemType.Footer:
    case ListItemType.Separator:
    case ListItemType.Pager:
         return;
    default:
             break;
}
LinkButton btn = (LinkButton)e.Item.Cells(0).Controls(0);
btn.Attributes.Add("OnClick", "confirm('Are you sure you
want to delete this record?');")

That's it.

HTH,

Elton Wang

>-----Original Message-----
>Yes, sorry if I was unclear.  That's what I was referring
to when I said a
Show quoteHide quote
>javaScript popup when the user clicks on the delete
button.
>
>Thanks,
>Paul
>
>"Elton Wang" wrote:
>
>> So actually, you want a deleting confirmation.
>>
>> Elton Wang
>>
>> >-----Original Message-----
>> >That was my last option if I couldn't figure out
another
>> way.  I don't want
>> >to deal with another aspx page and session variables.
>> >I found my answer on the following website.  This
shows
>> examples to do it
>> >with a buttoncolumn and an itemtemplate column!  Great
>> reference!!!
>>
>http://authors.aspalliance.com/aldotnet/examples/cd.aspx
>> >
>> >"Elton Wang" wrote:
>> >
>> >> You can still keep the delete button but change
>> deleting
>> >> function to collect data and save data to
SessionState.
>> >> Then popup delete page, Response.Write("<script>open
>> >> ('delete.aspx')</script>"). In delete page, retrieve
>> data
>> >> from SessionState.
>> >>
>> >> HTH,
>> >>
>> >> Elton Wang
>> >>
>> >> >-----Original Message-----
>> >> >I have a datagrid that brings back a number of
records
>> >> and I want to allow
>> >> >the user to click a "delete" button in each row of
the
>> >> datagrid to delete
>> >> >records.  I originally used a <asp:ButtonColumn>
for
>> this
>> >> and gave it a
>> >> >CommandName attribute.  This worked great. 
However,
>> the
>> >> client wants to have
>> >> >a popup when they click on the delete button. 
>> >> >
>> >> >So now I'm thinking that I have to create a
javaScript
>> >> function and instead
>> >> >of using an <asp:ButtonColumn>, I'll have to use an
>> >> <asp:TemplateColumn> with
>> >> >an embedded <asp:button> inside of the item
template. 
>> In
>> >> this button I'm
>> >> >imagining I'll be able to do an onclick javascript
>> event
>> >> handler, but I'm not
>> >> >sure how to do this.
>> >> >
>> >> >I'm unsure how to create this type of
functionality.  
Show quoteHide quote
>> >> The important piece
>> >> >is being able to pass the data for the entire row,
>> from
>> >> which the delete
>> >> >button was clicked, to the javascript function. 
This
>> was
>> >> easily done with
>> >> >the button colum because the _ItemCommand event
>> handler
>> >> for the datagrid took
>> >> >the input: DataGridCommandEventArgs, which had the
>> data
>> >> for the entire row. 
>> >> >
>> >> >Any thoughts?  Your help is greatly appreciated.
>> >> >
>> >> >--
>> >> >PK9
>> >> >.
>> >> >
>> >>
>> >.
>> >
>>
>.
>