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

Hide A Href link in template Column

9 Answers 553 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kevin
Top achievements
Rank 1
Kevin asked on 27 Mar 2014, 05:03 PM
I am calling Radwindows from my radgrid and found the best way to do so is to use A Hrefs links inside of template columns.  I now have a case where I need to hide the link if a situation holds true.  I tried to use HtmlLnks, cell text and nothing has worked to get the A href.  How can I get a hold of the a href to hide it if a condition holds true.  Thanks

<telerik:GridTemplateColumn HeaderText="Edit" UniqueName="Href">
                                   <ItemTemplate>
                                       <a href="#" id="Request" title="EDIT MAC" onclick="SelectWindow(<%#Eval("intMacTypeId")%>, <%#Eval("intUserId")%>);return false;"><u>Edit MAC</u></a>
                                   </ItemTemplate>
                               </telerik:GridTemplateColumn>
 
Protected Sub myRadGrid_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles myRadGrid.ItemDataBound
       If TypeOf e.Item Is GridDataItem Then
           Dim item As GridDataItem = DirectCast(e.Item, GridDataItem)
           Dim ncc As CheckBox = DirectCast(item.FindControl("cbNcc"), CheckBox)
           Dim delete As LinkButton = DirectCast(item.FindControl("lnkDelete"), LinkButton)
           Dim user As HiddenField = DirectCast(item.FindControl("HFImoId"), HiddenField)
           Dim cell As TableCell = item("Href")
           Dim cellText As String = cell.Text
 
 
           If ncc.Checked = True Then
               delete.Visible = False
               cellText = ""
           End If
 
           If user.Value <> HFUserId.Value Then
               delete.Visible = False
               cellText = ""
           End If
       End If
   End Sub

9 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 28 Mar 2014, 10:41 AM
Hi Kevin,

Please set the runat="server" property of the <a> tag. Below have a look at the sample code snippet.

ASPX:
<telerik:GridTemplateColumn HeaderText="Number" UniqueName="Number">
    <ItemTemplate>
        <a href="#" id="Request" runat="server">
            <%#Eval("Number") %>
        </a>
    </ItemTemplate>
</telerik:GridTemplateColumn>

VB:
Protected Sub RadGrid1_ItemDataBound1(sender As Object, e As GridItemEventArgs)
    If TypeOf e.Item Is GridDataItem Then
        Dim item As GridDataItem = DirectCast(e.Item, GridDataItem)
        Dim link As HtmlAnchor = DirectCast(item.FindControl("Request"), HtmlAnchor)
            '  Gets the Text           
        Dim text As String = link.InnerText
    End If
End Sub

Thanks,
Princy
0
Kevin
Top achievements
Rank 1
answered on 28 Mar 2014, 03:28 PM
HI,

Ok tried this but I get an HTML error becuaes of  my onclick event, Once I take this out it works fine, but I need this in there to open the radwindow.



<telerik:GridTemplateColumn HeaderText="Edit" UniqueName="Href">
                                   <ItemTemplate>
                                       <a href="#" id="EditMac" runat="server" onclick="SelectWindow(<%#Eval("intMacTypeId")%>, <%#Eval("intUserId")%>);return false;"><u>Edit MAC</u></a>
                                   </ItemTemplate>
                               </telerik:GridTemplateColumn>
 
 
 
Protected Sub myRadGrid_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles myRadGrid.ItemDataBound
       If TypeOf e.Item Is GridDataItem Then
           Dim item As GridDataItem = DirectCast(e.Item, GridDataItem)
           Dim ncc As CheckBox = DirectCast(item.FindControl("cbNcc"), CheckBox)
           Dim delete As LinkButton = DirectCast(item.FindControl("lnkDelete"), LinkButton)
           Dim user As HiddenField = DirectCast(item.FindControl("HFImoId"), HiddenField)
           Dim link As HtmlAnchor = DirectCast(item.FindControl("EditMac"), HtmlAnchor)
 
           If ncc.Checked = True Then
               delete.Visible = False
               link.Visible = False
           End If
 
           If user.Value <> HFUserId.Value Then
               delete.Visible = False
               link.Visible = False
           End If
       End If
   End Sub
0
Princy
Top achievements
Rank 2
answered on 01 Apr 2014, 04:21 AM
Hi Kevin,

Please try the following code snippet to pass the values to your client events.

ASPX:
<telerik:GridTemplateColumn HeaderText="Edit" UniqueName="Href">
    <ItemTemplate>
      <a href="#" id="Request" runat="server" title="EDIT MAC" onclick='<%# "SelectWindow(" + Eval("intMacTypeId") + "," + Eval("intUserId") + " );" %>'>
      <u>Edit MAC</u></a>
    </ItemTemplate>
</telerik:GridTemplateColumn>

Thanks,
Princy
0
Kevin
Top achievements
Rank 1
answered on 01 Apr 2014, 02:10 PM
Hi Princy,

Ok every avenue runs into issues, this is one that I do not think can be done from everything I google.  The lastest prodocuted this error.Source error was the a href link.

Input string was not in a correct format.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
 
Exception Details: System.FormatException: Input string was not in a correct format.
 
Source Error:
0
Princy
Top achievements
Rank 2
answered on 02 Apr 2014, 04:35 AM
Hi Kevin,

Such an error occurs when you are not having the data in correct format, eg , string or int. Make sure you have convert the data into correct format where needed. Put breakpoints and check where the issue is raised. Provide your code snippet with which we can identify the issue more clearly.

