Click here to Skip to main content
15,914,924 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear All,

I am using Nested Repeater Control in my page to display a set of questions and for each question, 4 choices.

I an able to use a single repeater and display all the questions. But I am unable to use Nested Repeaters.

I get a runtime exception : "ArgumentNullException was unhandled by user code, 'column' argument cannot be null Parameter Name: column" (Error line I have highlighted in bold)

Below is the ASPX File.

XML
<body>
    <form id="form1" runat="server">
    <div style="height: 307px">
        <asp:Repeater ID="Repeater1" runat="server"
            onitemcommand="Repeater1_ItemCommand">
        <ItemTemplate>
        <%#DataBinder.Eval(Container, "DataItem.q_text")%>
        <br />
        <asp:Repeater ID="Repeater3" dataSource='<%#((DataRowView)Container.DataItem).Row.GetChildRows("myrelation")%>' runat="server">
        <AlternatingItemTemplate>
        <br />
        <%#DataBinder.Eval(Container,"DataItem.ans_text")%>

        </AlternatingItemTemplate>
         </asp:Repeater>
        </ItemTemplate>
        <AlternatingItemTemplate>
        <tr>
        <td>
        <br/>
        <%#DataBinder.Eval(Container, "DataItem.q_text")%>
        <br/>
        <br/>
        </td>
        </tr>
        </AlternatingItemTemplate>
         </asp:Repeater>

    </div>
    </form>
</body>



Below is the Code Behind code.

protected void Page_Load(object sender, EventArgs e)
    {
        const string ConnectionString = "Data Source=X-XXXXXXXX\\SQLEXPRESS;Initial Catalog=XXXXXX;Integrated Security=True";
        SqlConnection conn = new SqlConnection(ConnectionString);
        
        
        conn.Open();
        

        string query = "select q_text from table1";
        string query1 = "select ans_text from  table1, table2 where  table1.q_id= table2.q_id";

        SqlDataAdapter cmd1 = new SqlDataAdapter(query, conn);
        DataSet ds = new DataSet();
        cmd1.Fill(ds, "table1");

        SqlDataAdapter cmd2 = new SqlDataAdapter(query1, conn);
        cmd2.Fill(ds, "table2");
        ds.Relations.Add("myrelation", ds.Tables[" table1"].Columns["q_id"], ds.Tables[ table2"].Columns["q_id"]);
        Repeater1.DataSource = ds.Tables[" table1"];
        Page.DataBind();

        conn.Close();

  
    }


Neither of tables are blank and are having valid values.

Kindly assist.
Posted

1 solution

You were given this link as an answer to your last question
A quick guide to using nested repeaters in ASP.NET[^]
 
Share this answer
 
Comments
Mukund Kallapur 6-Oct-10 1:27am    
Hi Mark,

I have already checked that link, in that case an XML file is used and here I am using Database, I have also tried using the code from that example, but I am getting errors.

Hence I have posted this post.

Thanks
Mukund Kallapur 6-Oct-10 1:53am    
Hi Mark,

I have tried the same code which is given in the link, but I wanted to know that whether that code is wrong ??

Because it gives a compile time error "The name "PlayerRepeater" does not exist in the current context"

Can u pls chk

Regards
saini arun 6-Oct-10 4:01am    
In which project you are getting the compile time error?

In the downloaded source code from article or in your project?

The source code downloaded from article compile and run absolutely fine on my end.
[no name] 6-Oct-10 7:21am    
You have to be able to expand your thinking, not every article or sample is going to perfectly fit your needs. It doesn't matter that the article uses an XML file and you need a DataSet, the binding will be done the same because DataSource is a object.
Mukund Kallapur 6-Oct-10 14:15pm    
Hi Mark,

Your suggestion is correct, thats why I tried with the tables from the database, but here the error is different which says "Column cannot be null", as I have said in this post, whereas in the example it uses an XML, which is not having columns.

Kndly assist...

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



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