473,387 Members | 1,590 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Parent Child GridView Issue

Hi,

We are working on a gridview inside the gridview (parent-child) scenario.
The data of child grid will depend on the data of parent.
Objectives:
1.Add new row in parent grid after each row and add child grid into that row
because the columns in child grid are same as parent grid and we want to
align them with the cols of parent grid.
2. If there is data for child grid we show a plus image in the parent row
(in the row above the child grid row).
3.Clicking on Plus and Minus images controls the visibility of the child
grid.

Achieved so far:
1.Adding new row to parent grid and adding child grid to that row at the
time of row binding.
2.Plus image visible or not
3.Showing child grid when clicked on plus image.

Questions
1.Plus image is not changing to minus image.
2.How do we hide the child grid when minus image is clicked?
3.How do we access the data/controls of parent grid which bound to the Bound
Field?

Any help will be greatly appreciated.
Thanks,
Innova..

Below is the code which give you some idea how we achiving our objectives.

<asp:GridView ID="gvStock" CellPadding="0" CellSpacing="0" runat="server"
GridLines="Both" CssClass="midgrey" ForeColor="#333333"
AutoGenerateColumns="false" OnRowDataBound="gvStock_RowDataBound" >
<FooterStyle BackColor="#507CD1" Font-Bold="True"
ForeColor="White" />
<RowStyle BackColor="#EFF3FB" />
<EditRowStyle BackColor="#2461BF" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True"
ForeColor="#333333" />
<PagerStyle BackColor="#2461BF" ForeColor="White"
HorizontalAlign="Center" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True"
ForeColor="White" />
<AlternatingRowStyle BackColor="White" />

<Columns >
<asp:TemplateField ItemStyle-Width="1%" >
<ItemTemplate >
<asp:ImageButton id="btPlus"
ImageUrl="~/img/plus.jpg" CausesValidation="false" CommandName="Edit"
CommandArgument='<%#DataBinder.Eval(Container, "DataItem.stockID")%>'
OnCommand="ShowChildGrid" Visible='<%#
GetImageVaisibility(DataBinder.Eval(Container,
"DataItem.StockID").ToString())%>' runat="server" />

</ItemTemplate>

</asp:TemplateField>
<asp:BoundField ItemStyle-Width="30%"
DataField="Stock" HeaderText="Stock" />
<asp:BoundField ItemStyle-Width="22%"
DataField="CurrentValue" HeaderText="Current Value" />
<asp:BoundField ItemStyle-Width="22%"
DataField="PreviousValue" HeaderText="Previous Value" />
<asp:BoundField ItemStyle-Width="20%"
DataField="change" HeaderText="Change" />
<asp:TemplateField HeaderText ="%">
<ItemTemplate >
<asp:Label runat="server" CssClass='<%#
getColour(DataBinder.Eval(Container,
"DataItem.ChangePercentage").ToString(),DataBinder .Eval(Container,
"DataItem.Type").ToString() ) %>' Text='<%# DataBinder.Eval(Container,
"DataItem.ChangePercentage")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
================================================== ======
public void gvStock_RowDataBound(object sender, GridViewRowEventArgs e)
{
DataControlRowState rowstate ;
if (e.Row.RowType == DataControlRowType.DataRow)
{

Table table = e.Row.Parent as Table;

if (table != null)
{ BoundField bs;
rowstate = e.Row.RowState;
if (rowstate == DataControlRowState.Normal )
{
clsStock st = e.Row.DataItem as clsStock;
GridViewRow row = new GridViewRow(-1, -1,
DataControlRowType.DataRow, DataControlRowState.Normal);
row.ID = "gv_" + st.StockID.ToString();
TableCell cell = new TableCell();
cell.ColumnSpan = gvStock.Columns.Count;
cell.Width = Unit.Percentage(100);

GridView gv = new GridView();
gv.DataSource = clsStock.GetMyStock_Filter(userSessoin,
st.StockID);
gv.GridLines = GridLines.Both;
gv.AutoGenerateColumns = false;
gv.Width = Unit.Percentage(100);
gv.CellPadding = 0;
gv.CellSpacing = 0;
gv.ShowHeader = false;
gv.CssClass = "midgrey";

bs = new BoundField();
bs.ItemStyle.Width = Unit.Percentage(4);
bs.DataField = "Type";
gv.Columns.Add(bs);

bs=new BoundField ();
bs.ItemStyle.Width = Unit.Percentage(27);
bs.DataField = "stock";
gv.Columns.Add(bs);

bs = new BoundField();
bs.ItemStyle.Width = Unit.Percentage(22);
bs.DataField = "CurrentValue";
gv.Columns.Add(bs);

bs = new BoundField();
bs.ItemStyle.Width = Unit.Percentage(22);
bs.DataField = "PreviousValue";
gv.Columns.Add(bs);

bs = new BoundField();
bs.ItemStyle.Width = Unit.Percentage(20);
bs.DataField = "change";
gv.Columns.Add(bs);

bs = new BoundField();
bs.ItemStyle.Width = Unit.Percentage(15);
bs.DataField = "ChangePercentage";
gv.Columns.Add(bs);

gv.DataBind();

for (byte i = 0; i<=gv.Rows.Count - 1;i++ )
gv.Rows[i].Cells[5].CssClass =
getColour(gv.Rows[i].Cells[5].Text, gv.Rows[i].Cells[0].Text);

cell.Controls.Add(gv);
row.Cells.Add(cell);
row.Visible = false;
table.Rows.Add(row);


}

}
}
}

