473,386 Members | 1,785 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,386 software developers and data experts.

multiple selection in nested gridview, help please

hello all,

I have a parent gridview company and in this one a nested gridview people, Is it possible to allow the user to select one row or multiple rows from the people gridview using a check box and also get the datakey (in my case personid) of the the rows selected. Please point me in the right direction. This is what i have so far but i have problem accessing the child gridview in the button click event

Cheers, Shilpa.

<asp:GridView ID="grdCompanyPeople" runat="server" AutoGenerateColumns="False" DataKeyNames ="CoDetailID,CoID" OnRowDataBound ="grdCompanyPeople_RowDataBound" SelectedIndex ="0" OnSelectedIndexChanging ="grdCompanyPeople_SelectedIndexChanging" OnRowCreated="grdCompanyPeople_RowCreated" OnRowCommand ="grdCompanyPeople_RowCommand" OnPageIndexChanging ="grdCompanyPeople_PageIndexChanging" PageSize ="2" AllowPaging="True" OnSelectedIndexChanged ="grdCompanyPeople_SelectedIndexChanged" GridLines="Horizontal" Width="100%">

<Columns>

<asp:TemplateField>



<ItemTemplate>

<asp:ImageButton ID="btnDSelect" runat="server" ImageUrl="../images/ok.png"

ToolTip="Display Deal Details" CommandArgument='<%# Bind("CoDetailID") %>' OnClick="btnCSelect_Click"/>

</ItemTemplate>

<ItemStyle VerticalAlign="Top" />

</asp:TemplateField>
<asp:TemplateField HeaderText="Company Type">

<ItemTemplate>

<table>

<tr>

<td></td>

<td><asp:DropDownList ID="ddlCoType" runat="server" CssClass="form">

</asp:DropDownList>

<asp:Label ID="DetailID" runat="server" Text='<%# Bind("CoDetailID") %>' Visible="False"></asp:Label></td>

<td valign="top"><asp:Label ID="Label2" runat="server" Text="Hired By:" Height="1px" Width="50px"></asp:Label></td>

<td valign="top"><asp:DropDownList ID="ddlClientList" runat="server" AppendDataBoundItems="true" CssClass="form">

<asp:ListItem Text ="Please Select" Value="0" />

</asp:DropDownList></td>

</tr>

</table>



</ItemTemplate>

<ItemStyle Width="10px" VerticalAlign="Top" />

<HeaderStyle HorizontalAlign="Center" />

</asp:TemplateField>

<asp:TemplateField HeaderText="Company Role">

<ItemTemplate>

<asp:TextBox ID="tbCoRole" runat="server" CssClass ="form"></asp:TextBox>

</ItemTemplate>

<ItemStyle Width="10px" VerticalAlign="Top" />

<HeaderStyle HorizontalAlign="Center" />

</asp:TemplateField>

<asp:BoundField DataField="Company" HeaderText="Company" >

<ItemStyle Width="80px" VerticalAlign="Top" />

<HeaderStyle HorizontalAlign="Center" />

</asp:BoundField>

<asp:BoundField DataField="City" HeaderText="City" >

<ItemStyle Width="40px" VerticalAlign="Top" />

<HeaderStyle HorizontalAlign="Center" />

</asp:BoundField>

<asp:BoundField DataField="State" HeaderText="State" >

<ItemStyle Width="20px" VerticalAlign="Top" />

<HeaderStyle HorizontalAlign="Center" />

</asp:BoundField>

<asp:BoundField DataField="Country" HeaderText="Country" >

<ItemStyle Width="50px" VerticalAlign="Top" />

<HeaderStyle HorizontalAlign="Center" />

</asp:BoundField>

<asp:ButtonField ButtonType ="Image" CommandName="Show" ImageUrl="../images/add.png" >

<ItemStyle VerticalAlign="Top" />

</asp:ButtonField>

<asp:ButtonField ButtonType ="Image" CommandName="Hide" ImageUrl="../images/remove.png" >

<ItemStyle VerticalAlign="Top" />

</asp:ButtonField>

<asp:TemplateField HeaderText="People List">

<ItemTemplate> /// Nested people gridview

<asp:GridView ID="grdPersons" runat="server" AutoGenerateColumns ="false" DataKeyNames ="PersonID" GridLines="Horizontal" HeaderStyle-CssClass="head_1" Width="160px">

<Columns>

<asp:TemplateField>

<HeaderStyle HorizontalAlign="left" />

<HeaderTemplate>

<asp:CheckBox ID="chkSelectAll" ToolTip="Click here to select/deselect all rows"

