Saturday, March 24, 2012

confirm button extender in a datagrid

Hi all,

Quick Question.

How can you use a confirm button extender in a datagrid?

So if you have a datagrid with 10 rows, each with a delete link button at the end and you want the confirm dialouge to popup everytime you click on any of the 10 delete link buttons. How do you do it?

Thanks in advance.

Use the rowdatabound event to add an attribue to thelinkbutton("DELETE"), assuming the linkbutton is in the first column ofthe gridview:


If e.Row.RowType = DataControlRowType.DataRowThen
Dim lbAs LinkButton
lb = e.Row.Cells(0).Controls(0)
lb.Attributes.Add("onclick", "javascript:return confirm('Are you sure you want to delete this row?');")
End If
OnClientClick="return confirm('Are you sure you want to delete
this item?');"

However,to make that work, you'll need to convert the Delete button into aTemplate field. The following post gives more details about this:

http://p2p.wrox.com/topic.asp?TOPIC_ID=45586

cheers


Thanks,

I allready have that. I allready have a javascript confirm dialouge.

I wanted to use the confirm button exetender in the ajax tool kit. I know its exactly the same, but i thought i would try the "new thing".

Thanks for your response though.


Just add a confirmbuttonextender in the template for the column so that one gets created for every row of the grid.

i did this...

<

asp:GridViewID="grvReservas"runat="server"CellPadding="4"GridLines="None"Height="81px"Style="z-index: 115; left: 58px; position: absolute; top: 328px"Width="691px"OnRowDeleting="grvReservas_RowDeleting"OnSelectedIndexChanged="grvReservas_SelectedIndexChanged"ForeColor="#333333"><FooterStyleBackColor="#507CD1"ForeColor="White"Font-Bold="True"/><RowStyleBackColor="#EFF3FB"/><SelectedRowStyleBackColor="#D1DDF1"Font-Bold="True"ForeColor="#333333"/><PagerStyleBackColor="#2461BF"ForeColor="White"HorizontalAlign="Center"/><HeaderStyleBackColor="#507CD1"Font-Bold="True"ForeColor="White"/><AlternatingRowStyleBackColor="White"/><Columns><asp:CommandFieldShowDeleteButton="True"/><asp:TemplateField><ItemTemplate><asp:ImageButtonID="ImageButtonDelete"runat="server"CausesValidation="false"CommandName="ImageButtonDelete"ImageUrl="../images/eliminar.jpg"OnClick="ImageButtonDelete_Click"Visible="true"/><cc1:ConfirmButtonExtenderID="ConfirmButtonExtender1"runat="server"ConfirmText="?Esta seguro que desea cancelar la reserva seleccionada?"TargetControlID="ImageButtonDelete"></cc1:ConfirmButtonExtender></ItemTemplate></asp:TemplateField><asp:ImageField></asp:ImageField></Columns><EditRowStyleBackColor="#2461BF"/>

</asp:GridView>

but in ImageButtonDelete_Click method, how do i know which row is selected?????


You could add a commandargument to the imagebutton with some kind of ID value that identifies the data that you want to delete.
how can i add a commandargument to the imagebutton with the ID value ?

Hookup to the rowdatabound event of the gridview and then set the property in there.

No comments:

Post a Comment