Laster
Laster

Reputation: 31

A column named 'link' already belongs to this DataTable: cannot set a nested table name to the same name

<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" Title="Industry News" %>

<%@ Import Namespace="System.Xml" %>

<%@ Import Namespace="System.Data" %>



<script runat="server">



protected void Page_Load(object sender, EventArgs e)

{

    XmlTextReader reader = new XmlTextReader("http://www.trucknews.com/rssfeeds       /TN_dailynews.xml");

    DataSet ds = new DataSet();

    ds.ReadXml(reader);



    GridView1.DataSource = ds.Tables[2];

    GridView1.DataBind();       

}

</script>



<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

<img src="Images/newsweb.gif" /><br />

<br />

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" GridLines="None" Width="100%">

    <Columns>

        <asp:TemplateField>

            <ItemTemplate>

                <table style="width: 100%">

                    <tr style="text-align: left; vertical-align: text-top">

                        <td colspan="2"><hr style="width: 100%" /></td>

                    </tr>

                    <tr style="text-align: left; vertical-align: text-top">

                        <td style="text-align: left"><a onclick="window.open(this.href,'_blank');return false;" href="<%# Eval("link") %>"><%# Eval("title") %></a></td>

                        <td style="text-align: right"><%# Eval("author") %></td>

                    </tr>

                </table>

            </ItemTemplate>             

        </asp:TemplateField>

    </Columns>

    <RowStyle HorizontalAlign="Left" VerticalAlign="Top" />

    <AlternatingRowStyle HorizontalAlign="Left" VerticalAlign="Top" />

</asp:GridView>


var _gaq = _gaq || [];

_gaq.push(['_setAccount', 'UA-2040116-3']);

_gaq.push(['_trackPageview']);



(function() {

var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;

ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') +   '.google-analytics.com/ga.js';

var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);

})();



</script>


</asp:Content>

Anyone have any ideas what the problem could be, I need more eyes =)

I thought it might be recent update I made, but alas it wasn't. I assume it has something to do with the XML I am pointing to.

http://www.trucknews.com/rssfeeds/TN_dailynews.xml

Thank in advance.

Upvotes: 1

Views: 3749

Answers (3)

almi_n
almi_n

Reputation: 51

I guess the problem is caused by the line

<atom:link href="http://www.trucknews.com/rssfeeds/TN_dailynews.xml" rel="self" type="application/rss+xml"/>

of the source. ReadXml function does not take the namespace into consideration I guess, so it makes two link columns.

Upvotes: 1

Hogan
Hogan

Reputation: 70526

The problem is still the same -- use single quotes as HatSoft says

href="<%# Eval('link') %>"

Is wrong, because in Eval('Link') is not valid C#. You want this:

href='<%# Eval("link") %>'

Upvotes: 0

HatSoft
HatSoft

Reputation: 11201

I noticed this href="<%# Eval("link") %>" and can say that you are not using the DataBinder Eval correctly

Please use it this way href='<%# Eval("link") %>' use the single quotes

Upvotes: 0

Related Questions