DataRelation Collection Problem and Repeater

  • Thread starter Thread starter Guest
  • Start date Start date
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-
 
Did you read my answer to your other post about this? did it not help..you
don't seem to be doing what I suggested you try...

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)


I am Sam said:
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-
 
Hi Karl,

I did try your suggestion but I got the same error message regarding cast.



Karl Seguin said:
Did you read my answer to your other post about this? did it not help..you
don't seem to be doing what I suggested you try...

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)


I am Sam said:
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-
 
And when you cast it to DataRow instead?

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)


I am Sam said:
Hi Karl,

I did try your suggestion but I got the same error message regarding cast.



Karl Seguin said:
Did you read my answer to your other post about this? did it not help..you
don't seem to be doing what I suggested you try...

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)


I am Sam said:
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-
 
I get the following error message:

CS0117: 'System.Data.DataRow' does not contain a definition for
'CreateChildView'

making the repeater datasource as follows:
<%# ((DataRow)Container.DataItem).CreateChildView("DataFK")%>
If I type <%# ((DataRow)Container.DataItem).Rows.CreateChildView("DataFK")%>
I get an error message saying that
System.Data.DataRow does not contain a definition for Rows.


Karl Seguin said:
And when you cast it to DataRow instead?

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)


I am Sam said:
Hi Karl,

I did try your suggestion but I got the same error message regarding cast.



Karl Seguin said:
Did you read my answer to your other post about this? did it not help..you
don't seem to be doing what I suggested you try...

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)


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-
 
I get an error message stating that
System.Data.DataRow does not contain a definition for 'CreateChildView'
I typed the following:
<%# ((DataRow)Container.DataItem).CreateChildView("DataFK")%>
I also tried in the datasource <%#
((DataRow)Container.DataItem).Rows.CreateChildView("DataFK")%>
and got a a similar error but instead of 'CreateChildView' the undefined
element was 'Rows'.

Karl Seguin said:
And when you cast it to DataRow instead?

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)


I am Sam said:
Hi Karl,

I did try your suggestion but I got the same error message regarding cast.



Karl Seguin said:
Did you read my answer to your other post about this? did it not help..you
don't seem to be doing what I suggested you try...

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)


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-
 
And when I cast to DataView I get a compiliation Error as follows:

CS0122: 'System.Data.DataView.CreateChildView(string, int)' is inaccessible
due to its protection level

This is truly killing me. Is there anyway I can alter the protection level
and exactly what protection level?

Karl Seguin said:
And when you cast it to DataRow instead?

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)


I am Sam said:
Hi Karl,

I did try your suggestion but I got the same error message regarding cast.



Karl Seguin said:
Did you read my answer to your other post about this? did it not help..you
don't seem to be doing what I suggested you try...

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)


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-
 
I doubt anything is truly killing you. I think if you took the time to
understand what was going on you'd find that the solution isn't all that
complicated. I clearly haven't been very helpful to date, otherwise we'd
have this figured out by now, my apologies to that fact.

Having said that, when you bind a control to a dataset/datatable it's
actually the Default DataView which gets bound. As such, each row is a
DataRowView...this explains why you must cast e.Item.Data to the type
DataRowView. The DataRowView has a Row property which represents the actual
row it's 'viewing'

When you did:
((DataRowView)Container.DataItem).Row.GetChildRows

you were pretty much saying for the current DataRowView, get the underlying
row and then get all the child rows for the given relationship.

I belive this is where you are getting confused. The initial repeater is
getting bound to a DataView, hence the individual items are DataRowViews.
This inner repeater is getting bound to an array of rows. Hence, the
individual items are DataRow's, not DataRowViews. This is why you got the
initial cast error. As I tried to point out, there are two ways out of this
mess. You can either use the CreateChildView method of the DataRowView to
get another DataView instead of an array of rows...or you get cast the inner
repeater's DataItem to DataRow...you seem to have tried a combination of
both but never the right one....

If you still aren't following me, add an OnItemDataBound event to each
repeater (it can be the same method shared by all), add a breakpoint inside
an IF statement which checks for e.Item.ItemType == Item and see what type
e.Item.DataItem is...this will tell you exactly what type you need to cast
to.

Again, looking at your examples you've done two things:
- Cast the inner repeater's item to DataRowView when it should have been
DataRow
- Cast the inner repeater's item to DataRow (yay!) but then cast what that
repeater was being bound to to a DataView via CreateChildView (booo!)

In the 2nd attempt you did both things when you should have done one or the
other. Personally I would keep everything as DataRowView and use the
CreateChildView, instead or Row.GetChildRows()

Hope this helped.

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)


I am Sam said:
And when I cast to DataView I get a compiliation Error as follows:

CS0122: 'System.Data.DataView.CreateChildView(string, int)' is inaccessible
due to its protection level

This is truly killing me. Is there anyway I can alter the protection level
and exactly what protection level?

Karl Seguin said:
And when you cast it to DataRow instead?

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)


I am Sam said:
Hi Karl,

I did try your suggestion but I got the same error message regarding cast.



:

Did you read my answer to your other post about this? did it not help..you
don't seem to be doing what I suggested you try...

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)


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-
 
Hey Karl;

It worked!!!! Thank you so much for your help. Your a good man.


Karl Seguin said:
I doubt anything is truly killing you. I think if you took the time to
understand what was going on you'd find that the solution isn't all that
complicated. I clearly haven't been very helpful to date, otherwise we'd
have this figured out by now, my apologies to that fact.

Having said that, when you bind a control to a dataset/datatable it's
actually the Default DataView which gets bound. As such, each row is a
DataRowView...this explains why you must cast e.Item.Data to the type
DataRowView. The DataRowView has a Row property which represents the actual
row it's 'viewing'

When you did:
((DataRowView)Container.DataItem).Row.GetChildRows

you were pretty much saying for the current DataRowView, get the underlying
row and then get all the child rows for the given relationship.

I belive this is where you are getting confused. The initial repeater is
getting bound to a DataView, hence the individual items are DataRowViews.
This inner repeater is getting bound to an array of rows. Hence, the
individual items are DataRow's, not DataRowViews. This is why you got the
initial cast error. As I tried to point out, there are two ways out of this
mess. You can either use the CreateChildView method of the DataRowView to
get another DataView instead of an array of rows...or you get cast the inner
repeater's DataItem to DataRow...you seem to have tried a combination of
both but never the right one....

If you still aren't following me, add an OnItemDataBound event to each
repeater (it can be the same method shared by all), add a breakpoint inside
an IF statement which checks for e.Item.ItemType == Item and see what type
e.Item.DataItem is...this will tell you exactly what type you need to cast
to.

Again, looking at your examples you've done two things:
- Cast the inner repeater's item to DataRowView when it should have been
DataRow
- Cast the inner repeater's item to DataRow (yay!) but then cast what that
repeater was being bound to to a DataView via CreateChildView (booo!)

In the 2nd attempt you did both things when you should have done one or the
other. Personally I would keep everything as DataRowView and use the
CreateChildView, instead or Row.GetChildRows()

Hope this helped.

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)


I am Sam said:
And when I cast to DataView I get a compiliation Error as follows:

CS0122: 'System.Data.DataView.CreateChildView(string, int)' is inaccessible
due to its protection level

This is truly killing me. Is there anyway I can alter the protection level
and exactly what protection level?

Karl Seguin said:
And when you cast it to DataRow instead?

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)


Hi Karl,

I did try your suggestion but I got the same error message regarding cast.



:

Did you read my answer to your other post about this? did it not
help..you
don't seem to be doing what I suggested you try...

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)


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-
 
Back
Top