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

hyperlink text bound from database and open a radwindow

3 Answers 127 Views
Grid
This is a migrated thread and some comments may be shown as answers.
newguy
Top achievements
Rank 1
newguy asked on 02 Sep 2013, 08:46 AM
Hi Guys,

i currently have a rad window that opens when a picture in the RadGrid is clicked

My RadGrid
<telerik:RadGrid ID="grdIncidents" Height="890px" runat="server" OnItemCreated="grdIncidents_ItemCreated"
                    AllowAutomaticInserts="True" AutoGenerateColumns="False" OnNeedDataSource="grdIncidents_NeedDataSource"
                    meta:resourcekey="grdIncidentsResource1" AllowPaging="True" PageSize="15" AllowSorting="True" OnDeleteCommand="grdIncidents_DeleteCommand"
                    CellSpacing="0" GridLines="None" onprerender="grdIncidents_PreRender">
 
                    <ClientSettings Scrolling-AllowScroll="false">
                        <Selecting CellSelectionMode="None"></Selecting>
                    </ClientSettings>
 
                    <MasterTableView DataKeyNames="IncidentID" ClientDataKeyNames="IncidentID" CommandItemDisplay="Top">
                     
                    <Columns>
                        <telerik:GridBoundColumn DataField="Status" HeaderText="Status" ItemStyle-Font-Names="Calibri" meta:resourcekey="GridBoundColumnResource1"
                                                 Resizable="False" UniqueName="Status" ReadOnly="True" Reorderable="False" ShowSortIcon="False">
 
                            <FooterStyle HorizontalAlign="Center" Width="20px" Wrap="True" />
                            <HeaderStyle HorizontalAlign="Center" Width="20px" Wrap="True" />
                            <ItemStyle Font-Names="Calibri" HorizontalAlign="Center" Width="20px" Wrap="True" />
                        </telerik:GridBoundColumn>
 
                        <telerik:GridHyperLinkColumn FooterText="HyperLinkColumn footer" UniqueName="IncidentType" HeaderText="Title</br>Reference" DataTextField="IncidentType" NavigateUrl="#">
                        </telerik:GridHyperLinkColumn>
 
                           <telerik:GridBoundColumn DataField="AccountDetails"
                                HeaderText="Account<br/>Site<br/>Location"
                                meta:resourcekey="GridBoundColumnResource4" UniqueName="AccountDetails" Resizable="False"/>
                             
                            <telerik:GridBoundColumn DataField="ProductDetails"
                                HeaderText="Product<br/>Component"
                                meta:resourcekey="GridBoundColumnResource5" UniqueName="ProductDetails" Resizable="False"/>
                             
                            <telerik:GridBoundColumn DataField="DepartmentDetails"
                                HeaderText="Department<br/>Category"
                                meta:resourcekey="GridBoundColumnResource6" UniqueName="DepartmentDetails" Resizable="False"/>
                             
                            <telerik:GridBoundColumn DataField="ImpactLevel"
                             HeaderText="Impact"
                             meta:resourcekey="GridBoundColumnResource7" UniqueName="ImpactLevel" Resizable="False"/>
                             
                            <telerik:GridBoundColumn DataField="CurrentAssignedPerson.FullName"
                                HeaderText="Assigned User" meta:resourcekey="GridBoundColumnResource8" UniqueName="Assigned" Resizable="False"/>
                             
                            <telerik:GridBoundColumn DataField="LoggedDate" HeaderText="Incident Log Date"
                                meta:resourcekey="GridBoundColumnResource9" UniqueName="LoggedDate" />
                             
                            <telerik:GridBoundColumn DataField="LastUpdated" HeaderText="Last Action Date" meta:resourcekey="GridBoundColumnResource10"
                                UniqueName="LastUpdated" />
 
                            <telerik:GridTemplateColumn UniqueName="TemplateEditColumn">
                            <ItemStyle HorizontalAlign="Center" />
                                <ItemTemplate>
                                    <asp:HyperLink ID="EditLink" runat="server" Text="Edit"><img src="../Images/icons/pencil.png" class="editPics"></asp:HyperLink>
                                    <br>Edit
                                </ItemTemplate>
                            </telerik:GridTemplateColumn>
 
                            <telerik:GridTemplateColumn UniqueName="ActionColumn">
                            <ItemStyle HorizontalAlign="Center" />
                                <ItemTemplate>
                                    <asp:HyperLink ID="ActionLink" Text="Action" runat="server"><img src="../Images/icons/action.png" class="editPics"></asp:HyperLink>
                                    <br>Action
                                </ItemTemplate>
                            </telerik:GridTemplateColumn>
 
                            <telerik:GridButtonColumn UniqueName="GridDeleteButton" ConfirmText="Are you sure that you would like \nto delete this incident?" ConfirmDialogType="RadWindow" ConfirmTitle="Delete" ButtonType="ImageButton" CommandName="Delete" />
 
                        </Columns>
 
                        <CommandItemTemplate>
                            <div id="AddIncidentDiv" runat="server" style="padding: 4px 7px 4px; text-align:right;">
                                <asp:ImageButton ID="btnAdd" runat="server" ToolTip="Add New Incident" ImageUrl="../Images/icons/add.png" OnClientClick="return ShowInsertForm();"/>
                            </div>
                        </CommandItemTemplate>
                    </MasterTableView>
                </telerik:RadGrid>

