473,671 Members | 2,180 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

datagrid problem

Reb
I am using a datagrid within another datagrid. My second
datagrid is expand/collapse one. I am facing some error.
This is my code.

ExpandGrid.aspx

<form id="Form1" method="post" runat="server">
<asp:DataGrid id="DataGrid1" style="Z-INDEX: 101; LEFT:
8px; POSITION: absolute; TOP: 8px" runat="server"
BorderColor="#E 7E7FF" BorderStyle="No ne" BorderWidth="1p x"
BackColor="Whit e" CellPadding="3"
OnItemCommand=D ataGrid1_ItemCo mmand GridLines="Hori zontal"
Width="503px" AutoGenerateCol umns="False"
onItemDataBound ="getChildSourc e">
<SelectedItemSt yle Font-Bold="True" ForeColor="#F7F 7F7"
BackColor="#738 A9C"></SelectedItemSty le>
<AlternatingIte mStyle
BackColor="#F7F 7F7"></AlternatingItem Style>
<ItemStyle ForeColor="#4A3 C8C"
BackColor="#E7E 7FF"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="#F7F 7F7"
BackColor="#4A3 C8C"></HeaderStyle>
<FooterStyle ForeColor="#4A3 C8C"
BackColor="#B5C 7DE"></FooterStyle>
<PagerStyle HorizontalAlign ="Right" ForeColor="#4A3 C8C"
BackColor="#E7E 7FF" Mode="NumericPa ges"></PagerStyle>
<Columns>
<asp:TemplateCo lumn ItemStyle-Width="9">
<ItemTemplate >
<asp:ImageButto n ImageUrl="~/Images/Plus.gif"
CommandName="Ex pand" ID="btnExpand"
Runat="server"> </asp:ImageButton >
</ItemTemplate>
</asp:TemplateCol umn>
<asp:BoundColum n DataField="Item ID" HeaderText="ID" />
<asp:BoundColum n DataField="Item Text" HeaderText="Tex t" />
<asp:TemplateCo lumn>
<ItemStyle Width="1" />
<ItemTemplate >
<asp:PlaceHolde r ID="ExpandedCon tent" Visible="False"
Runat="server">
</td></tr>
<tr>
<td width="9"> </td>
<td colspan="3">
<asp:DataGrid id="Datagrid2" runat="server"
BorderColor="#E 7E7FF" BorderStyle="No ne" BorderWidth="1p x"
BackColor="Whit e" CellPadding="3" GridLines="Hori zontal"
Width="503px" AutoGenerateCol umns="False">
<SelectedItemSt yle Font-Bold="True" ForeColor="#F7F 7F7"
BackColor="#738 A9C"></SelectedItemSty le>
<AlternatingIte mStyle
BackColor="#F7F 7F7"></AlternatingItem Style>
<ItemStyle ForeColor="#4A3 C8C"
BackColor="#E7E 7FF"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="#F7F 7F7"
BackColor="#4A3 C8C"></HeaderStyle>
<FooterStyle ForeColor="#4A3 C8C"
BackColor="#B5C 7DE"></FooterStyle>
<PagerStyle HorizontalAlign ="Right" ForeColor="#4A3 C8C"
BackColor="#E7E 7FF" Mode="NumericPa ges"></PagerStyle>
<Columns>
<asp:BoundColum n DataField="Desc ription"
HeaderText="Des cription" />

</Columns>
</asp:DataGrid>
</asp:PlaceHolder >
</ItemTemplate>
</asp:TemplateCol umn>
</Columns>
</asp:DataGrid>
</form>

Its corresponding c# file is:

using System;
using System.Collecti ons;
using System.Componen tModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.Sess ionState;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.H tmlControls;
using System.Data.Sql Client;