Thanks,
Princy
0
Kevin
Top achievements
Rank 1
answered on 03 Apr 2014, 01:33 PM
Hi Princy,

Ok do not get that one since they are Primary keys from the DB what are int's. 

<telerik:GridTemplateColumn HeaderText="Edit">
                                    <ItemTemplate>
                                       <%-- <a href="#" id="EditMac" onclick="SelectWindow(<%#Eval("intMacTypeId")%>, <%#Eval("intUserId")%>, <%#Eval("bitNcc")%>);return false;"><u>Edit MAC</u></a>--%>
                                        <a href="#" id="Request" runat="server" title="EDIT MAC" onclick='<%# "SelectWindow(" + Eval("intMacTypeId") + "," + Eval("intUserId") + " );"%>'><u>Edit MAC</u></a>
                                    </ItemTemplate>
                                </telerik:GridTemplateColumn>
 
 
NeedDataSource
 
 Protected Sub myRadGrid_NeedDataSource(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles myRadGrid.NeedDataSource
 
        sql = "select intUserId, strMAcNum, intImoId, strMacType, LName + ' ' + FName + ' ' + MName Name, dtSubmitted, IMO, Case when bitNcc IS NULL then '0' WHEN bitNCC = 'True' THEN '1' " _
            & "WHEN bitNCc = 'False' then '0' END bitNCC, Case when bitTelcom IS NULL then 'false' else bitTelcom END bitTelcom, intMacTypeId from vw_IMAC_UserTbl"
 
        myRadGrid.DataSource = getData(sql)
    End Sub









0
Princy
Top achievements
Rank 2
answered on 04 Apr 2014, 04:08 AM
Hi Kevin,

Unfortunately, I'm not able to replicate the issue at my end. Below is a sample code snippet I tried which works as expected.

ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" AllowPaging="true" OnItemDataBound="RadGrid1_ItemDataBound" OnNeedDataSource="RadGrid1_NeedDataSource">
    <MasterTableView DataKeyNames="OrderID">
        <Columns>          
            <telerik:GridBoundColumn UniqueName="OrderID" DataField="OrderID" HeaderText="OrderID">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="ShipCity" HeaderText="ShipCity" UniqueName="ShipCity" />
            <telerik:GridTemplateColumn HeaderText="Edit" UniqueName="Href">
                <ItemTemplate>
                    <a href="#" id="Request" runat="server" title="EDIT MAC" onclick='<%# "SelectWindow(" + Eval("OrderID") + "," + Eval("ShipVia") + " );" %>'>
                        <u>Edit MAC</u></a>
                </ItemTemplate>
            </telerik:GridTemplateColumn>
        </Columns>
    </MasterTableView>
</telerik:RadGrid>

VB:
Protected Sub RadGrid1_ItemDataBound(sender As Object, e As GridItemEventArgs)
    If TypeOf e.Item Is GridDataItem Then
        Dim item As GridDataItem = DirectCast(e.Item, GridDataItem)
        Dim link As HtmlAnchor = DirectCast(item.FindControl("Request"), HtmlAnchor)
        If item("OrderID").Text = "10256" Then
          link.Visible = False
        End If
    End If
End Sub
 
Protected Sub RadGrid1_NeedDataSource(sender As Object, e As GridNeedDataSourceEventArgs)
    Dim sql As String = "select OrderID, ShipCity, ShipVia from Orders"
    RadGrid1.DataSource = GetDataTable(sql)
End Sub

JS:
<script type="text/javascript">
  function SelectWindow(orderid, shipid) {
    alert(orderid);
    alert(shipid);
  }
</script>

Thanks,
Princy
0
Kevin
Top achievements
Rank 1
answered on 04 Apr 2014, 06:47 PM
Hi Princy,

Ok I think it is hiccuping on this.the intUserId that I pass in has the following int's  1010, 1012 etc  and the intMacTypId is just a 1 2 or 3.  I am perplexed as to why it should wnat to convert to a double.  Is there a way around this.  It looks like the javascript that is causing the problem.

[FormatException: Input string was not in a correct format.]
   Microsoft.VisualBasic.CompilerServices.Conversions.ParseDouble(String Value, NumberFormatInfo NumberFormat) +181
   Microsoft.VisualBasic.CompilerServices.Conversions.ToDouble(String Value, NumberFormatInfo NumberFormat) +63
 
[InvalidCastException: Conversion from string "SelectWindow(" to type 'Double' is not valid.]
0
Princy
Top achievements
Rank 2
answered on 08 Apr 2014, 11:32 AM
Hi Kevin,

You can try calling the SelectWindow, from server side as below:

ASPX:
<telerik:GridTemplateColumn HeaderText="Edit" UniqueName="Href">
    <ItemTemplate>
        <a href="#" id="Request" runat="server" title="EDIT MAC"><u>Edit MAC</u></a>
    </ItemTemplate>
</telerik:GridTemplateColumn>

VB:
Protected Sub RadGrid1_ItemDataBound(sender As Object, e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemDataBound
       If TypeOf e.Item Is GridDataItem Then
           Dim item As GridDataItem = DirectCast(e.Item, GridDataItem)
           Dim link As HtmlAnchor = DirectCast(item.FindControl("Request"), HtmlAnchor)
           link.Attributes.Add("onclick", "SelectWindow('" + item("intUserId").Text + "','" + item("intMacTypeId").Text + "'); return false;")
       End If   
   End Sub

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