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

Discussion in 'ASP .Net' started by Samy, Oct 27, 2005.

  1. Samy

    Samy Guest

    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.
    Samy, Oct 27, 2005
    #1
    1. Advertising

  2. 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
    "Samy" <> wrote in message
    news:...
    > 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. Justin Gengo, Oct 27, 2005
    #2
    1. Advertising

  3. Samy

    Samy Guest

    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
    Samy, Oct 27, 2005
    #3
  4. Samy

    Samy Guest

    this._deleteBtn.Attributes.Add("onclick", "return Confirm_Delete();");
    Samy, Oct 27, 2005
    #4
  5. 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
    "Samy" <> wrote in message
    news:...
    > 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. Justin Gengo, Oct 27, 2005
    #5
  6. Samy

    Samy Guest

    Hi Justin,
    Thanks for your reply. I really appreciate it.
    Samy, Oct 28, 2005
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mohammad Ali via DotNetMonster.com

    "Deleted row information cannot be accessed through the row." WHY!!

    Mohammad Ali via DotNetMonster.com, Apr 16, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    8,255
    Mohammad Ali via DotNetMonster.com
    Apr 16, 2005
  2. Elton W
    Replies:
    0
    Views:
    3,289
    Elton W
    May 15, 2005
  3. Hiten
    Replies:
    1
    Views:
    620
    Vidar Petursson
    May 26, 2004
  4. Chumley the Walrus
    Replies:
    2
    Views:
    252
    Tom Gosselin
    Aug 10, 2004
  5. Replies:
    2
    Views:
    181
Loading...

Share This Page