namespace ExpandGrid
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.P age
{
protected System.Web.UI.W ebControls.Data Grid DataGrid1;

private void Page_Load(objec t sender, System.EventArg s e)
{

if (!IsPostBack)
{
DataTable dt = new DataTable();
DataView dv = new DataView();
dt.Columns.Add( "ItemID");
dt.Columns.Add( "Item");
dt.Columns.Add( "Descriptio n");

SqlConnection myConnection = new SqlConnection() ;
myConnection.Co nnectionString = "user
id=sa;password= sa;initial catalog=Minutes ;data source=
(local)";
myConnection.Op en();
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter( "Select
ItemID,ItemText from Item1",myConnec tion);
da.Fill(ds,"Ite m1");
DataGrid1.DataS ource = ds;
DataBind();

}
}

#region Web Form Designer generated code
override protected void OnInit(EventArg s e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form
Designer.
//
InitializeCompo nent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeCompo nent()
{
this.Load += new System.EventHan dler(this.Page_ Load);

}
#endregion

public void DataGrid1_ItemC ommand(Object sender,
DataGridCommand EventArgs e)
{
switch( e.CommandName)
{
case "Expand":
PlaceHolder ExpandedContent ;
ExpandedContent = (PlaceHolder)e. Item.Cells
[DataGrid1.Colum ns.Count - 1].FindControl
("ExpandedConte nt");
ExpandedContent .Visible = (!ExpandedConte nt.Visible);

ImageButton btnExpand;

btnExpand = (ImageButton)e. Item.Cells[0].FindControl
("btnExpand" );
if (btnExpand.Imag eUrl == "~/Images/Plus.gif")
{
btnExpand.Image Url = "~/Images/Minus.gif";
fetchData();
}
else
btnExpand.Image Url = "~/Images/Plus.gif";
break;
}
}

public void fetchData ()
{
SqlConnection myConn = new SqlConnection (
"server=(local) ;user id=sa;password= sa;
database=Minute s" );
string query = "select ItemID,ItemText from Item1; " +
"select ItemID, Description from Item1";

SqlDataAdapter da = new SqlDataAdapter ( query, myConn );
DataSet ds = new DataSet ( );
da.Fill ( ds );

// define a relationship between the two tables
ds.Relations.Ad d ( "itemId",
ds.Tables [ 0 ].Columns [ "ItemID" ] ,
ds.Tables [ 1 ].Columns [ "ItemID" ] );

DataGrid1.DataS ource = ds.Tables [ 0 ].DefaultView;
DataGrid1.DataB ind ();
}

public void getChildSource ( Object src,
DataGridItemEve ntArgs e )
{
if (e.Item.ItemTyp e == ListItemType.It em ||
e.Item.ItemType == ListItemType.Al ternatingItem)
{
DataGrid childGrid = ( DataGrid ) e.Item.FindCont rol
( "Datagrid2" );
childGrid.DataS ource = ( ( DataRowView )
e.Item.DataItem ).CreateChildVi ew ( "itemId" );
childGrid.DataB ind ( );
}
}
}
}
But when i run this, I am getting the error
The relation is not parented to the table to which this
DataView points.

can anyone kindly help.

thanks

Nov 15 '05 #1
0 2102

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
9921
by: Chris Plowman | last post by:
Hi all, I was wondering if anyone can help me with a really annoying problem I have been having. I made a derived datagrid class that will select the row when a user clicks anywhere on a cell (multi-select without modifier keys). I got that working fine, but I also wanted to keep rows selected after a sort, which I do by storing the row's id in an arraylist. The idea was to do the sort and then go back and re-select the rows with that...
0
3173
by: Emerson | last post by:
The following assumes a System.Windows.Forms.DataGrid with a System.Data.DataTable set as the DataSource. I'm programming in C# Here's my scenario I click in a cell on a DataGrid. I enter some text. Before changing to another cell in the DataGrid, I move my mouse pointer off the DataGrid and change the selected item in a ListBox or TreeView. Here's my question Which should fire first, the DataTable's RowChanged/CellChanged event or...
5
2587
by: Jeff | last post by:
IDE: VS 2003 :NET OS: XP Pro My app have a form with a tab-control on it. The tab-control have 2 tabpages. One of the tabpages displays a datagrid, and the other tabpage displays details (order date, name, address etc) about the selected row in the datagrid... My problem is when I enter a new record in the details tabpage (saves data to database), and go back to the datagrid. Only the data from the PM-table
1
4315
by: Rick | last post by:
Hello all, I hope all is well with you. I am having a seriously difficult time with this problem. Allow me to set up the problem. I have a System.Web.UI.Page with the following controls (watch the layout, some have child controls):
4
2117
by: The Alchemist | last post by:
I am having a problem with a dynamically-generated Datagrid. It is important to point out that this problem does not exist with a design-time created Datagrid, but only with a dynamically generated Datagrid in a Web Custom Control (WCC) : The datagrid has LinkButton Column which has a select LinkButton for each row. When this button is clicked, the Datagrid raises its 'ItemCommand' event which captures the information for that row and...
9
5053
by: tshad | last post by:
How do I find (and set) a couple of labels in the Footer after a DataGrid is filled? I have a bunch of DataGrids that get displayed nested inside a DataList. The datagrid looks like: ******************************************************************************* <asp:DataGrid visible="False" border=1
4
3487
by: tshad | last post by:
I am having trouble with links in my DataGrid. I have Links all over my page set to smaller and they are consistant all over the page in both Mozilla and IE, except for the DataGrid. Here is a snippet from my .css file: *************************** body { margin:0; padding:0;
0
1693
by: optimizeit | last post by:
What I am attempting to do is import an Excel Workbook and display the worksheets in a datagrid dynamically. I am very close to getting this to work. I have to this point successfully imported a single worksheet into a dataset. I successfully built a dynamic datagrid. And I did successfully bind it to the dataset. Then I added the datagrid control to a PlaceHolder. The first worksheet displays beautifully. The next step is to allow...
9
2715
by: rn5a | last post by:
A Form has a DataGrid which displays records from a SQL Server 2005 DB table. Users can modify the records using this DataGrid for which I am using EditCommandColumn in the DataGrid. This is the code: <script runat="server"> Dim sqlConn As New SqlConnection(".....") Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs) If Not (Page.IsPostBack) Then FillDataGrid()
2
6584
by: =?Utf-8?B?Y3JlYXZlczA2MjI=?= | last post by:
I have a nested datagrid in a xaml file, the parent datagrid loads the vendor information and the details loads the documents for that vendor in a datagrid. Everything is working fine until I click in the child datagrid and then go to the combobox and choose another vendor. When the new vendor is loaded nothing shows in the datagrid but the itemsource shows the info is there. Know if I click on the child cell and then click back on the...
0
8474
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8392
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8912
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8819
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8597
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7428
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5692
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4403
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2049
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.