This is a migrated thread and some comments may be shown as answers.

Details Table HyperLink Click Row select Problem

3 Answers 105 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Venkata
Top achievements
Rank 1
Venkata asked on 10 Jul 2014, 09:31 PM
Hi,
I have a RadGrid which contains Parent Rows and each parent Row has Child Rows(populating Child rows with DetailTableDataBind event).
and i am creating a hyperlink inside the child table
protected void grd_ItemDataBound(object sender, GridItemEventArgs e)
{
  if (e.Item.OwnerTableView.Name == "ChildTable" && e.Item is GridDataItem)
       {
         GridDataItem item = (GridDataItem)e.Item;
         string  szID = item.GetDataKeyValue("ID").ToString();
         string szName = item.GetDataKeyValue("NAME").ToString(); 
 
         HyperLink hLink = (HyperLink)item.FindControl("HyperLink1");
         hLink.Text = szName;
 
         hLink.Attributes.Add("onclick", "return onDocClick('" + item.OwnerTableView.ParentItem.ItemIndex + "', '" + item.ItemIndex + "');");
      }
}

Javascript
 function onDocClick(parentindex, childindex) 
 { 
  // here How do i select/check Corresponding Parent Row and Child Row?
 }

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 11 Jul 2014, 09:09 AM
Hi Venkata,

Please try the following code snippet to select the Parent and Child rows.

ASPX:
<asp:ScriptManager ID="scriptmanagerMain" runat="server" EnablePageMethods="true" ScriptMode="Release" LoadScriptsBeforeUI="true">
</asp:ScriptManager>

JS:
<script type="text/javascript">
    var index = 0;
    function onDocClick(parentindex, childindex) {
        var val = '<%=Session["Index"] %>'
        if (val != "") {
            //To clear the previous selection
            var grid = $find("<%=RadGrid1.ClientID %>");
            var MasterTable = grid.get_masterTableView();
            MasterTable.clearSelectedItems();
            var detailTable = $find("<%= RadGrid1.ClientID %>").get_detailTables()[val];
            detailTable.clearSelectedItems();
            PageMethods.CreateSessionViaJavascript(parentindex);
        }
        //To select row
        var grid = $find("<%=RadGrid1.ClientID %>");
        var MasterTable = grid.get_masterTableView();
        MasterTable.clearSelectedItems();
        MasterTable.get_dataItems()[parentindex].set_selected("true");
        var Row = MasterTable.get_dataItems()[parentindex];
        if (Row._expanded == false) {
            Row.set_expanded("true");
        }
        var childRows = Row.get_nestedViews()[0].get_dataItems();
        Row.get_nestedViews()[0].clearSelectedItems();
        if (childRows[childindex]._selected == false) {
            childRows[childindex].set_selected("true");
        }
        if (val == "") {
        //storing in session the index to clear previous selection
            PageMethods.CreateSessionViaJavascript(parentindex);
        }
    }
</script>

C#:
[System.Web.Services.WebMethod]
public static string CreateSessionViaJavascript(string index)
{
    Page objp = new Page();
    objp.Session["Index"] = index;
    return index;
}

Thanks,
Princy
0
Prabha
Top achievements
Rank 1
answered on 12 Jul 2014, 11:37 AM
Hi Princy,

I have to call Confirm message when Editbutton click on GridEditCommandColumn.

that is, In ItemCommand event ->CommandName=="Update" -> I will check one condition, if that will be true means , it will show a javascript confirm message.

 if (IsTrue==true)
{
                            Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "javascript::if(!confirm(Delete the row?));", true);                

      if user click ok 
      {
          //my code
       }
       else
            return;
 }

how to do this?
0
Princy
Top achievements
Rank 2
answered on 15 Jul 2014, 09:41 AM
Hi Prabha,

Please try the following code snippet to have a confirm on Update.

C#:
void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
   if (e.Item is GridEditableItem && e.Item.IsInEditMode && !e.Item.OwnerTableView.IsItemInserted)
  {
   GridEditableItem editItem = e.Item as GridEditableItem;
   //Accessing UpdateButton in editform
   LinkButton button = (LinkButton)editItem.FindControl("UpdateButton");
   //Attaching a client onclick event for confirm
   button.Attributes.Add("onclick", "GetInputFromUser('" + editItem.ItemIndex + "');return false;");
  }
}

JS:
<script type="text/javascript">
    function GetInputFromUser(index) {
     if (confirm("Are you sure you want to Update this?") == true) {
      //fire the Update command
      $find('<%= RadGrid1.ClientID %>').get_masterTableView().fireCommand("Update", index);
       }
        else {
        //Your code
       //If you want a server event you can use fireCommand with ur Custom CommandName
       }
    }
</script>

Thanks,
Princy
Tags
Grid
Asked by
Venkata
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Prabha
Top achievements
Rank 1
Share this question
or