public void ShowChildGrid(object sender, CommandEventArgs e)
{
string str = "gv_" + e.CommandArgument;
TableRow gv = gvStock.FindControl(str) as TableRow ;
gv.Visible = gv.Visible? false :true ;
ImageButton bt =(ImageButton ) sender ;

bt.ImageUrl = bt.ImageUrl == "~/img/plus.jpg" ? "~/img/minus.jpg" :
"~/img/plus.jpg" ;

}


Jun 9 '06 #1
0 8543

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

Similar topics

25
by: Steve Jorgensen | last post by:
Yup, Steve's full of tips, but hey, it makes him feel important, right? Ok, here goes. I've been trying to improve encapsulation by putting code in the same object as the stuff it affects, so I...
13
by: Stuart McGraw | last post by:
I haven't been able to figure this out and would appreciate some help... I have two tables, both with autonumber primary keys, and linked in a conventional master-child relationship. I've...
1
by: Earl Teigrob | last post by:
I did a ton of searching to try and find a simple solution to this issue and finally wrote my own, which I am sharing with everyone. In my searching, I did find a very complete and robust solution at...
5
by: Patrick Vanden Driessche | last post by:
Hi All, I'm currently writing an in-house Form validation framework (WinForms) which is based on 'Component'-inheriting object. So basically, I have a small hierarchy. FormValidator +--...
2
by: ads | last post by:
hi guys, Here's the scenario: i have a gridview on a parent page. Then i open another (child) page where i can modify the data on the dridview. How do i update the gridview soon as i do...
1
by: Andrew Hayes | last post by:
I have a parent page with a gridview, and a child page with a formview. Using the solution on velocityreviews: ...
2
by: jeet232 | last post by:
I've a class 'Parent' I declare a map using map<Parent, Parent> mymap; Now I derive one child 'Child' and I've to add it to this map, so I do a static_cast like this: Child* key = new...
2
by: =?Utf-8?B?U2lsa0NpdHlGbG9yaWRh?= | last post by:
I have a web page "PgA" with a GridView. I open another page "PgB" in a new window. On PgB, they do some things that affect the underlying data for the GridView on PgA. When the user is done...
4
by: KMSDXB | last post by:
Hi, I have three forms. "Main form" is a container and "Logon Form" is the child of this. I want to invoke another "AppLogin Form" from "Logon Form" as a child form to get the login details to a...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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,...
0
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...

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.