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

Not able to get text from GridHyperLinkColumn

1 Answer 133 Views
Grid
This is a migrated thread and some comments may be shown as answers.
bharat kumar
Top achievements
Rank 1
bharat kumar asked on 27 Sep 2010, 04:55 PM

Hi,
i am using Radgrid and here is the column ...

 <telerik:GridHyperLinkColumn DataTextField="CostCentre" HeaderText="Cost Centre" SortExpression="CostCentre"
                            FooterStyle-Font-Bold ="true"
                            FooterStyle-HorizontalAlign ="Right"
                            UniqueName="CostCentre"
                            DataNavigateUrlFields="Id"
                            DataNavigateUrlFormatString="~/Allotment/Allotment.aspx?allotmentId={0}&ViewMode=ReadOnly"
                            Target="_blank"
                            HeaderStyle-HorizontalAlign="Right"
                            ItemStyle-HorizontalAlign="Right" HeaderStyle-Width="80px"
                            />

but when i am trying to access the text of this field i am getting error.

public static void PrintRadGrid(ref StringBuilder content, RadGrid radgrid, ArrayList fieldsList, string gridTitle)
    {

        //print rows
        foreach (GridDataItem item in radgrid.Items)
        {
            ArrayList newArray = new ArrayList();

            for (int i = 0; i < fieldsList.Count; i++)
            {   
                Type type = radgrid.Columns[i].GetType();

                if (type.Name == "GridHyperLinkColumn")
                {
                   newArray.Add(((HyperLink)item[fieldsList[i].ToString()].Controls[i]).Text);
                }
                else if (type.Name == "GridBoundColumn")
                {
                   newArray.Add(item[fieldsList[i].ToString()].Text);
                }
            }

            content.Append("<tr>");
            foreach (string value in newArray)
            {
                content.Append("<td>" + value + "</td>");
            }
            content.Append("</tr>");
        }


        content.Append("</table>");
        content.Append("<br />");

    }

and it is working fine for GridBoundColumn.


please help.

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 28 Sep 2010, 06:00 AM
Hello Bharat,

You can access Hyperlink control and then retrieve the text using its ColumnUniqueName(here it is 'CostCentre') like below.

C#:
foreach (GridDataItem item in RadGrid1.Items)
     {
         ArrayList newArray = new ArrayList();
         newArray.Add(((HyperLink)item["CostCentre"].Controls[0]).Text); // access Hyperlink text using ColumnUniqueName
     }

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