Javascript that opens the window
function ShowEditForm(id, rowIndex) {
                var grid = $find("<%= grdIncidents.ClientID %>");
 
                var rowControl = grid.get_masterTableView().get_dataItems()[rowIndex].get_element();
                grid.get_masterTableView().selectItem(rowControl, true);
 
                window.radopen("EditIncidents.aspx?IncidentID=" + id, "IncidentListDialog");
                return false;
            }

Code behind
protected void grdIncidents_ItemCreated(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridDataItem)
            {
                HyperLink editLink = (HyperLink)e.Item.FindControl("EditLink");
                editLink.Attributes["href"] = "#";
                editLink.Attributes["onclick"] = String.Format("return ShowEditForm('{0}','{1}');", e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["IncidentID"], e.Item.ItemIndex);

                     HyperLink actionLink = (HyperLink)e.Item.FindControl("ActionLink");
                     actionLink.Attributes["href"] = "#";
                     actionLink.Attributes["onclick"] = String.Format("return ShowActionForm('{0}','{1}');", e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["IncidentID"], e.Item.ItemIndex);
 
            }
        }

Reference numbers are being loaded from the database into the radGrid as a GridHyperLink column, what needs to be done is when a hyper link is clicked it opens the RadWindow, how would i go about doing this? while still loading the reference numbers from the database.

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 02 Sep 2013, 09:34 AM
Hi Newguy,

Please try the following code snippet to open a RadWindow on GridHyperLinkColumn.

ASPX:
<telerik:RadWindowManager ID="RadWindowManager1" runat="server">
    <Windows>
        <telerik:RadWindow ID="RadWindowDetails" runat="server">
        </telerik:RadWindow>
    </Windows>
</telerik:RadWindowManager>
 . . . . . . . . . . . .
 <telerik:GridHyperLinkColumn HeaderText="" UniqueName="OpenWindow" DataTextField="DataColumnName"   DataTextFormatString="OpenWindow" DataNavigateUrlFields="OpenWindow" DataNavigateUrlFormatString="javascript:ViewCheck({0})">
</telerik:GridHyperLinkColumn>

JS:
<script type="text/javascript">
 function ViewCheck(id) {
    var openWnd = radopen("YouPage.aspx", "RadWindowDetails");
    }   
</script>

Thanks,
Princy
0
newguy
Top achievements
Rank 1
answered on 02 Sep 2013, 10:54 AM
Hi Princy,

i have recreated your code, clicking on the hyperlinks still does nothing.
0
Princy
Top achievements
Rank 1
answered on 03 Sep 2013, 06:21 AM
Hi,

I'm not sure how you are trying to open the window on HyperLink,here are two methods for doing it,please check if either of this helps.

1)From the ClientSide,make sure you have set the DataNavigateUrlFields and DataNavigateUrlFormatString.

ASPX:
<telerik:GridHyperLinkColumn UniqueName="Freight" HeaderText="Title" DataNavigateUrlFormatString="javascript:ViewCheck({0})" DataTextField="Freight" DataNavigateUrlFields="Freight">
</telerik:GridHyperLinkColumn>

JS:
function ViewCheck(id) {       
  var openWnd = radopen("page.aspx?Frieght="+id, "RadWindowDetails");
  }

2)From ServerSide to ClientSide.

ASPX:
<telerik:GridHyperLinkColumn UniqueName="CustomerID" HeaderText="Title" DataTextField="CustomerID">
</telerik:GridHyperLinkColumn>

C#:
protected void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)
   {     
       if (e.Item is GridDataItem)
       {
           GridDataItem item = (GridDataItem)e.Item;
           HyperLink links = (HyperLink)item["CustomerID"].Controls[0];//UniqueName of HyperLinkColumn
           links.Attributes["href"] = "#";
           links.Attributes["onclick"] = String.Format("return Show('{0}');", e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["OrderID"]); //Calling Client side event and DataKeyValue being passed to client
       }
   }

JS:
function Show(id) {
       window.radopen("page.aspx?OrderID=" + id, "RadWindowDetails");
   }

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