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

Cant open a Rad window on GridHyperlink Click

2 Answers 20 Views
Grid
This is a migrated thread and some comments may be shown as answers.
newguy
Top achievements
Rank 1
newguy asked on 10 Sep 2013, 01:38 PM
Hi Guys,

I have the following 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: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:GridHyperLinkColumn FooterText="HyperLinkColumn footer" UniqueName="IncidentType" HeaderText="Title</br>Reference" DataTextField="IncidentType" NavigateUrl="#">
                            </telerik:GridHyperLinkColumn>
                             
                            <telerik:GridBoundColumn DataField="DepartmentDetails"
                                HeaderText="Department<br/>Category"
                                meta:resourcekey="GridBoundColumnResource6" UniqueName="DepartmentDetails" 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: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>

The GridHyperLinks are being populated with reference numbers, each Item in the Grid has a different reference number, what i need is when a client clicks on the reference number it opens a RadWindow and passes the IncidentID to the window aswel.

The following Grid ItemTemplate 'TemplateEditColumn' does exactly what i want, our client has asked us to remove this ItemTemplate and wants the RadWindow Opened when he clicks on the Reference number(Gridhyperlink)
.

How would i move the following functionality to the GridHyperLinkColumn?

<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>

C# 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);
            }
        }

2 Answers, 1 is accepted

Sort by
0
Accepted
Konstantin Dikov
Telerik team
answered on 13 Sep 2013, 11:17 AM
Hi John,

If you want to move the logic that you have from the template column to the "HyperLinkColumn", you could get the "HyperLinkColumn" HyperLink control as shown bellow and set the same attributes:
protected void grdIncidents_ItemDataBound(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 hyperLinkColumn = ((e.Item as GridDataItem)["IncidentType"].Controls[0] as HyperLink);
        hyperLinkColumn.Attributes["href"] = "#";
        hyperLinkColumn.Attributes["onclick"] = String.Format("return ShowEditForm('{0}','{1}');", e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["IncidentID"], e.Item.ItemIndex);
    }
}

Hope that helps.

 

Regards,
Konstantin Dikov
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
newguy
Top achievements
Rank 1
answered on 16 Sep 2013, 02:12 PM
Thank you so much :D
Tags
Grid
Asked by
newguy
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
newguy
Top achievements
Rank 1
Share this question
or