how to get the value out of the HyperLink column in the datagrid

I need to get the text which is displayed in the hyperlink column. I tried many ways but always it returns empty "". 

This is little bit of my C# code:

foreach(DataGridItem dgi in myDataGrid.Items)
            {
                CheckBox myCheckBox = (CheckBox)dgi.Cells[3].Controls[1];
                HyperLinkColumn hyper = (HyperLinkColumn) myDataGrid.Columns[1];   
               
                if(myCheckBox.Checked == true)
                {

                   
                    str.Append(hyper.Text);


And this is the html code for the DataGrid:

<asp:datagrid id="myDataGrid" runat="server" DataKeyField="CodeSampleID" ShowFooter="True" ShowHeader="False"
                Width="912px" Font-Size="XX-Small" Font-Names="Verdana" AutoGenerateColumns="False" BorderWidth="0px">
                <Columns>
                    <asp:BoundColumn DataField="Name" HeaderText="Name"></asp:BoundColumn>
                    <asp:HyperLinkColumn Target="_blank" DataNavigateUrlField="Url" DataTextField="Url" HeaderText="Url"></asp:HyperLinkColumn>
                    <asp:BoundColumn DataField="DateCreated" HeaderText="DateCreated"></asp:BoundColumn>
                    <asp:TemplateColumn HeaderText="Select">
                        <ItemTemplate>
                            <asp:CheckBox id="CheckBox1" runat="server"></asp:CheckBox>
                        </ItemTemplate>
                    </asp:TemplateColumn>
                </Columns>
            </asp:datagrid>

HighOnCoding
Wanna get high!
0
azamsharp
4/29/2005 6:59:44 PM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

2 Replies
611 Views

Similar Articles

[PageSpeed] 15

 azamsharp wrote:
I need to get the text which is displayed in the hyperlink column. I tried many ways but always it returns empty "".

This is little bit of my C# code:

foreach(DataGridItem dgi in myDataGrid.Items)
            {
                CheckBox myCheckBox = (CheckBox)dgi.Cells[3].Controls[1];
                HyperLinkColumn hyper = (HyperLinkColumn) myDataGrid.Columns[1];   
               
                if(myCheckBox.Checked == true)
                {

                   
                    str.Append(hyper.Text);

Try This instead:

foreach(DataGridItem dgi in myDataGrid.Items)
            {
                CheckBox myCheckBox = (CheckBox)dgi.Cells[3].Controls[1];
                //HyperLinkColumn hyper = (HyperLinkColumn) myDataGrid.Columns[1];   

               HyperLink hyper = (HyperLink) dgi.Cell[1].Controls[0];

            
                
                if(myCheckBox.Checked == true)
                {

                   
                    str.Append(hyper.Text);

 


Richard Xin
MCAD(charter member),MCDBA,MCSD
Web Site: www.richardxin.com (For ASP.Net tips and Code snippet)
0
rx
4/29/2005 7:25:20 PM
Thanks a Billion. Its working :) 

Thanks again :)


HighOnCoding
Wanna get high!
0
azamsharp
4/29/2005 8:10:04 PM
Reply: