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

gridhyperlink column query

4 Answers 122 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 18 Jan 2012, 12:37 PM

I have a databound grid and am needing to add an additional column that will show a link to a google map for the location designated for the record in each row.

firstly im not sure i am doing this in the correct place, second issue im having (using hard coded parameters) is that the URL is not including these parameter values, the URL just shows the querystring names but none of these has the additional values.

as far as i can see the url format string seems correct and the urlparameters variable is getting the string values set ok, but for some reason they are not replacing the palceholder values in the url.

finally how would i get at the actual datatable values i need once i have this hard coded version working correctly?

heres my code:

Private Sub FillGrid()
        Try

            Dim gc As GridBoundColumn
            Dim glc As GridHyperLinkColumn           

            glc = New GridHyperLinkColumn
            Me.uxGrid.Columns.Add(glc)
            glc.HeaderText = "Map"
            Dim urlparameters As String()           
            urlparameters = New String() {"b12jp", "1234", "32.54545", "-2.2342342"}
            glc.DataNavigateUrlFields = urlparameters
            glc.DataTextFormatString = "{2:D}"
            glc.DataTextFormatString = "{3:D}"
            glc.DataNavigateUrlFormatString = "GoogleMaps.htm?postcode={0}&id={1}&lat={2}&lng={3}"
            glc.UniqueName = ""
            glc.ItemStyle.HorizontalAlign = HorizontalAlign.Center
            glc.Text = "Map"
            glc.HeaderStyle.Width = Unit.Pixel(40)
            glc.HeaderStyle.HorizontalAlign = HorizontalAlign.Center

            For Each col As DataColumn In _myData.Columns

                gc = New GridBoundColumn
                Me.uxGrid.Columns.Add(gc)
                gc.HeaderText = GetCaption(col.ColumnName)
                gc.UniqueName = col.ColumnName
                gc.DataField = col.ColumnName
                gc.Display = True
                gc.HeaderStyle.Width = Unit.Pixel(170)
                gc.ItemStyle.Wrap = True
            Next
           
        Catch ex As Exception
           
        End Try
    End Sub

4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 18 Jan 2012, 12:47 PM
Hello Mark,

RadGrid does not support mixing declarative grid columns with grid columns added dynamically at runtime. Check the following help documentation which explains more about this.
Programmatic Creation.

-Shinu.
0
Mark
Top achievements
Rank 1
answered on 18 Jan 2012, 01:56 PM
the radgrid control is defined in the aspx file.

i just want to know how to add a additional column for a hyperlink in the code behind that would pick up datatable values in the url querystring for this column

can it be done?
0
Mark
Top achievements
Rank 1
answered on 18 Jan 2012, 02:36 PM

ok, im now trying an GridTemplateColumn to show my link, but im not seeing the column appear in the grid at all... what have i missed ?

heres my aspx page

<telerik:RadGrid ID="uxGrid" runat="server"
        EnableViewState="true" AllowAutomaticDeletes="false"
            AutoGenerateColumns="False" AllowSorting="True"
            GridLines="None" Skin="Default" AllowPaging="True" Culture="(Default)" PageSize="20"
            Width="100%" Height="350px" AllowFilteringByColumn="true"
        EnableHeaderContextMenu="true" EnableHeaderContextFilterMenu="true"
        GroupingEnabled="false" OnItemDataBound="uxGrid_ItemDataBound" ShowHeader="True">
       
        <ClientSettings EnableRowHoverStyle="true" >
            <Scrolling AllowScroll="True" UseStaticHeaders="True" />
        </ClientSettings>
        <MasterTableView  IsFilterItemExpanded="false">  
        <Columns><telerik:GridTemplateColumn
    UniqueName="TemplateLinkColumn"
    AllowFiltering="false"
    HeaderText="URL">
    <ItemTemplate>
        <asp:HyperLink ID="Link" runat="server"></asp:HyperLink>
    </ItemTemplate>
</telerik:GridTemplateColumn>
</Columns>    
        </MasterTableView>
        <GroupingSettings CaseSensitive="False" />       
    </telerik:RadGrid>

my code behind has this in the itemdatabound event

If e.Item.ItemType = GridItemType.Item Or e.Item.ItemType = GridItemType.AlternatingItem Then

            Dim item As GridDataItem = CType(e.Item, GridDataItem)
            Dim linkCell As GridTableCell = CType(item("TemplateLinkColumn"), GridTableCell)
            Dim reportLink As HyperLink = CType(linkCell.FindControl("Link"), HyperLink)
           
            reportLink.Text = "Google"
           
            reportLink.NavigateUrl = "http://www.google.com"
           
            reportLink.Target = "_new"

        End If

0
Shinu
Top achievements
Rank 2
answered on 19 Jan 2012, 07:03 AM
Hello Mark,

Make sure that you are using Advanced data binding techniques to bind the grid. Here is the sample code that I tried which worked as expected.
aspx:
<telerik:RadGrid ID="grid1" runat="server" DataSourceID="SqlDataSource1" onitemdatabound="grid1_ItemDataBound" AutoGenerateColumns="false">
  <MasterTableView>
     <Columns>
        <telerik:GridTemplateColumn>
           <ItemTemplate>
               <asp:HyperLink ID="HyperLink1" runat="server"></asp:HyperLink>
           </ItemTemplate>
         </telerik:GridTemplateColumn>
                </Columns>
            </MasterTableView>
</telerik:RadGrid>
C#:
protected void grid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
 if (e.Item is GridDataItem)
 {
   GridDataItem item = (GridDataItem)e.Item;
   HyperLink link = (HyperLink)item.FindControl("HyperLink1");
   link.Text = "Google";
   link.NavigateUrl = "http://www.google.co.in/";
 }
}

-Shinu.
Tags
Grid
Asked by
Mark
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Mark
Top achievements
Rank 1
Share this question
or