DataRelation

G

Guest

Hi everyone,

This problem is making me old. I don't want to get any older.

I have a multi-nested repeater control as follows:

<asp:Repeater ID="clubRep1" Runat="server">
<HeaderTemplate><table>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td></td>
<td><asp:Repeater ID="clubRep2" DataSource='<%#
((DataRowView)Container.DataItem).Row.GetChildRows("Section_Data")%>'
Runat="server" >
<HeaderTemplate>
<table>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><asp:Repeater ID="clubRep3" DataSource='<%#
((DataRowView)Container.DataItem).Row.GetChildRows("DataFK")%>'
Runat="server" >
<HeaderTemplate>
</HeaderTemplate>
<ItemTemplate>
Testing
</ItemTemplate>
<FooterTemplate>
</FooterTemplate>
</asp:Repeater></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
The following is the codebehind:

public class PromoPosters : System.Web.UI.UserControl
{
protected System.Data.SqlClient.SqlConnection clubconn;
protected System.Data.SqlClient.SqlDataAdapter clubadapt1;
protected System.Data.SqlClient.SqlCommand clubcmd;
protected System.Data.SqlClient.SqlCommand clubcmdimg;
protected System.Data.DataSet dsClub2;
protected System.Data.DataRow drClub;
protected System.Web.UI.WebControls.Repeater clubRep1;
protected System.Web.UI.WebControls.Repeater clubRep2;
protected System.Data.DataView dView;

private void Page_Load(object sender, System.EventArgs e)
{
string strclubconn=ConfigurationSettings.AppSettings["ConnectionString"];
clubconn=new SqlConnection(strclubconn);
clubconn.Open();
dsClub2=new DataSet();
string strPromotitle="SELECT Section_Tbl.*" +
"FROM Section_Tbl WHERE Section_Tbl.MenuID='" +
Request.QueryString["PageID"] + "'";
string stringPromoSData="SELECT SectionData.* FROM SectionData";
string stringPromoImg="SELECT img_tbl.* FROM img_tbl ORDER BY
img_tbl.DateUpload Desc";

// Fill Dataset with necessary DataTables.
clubadapt1=new SqlDataAdapter(strPromotitle,clubconn);
clubadapt1.Fill(dsClub2,"Section");
clubadapt1.SelectCommand=new SqlCommand(stringPromoSData,clubconn);
clubadapt1.Fill(dsClub2,"Data");
clubadapt1.SelectCommand=new SqlCommand(stringPromoImg, clubconn);
clubadapt1.Fill(dsClub2,"imgs");
clubconn.Close();

if(!IsPostBack)
{
dsClub2.Relations.Add("Section_Data",
dsClub2.Tables["Section"].Columns["SectionID"],
dsClub2.Tables["Data"].Columns["SectionID"]);

dsClub2.Relations.Add("DataFK",
dsClub2.Tables["Data"].Columns["DataID"],
dsClub2.Tables["imgs"].Columns["DataID"]);

clubRep1.DataSource=dsClub2;
clubRep1.DataBind();
}
}

I don't know why but I keep getting a cast error as follows:

Exception Details: System.InvalidCastException: Specified cast is not valid.

Source Error:


Line 22: <ItemTemplate>
Line 23: <tr>
Line 24: <td><asp:Repeater ID="clubRep3" DataSource='<%#
((DataRowView)Container.DataItem).Row.GetChildRows("DataFK")%>'
Runat="server" >
Line 25: <HeaderTemplate>
Line 26: </HeaderTemplate>


Can someone please help me figure out why DataRowView is not the right cast
or what the problem could be if that isn't the problem. Please please

Sam-
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top