runat="server" />

</HeaderTemplate>

<ItemTemplate>

<asp:CheckBox ID="chkSelect" runat="server" />

<asp:ImageButton ID="btnPersonSelect" runat="server" ImageUrl="../images/ok.png"

ToolTip="Display People Details" CommandArgument='<%# Bind("PersonID") %>' OnClick="btnPersonSelect_Click"/>

</ItemTemplate>

<ItemStyle Width="5px" />

</asp:TemplateField>

<asp:BoundField DataField="FullName" HeaderText="Name" >

<ItemStyle Width="150px" />

</asp:BoundField>

<asp:BoundField DataField="Title" HeaderText="Job Title" />

</Columns>

</asp:GridView>

</ItemTemplate>

<HeaderStyle HorizontalAlign="Center" />

<ItemStyle VerticalAlign="Top" Width="250px" />

</asp:TemplateField>

</Columns>

<FooterStyle CssClass="head_1" />

<HeaderStyle CssClass="head_1" />

</asp:GridView>
//Binding the nested people grid in parent company gridview rowdatabound event
protected void grdCompanyPeople_RowDataBound(Object sender, GridViewRowEventArgs e)
{

if (e.Row.RowType == DataControlRowType.DataRow)
{

GridView People = e.Row.FindControl("grdPersons") as GridView;
String DetailID = (e.Row.FindControl("DetailID") as Label).Text.ToString();

int RecordCount;
DataSet DS = new DataSet();

String Cmd = "stored procedure name" + DetailID;
DS = info.SelectDSQuery(Cmd);

RecordCount = DS.Tables.Count;

People.Visible = false;if (RecordCount > 0)
{

People.DataSource = DS.Tables[0];

People.DataBind();

}

CheckBox chk = (CheckBox)People.FindControl("chkSelect");if (chk != null)
{

chk.Attributes.Add("onclick", "SelectRow()");
}

foreach (GridViewRow rw in People.Rows)
{

rw.Attributes.Add("onclick", "SelectRow()");

rw.Attributes.Add("title", "Click to toggle the selection of this row");
}

}

}

//Trying to get the personid of the checked rows but not able to find the nested gridview in this method

protected void Showselection()
{

GridView People = grdCompanyPeople.FindControl("grdPersons") as GridView; // this is returning null valueforeach (GridViewRow rw in People.Rows)
{

CheckBox chk = (CheckBox)rw.FindControl("chkSelect");

if (chk != null)
{

if (chk.Checked)
{

string PersonID = People.DataKeys[rw.RowIndex]["PersonID"].ToString()+",";
Response.Write(PersonID.ToString());

}

}

}

}
Aug 13 '07 #1
0 4627

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: hammad.awan_nospam | last post by:
Hello, I am using ASP.NET 2.0. What I have done is nested a gridview inside another column of a gridview using a template data field column declaritively in my web form. Inside this child...
3
by: Martin | last post by:
Hi, I have a very frustrating problem that I have researched for countless hours to no avail. There are many posts asking very similar things, however none usefull in my situation. I am using VS...
0
by: manuel.ricca | last post by:
Hello, I'm trying to create a table with 2 nested gridviews and then a DetailsView on the right. The DetailsView should show the details of the item selected in the 2nd (nested) GridView: My...
1
by: Roy | last post by:
Hey all. Below is the nested syntax on how to make a "codeless" nested gridview embedded within another gridviews templatefield column. Only problem is that it loads slow. REAL SLOW. There has to...
1
by: sheenaa | last post by:
Hello friends, I m using ASP.NET with C# 2005 and SQL SERVER 2005 for the ASP.Net Website. I m using sqldatasource to connect and retrieve the data from database and then it displays the data...
3
by: RobertTheProgrammer | last post by:
Hi folks, I've got another problem. Basically, I'm trying to use a nested GridView, however the nexted GridView displays no values (even though in debug I'm getting valid values into my DataSet. ...
6
by: RobertTheProgrammer | last post by:
Hi folks, Here's a weird problem... I have a nested GridView setup (i.e. a GridView within a GridView), and within the nested GridView I have a DropDownList item which has the...
2
by: Michael | last post by:
It seems that a gridview allows us to delete only a single row at a time. How to extend this functionality to select multiple rows and delete all of the selected rows in a single stroke? just like...
2
by: ASF | last post by:
Hey all, I have a gridview which pulls from a BLL which pulls from a DAL (an .XSD file). Each row on that gridview has a nested repeater which pulls from another table. The code which populates...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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:
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
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,...

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.