Click here to Skip to main content
14,735,745 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
On page_load

DataTable dt = new DataTable();
DataRow row = dt.NewRow();
row["LoginName"] = userNames;
row["NavigateUrl"] = personUrl8;
dt.Rows.Add(row);
RepeaterLinks.DataSource = dt;
RepeaterLinks.DataBind();


in my aspx page
<asp:Repeater ID="RepeaterLinks" runat="server">
              <ItemTemplate >
      <asp:HyperLink ID="MyLinks" runat="server" Text='<%# DataBinder.Eval(Container, "LoginName") %>' NavigateUrl='<%# DataBinder.Eval(Container, "NavigateUrl") %>'></asp:HyperLink>

       </ItemTemplate>
          </asp:Repeater>


I get column LoginName does not belong to the table?
Posted
Comments
Dave Kreskowiak 1-Jun-15 8:16am
   
And? Did you check the table that you passed into the page to see if it has a 'LoginName 'column. It's telling you that the column isn't in the table you gave it and if it's telling you this, it's correct.
Kurac1 1-Jun-15 8:18am
   
What have i done wrong?

Notice you are creating a new DataTable but have not given it a schema ("layout"), so no columns exist on it.

Try something like:
DataTable dt = new DataTable();

dt.Columns.Add("LoginName");
dt.Columns.Add("NavigateUrl");

DataRow row = dt.NewRow();
or populate the datatable from a data source
   
v2
Comments
Kurac1 1-Jun-15 9:11am
   
DataBinding: 'System.Web.UI.WebControls.RepeaterItem' does not contain a property with the name 'LoginName'.
Add the columns to the datatable [Below two additional code lines] =
DataTable dt = new DataTable();
dt.Columns.Add("LoginName", Type.GetType("System.String"));
dt.Columns.Add("NavigateUrl", Type.GetType("System.String"));
DataRow row = dt.NewRow();
row["LoginName"] = "pallavi";
row["NavigateUrl"] = "xyz";
dt.Rows.Add(row);

RepeaterLinks.DataSource = dt;
RepeaterLinks.DataBind();
   
Comments
Kurac1 1-Jun-15 9:07am
   
DataBinding: 'System.Web.UI.WebControls.RepeaterItem' does not contain a property with the name 'LoginName'.
Please check the code for design page i.e. aspx page :-
 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default4.aspx.cs" Inherits="Default4" %>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:repeater id="RepeaterLinks" runat="server" xmlns:asp="#unknown">
         <itemtemplate>
            <asp:hyperlink id="HyperLink2">
                runat="server" 
                NavigateUrl='<%# DataBinder.Eval(Container.DataItem, "NavigateUrl") %>'> <%# DataBinder.Eval(Container.DataItem, "LoginName") %></asp:hyperlink>
             <br />
        </itemtemplate>
        </asp:repeater>
    </div>
    </form>
</body>
</html>


Please check the below code behind code :-

protected void Page_Load(object sender, EventArgs e)
{
    DataTable dt = new DataTable();
    dt.Columns.Add("LoginName", Type.GetType("System.String"));
    dt.Columns.Add("NavigateUrl", Type.GetType("System.String"));
    DataRow row = dt.NewRow();
    row["LoginName"] = "LoginName";
    row["NavigateUrl"] = "Default.aspx";
    dt.Rows.Add(row);

    row = dt.NewRow();
    row["LoginName"] = "LoginName1";
    row["NavigateUrl"] = "Default2.aspx";
    dt.Rows.Add(row);

    RepeaterLinks.DataSource = dt;
    RepeaterLinks.DataBind();
}
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900