Adding a confirmation pop when a row with a radio button is selected to be deleted

S

Samy

Hi There,
I have a label in a datagrid which I make it a input type = radio in
ItemDataBound so that radio buttons are shown in the datagrid.
This is how I have it...

ASPX...
<asp:Label ID="_selectedRBtn" Runat="server"></asp:Label>

ASPX.CS

Label _selectedProfile = (Label)
e.Item.Cells[0].FindControl("_selectedRBtn");
_selectedProfile.Text = "<input type=radio name='RBtnSelection' value="
+ (int)this._constraints.DataKeys[e.Item.ItemIndex] + ">";

And I check the
if(Request.Form["RBtnSelection"] != null)
{
int SelectedID = int.Parse(Request.Form["RBtnSelection"]);
}
to retrieve the Id selected..
I have a delete button which when clicked should pop up a confirmation
pop up and then only delete the particular row...I am unable to figure
out when and where I have to add the onclick attribute for it....like.
this._deleteBtn.Attributes.Add("onclick", "return Confirm_Delete();");
Can somebody please suggest me how to do this??

Thanks a lot.
 
S

S. Justin Gengo

Samy,

Use the OnItemDatabound event of the datagrid, then in that event, identify
when an actual datarow is being bound, get the button object and cast it as
a button, and finally add your attribute. It would look something like this:

1.. Private Sub DataGrid1_ItemDataBound(ByVal sender As System.Object,
ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles
DataGrid1.ItemDataBound
2.. Try
3.. Dim itemType As ListItemType = e.Item.ItemType
4..
5.. If ((itemType = ListItemType.Pager) Or (itemType =
ListItemType.Header) Or (itemType = ListItemType.Footer)) Then
6.. Return
7.. Else
8.. '---You'll have to change the code that get's the link button to
reflect the proper zero based column index and control index:
9.. Dim button As LinkButton = CType(e.Item.Cells(3).Controls(0),
LinkButton)
10.. e.Item.Attributes.Add("onClick", "javascript:[your script here];")
11.. End If
12.. Catch ex As Exception
13.. '---Handle Exception
14.. End Try
15.. End Sub

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 
S

Samy

Hi Justin,
Thanks a lot for your reply. The delete button (Image button) is
outside the datagrid. So I need to know when and where the statement
below has to be added. I don't wnat to show the pop up confirmation
when none of the radio buttons are selected from the datagrid.

Please let me know if I am not clear
Thanks.
Sam
 
S

S. Justin Gengo

Samy,

Ok, I misunderstood the first time. But I've got you now.

You'll have to add a detection in your script that pops up the confirmation
to check each radio button to look for a selected one.

That script will have to loop through each radiobutton and check if any are
selected. It would look something like this:
(I haven't tested the script below. I converted it from one I built for
verfying a checkboxlist count in a CheckBoxListRequiredFieldValidator I
wrote.
If you'd like the original script you could download the validator from my
site. It's free and comes as a Visual Studio.Net 2003 project with full
source code. Get it here:
http://www.aboutfortunate.com?page=checkboxlistvalidatordemo.)

<script language="javascript">
<!--

function radiobutton_verification(clientID) {
var val = document.all[document.all[clientID].controltovalidate];
var col = val.all

if (col != null ) {
var radiobuttoncount = 0;

for (i = 0; i < col.length; i++ ) {
if (col.item(i).tagName == 'INPUT') {
radiobuttoncount += 1;

if (col.item(i).checked ) {
return true;
}
}
}
}
}

-->
</script>


--
Sincerely,


S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 

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,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top