GridView child of GridView - How to get value of a Template Control in the Child GridView

I have a Parent GridView and when you click in the Edit one of the columns has a Template Field which has a Child GridView. When you click Edit on the Child GridView I have a Template Field that has a TextBox. How to I retreive this value of the TextBox?

-- GridViewChild (Edit - Template Field containing this GridViewChild)
----- TextBox inside Template Field in GridViewChild.

Thank you.

Peace in Christ
Marco Napoli
1/21/2007 3:52:05 AM 72751 articles. 3 followers. Follow

8 Replies

Similar Articles

[PageSpeed] 27

What you can do as a solution is to override the RowDataBound and try to find the child GridView control. Once you get a reference to it, you can simply access any column inside the child grid.

Does this help?


Bilal Hadiar, MCP, MCTS, MCPD, MCT
Microsoft MVP - Telerik MVP
1/21/2007 5:30:14 PM

Good idea to retreive value from RowDataBound, my problem is that the Child GridView is composed of 3 Template fields which are TextBoxes in the Item Template. This gives the impression that the Child GridView all rows are Editable. The rows in the GridView are rows that do not yet exist in the SQL Server DB. But I need the users to enter all rows then I will have some code at the end that will loop through rows and inserted in DB.

Because of the above, how would you automatically get the RowDataBound to be called every time the user tabs to the next row since there is no Edit Command Botton?

Thank you.

Peace in Christ
Marco Napoli
1/21/2007 7:31:09 PM
Ps: Or if you click on a TextBox in the Child GridView, is there a way to call or invoice the Select Command so that row index is now selected?
Peace in Christ
Marco Napoli
1/21/2007 9:03:26 PM

Hi, I managed to get the value of a label control within a ChildGridview.

  1. ChildGridView_RowDataBound - assigns the rowindex to selectbutton.commandArgument property in each row.
  2. ChildGridView_RowCommand - the selectbutton finds a label in the ChildGridView using the rowindex from the commandArgument

Protected Sub ChildGridView_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs)
        Dim selectbutton As LinkButton
        selectbutton = CType(e.Row.FindControl("selectbutton"), LinkButton)
        If selectbutton IsNot Nothing Then
            selectbutton.CommandArgument = e.Row.RowIndex.ToString
        End If
    End Sub 

    Protected Sub ChildGridView_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs)

        If e.CommandName = "Select" Then
            gridviewchild = CType(sender, GridView)
            Dim rowIndex As Integer = Convert.ToInt32(e.CommandArgument)
            Dim label3 As Label = DirectCast(gridviewchild.Rows(rowIndex).FindControl("label3"), Label)
        End If
    End Sub


2/10/2007 9:36:01 AM

Thank you for your sample code I appreciate it.

Unfortunately the Child GridView use Template Fields in order to make all rows editable. When the user is tabbing through the TextBoxes I am trying to find the value of the row that I am on. But since no Row event is fired at this point, this is where my problem comes in finding the row index so I can get the value the user just entered. I use this value to calculate the next field.



Peace in Christ
Marco Napoli
2/16/2007 1:54:21 AM

You can find the row by using the GridViewRow = (GridViewRow)Sender.Parent.Parent;
2/16/2007 2:11:48 AM
Oops, I missed the part where you said there is no button or event.. I can't think of how you could do it with no event. I suppose you could loop through the entire grid and values to see if there were any changes
2/16/2007 2:43:27 AM
Events will fire if you declaritively assign  the events to the data controls ie. <asp:datalist onitemcommand="datalist1_itemCommand" ... you must do this on both parent and nested data controls in order to assign the correct method to the data control event. From the itemcommand (in either parent or nested data control) you can acces child controls via the e.item.findcontrol("itemID")  See an example below.


 Public WithEvents datalist1 As DataList

    Protected Sub DetailsView1_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles DetailsView1.DataBound
        If DetailsView1.PageCount = 0 Then

        End If

    End Sub

    Protected Sub DetailsView1_ItemCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewCommandEventArgs)

    End Sub

    Protected Sub datalist1_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataListCommandEventArgs) 
        Select Case e.CommandName
            Case "UpdateArea"
                SqlAreas.UpdateParameters("area").DefaultValue = CType(e.Item.FindControl("TextBox2"), TextBox).Text
                SqlAreas.UpdateParameters("id").DefaultValue = e.CommandArgument
                datalist1.EditItemIndex = -1
            Case "deleteArea"
                SqlAreas.DeleteParameters("id").DefaultValue = e.Item.ItemIndex
            Case "InsertArea"
                SqlAreas.InsertParameters("area").DefaultValue = CType(e.Item.FindControl("TextBox1"), TextBox).Text
            Case "CancelArea"
                datalist1.EditItemIndex = -1
            Case "EditArea"
                datalist1.EditItemIndex = e.Item.ItemIndex
        End Select
    End Sub

1/30/2009 5:00:39 AM

Similar Artilces:

Issue with getting values from child controls in a gridview, to use for the update using a SQLDataSource control
Hi all, I have a gridview bound with a SQLDataSource. I am using the Update feature of the SQLDataSource to update a SQL Server database with values entered into the gridview. However I am not getting it to work. I believe this is due to the controls that contain the user entries are not the gridview itself, but rather child controls within the gridview. I have been using the names of the actual controls but nothing happens. Upon submit, the screen returns blank, and the database is not updated. Here is some code:   <asp:GridView ID="GridEditSettlement" runat="server" AutoGenerate...

gridview control in another gridview control
Hi ia have a questioni have a gridview control which contains button in one my question is i need another gridview to be placed in the  first gidviewso that when i click on the button the second gridview will populate the my question is how to place second gridview in first gridview.or is there any approach like first grid itself acting as parent and child.please help me  Hi sirikalavalapalli:                I think nested gridview will help you. Check this link and it will show you how...

how to pass the controls from child gridview to parent gridview in c# to pass the controls from child gridview to parent gridview in c# Hi:   You can get the controls in ChildGridView like below. So if you want to get the reference of the control in ParentGridView, you can put them in ParentGridView event handler(like OnRowEditing .etc)        GridViewRow parent_row = ParentGridView.Rows[parent_index];     GridView ChildGridiView =         (GridView)parent_row.FindControl("ChildGridView");     GridViewRow child_row = ChildGridiView...

GridView and Javascript
Hey All, I need help from  you. I have a GridView. In the  Edit Item template of the first Column I have a textbox, an user control and hidden field. When I click on the user control it  opens a pop up from which I can choose the required value. The text value is populated in the textbox and Id in the hidden field. Here's the code for edit template.         <EditItemTemplate>                        <table cellpaddin...

Gridview control embedded in another gridview control
I am writing an ambulance crew scheduling application on the web and I need some help completing the last part.  I have an access database that has three tables: user table, shift table (describing the shifts available), and a schedule table (that stores shift by shift_id and user by user_id).  I have a gridview control that will display the available shifts but I cannot get the embedded gridview control that will display the user that is signed up for each shift to display because I cannot figure out how to use the OnRowDataBound method.  I need a simple VB example of how to...

get child control to gridview
Hi,   I need to get child control to the gridview during edit mode. In fact I have a date field, during edit mode, the date will be in a textbox, beside the textbox is an image button. For what I need is if user click on the button, it will popup a calendar. After user selected the date, then calendar will automatic close. And that selected date will be place into the textbox. So, how do I get control to the image button which is in edititemtemplate? Is anyone can help me!! Calvin...

using javascript getting value from textbox when edit button is clicked and both controls are present in gridview control
Hi All using javascript I want to get value  from textbox when edit button is clicked and both controls that is texbox and button are present in gridview control .Alok Hi aloksinha83, Please see this post: Thanks,Qin Dian TangMicrosoft Online Community SupportPlease remember to mark the replies as answers if they help and unmark them if they provide no help....

There is a Gridview Control in the tmplate field of another GridView Control.
    For instance,a gridview displays the information of the  students in a class.A table is recording the information except their mark.There is another table recording the mark of the students whose foreign key is the primary key of the previous table.   string strSQLconnection=".................."; SqlConnection sqlCononection=new SqlConnection(strSQLconnection); SqlCommand sqlCommand=new SqlCommand("select * from stuendent where classID=1",sqlConnection); SqlConnection.Open(); SqlDataReader reader=sqlCommand.ExecuteReader(); GridVie...

Child GridView control does not get displayed
I have a schopping cart Gridview that is bound to a SQL table. When I click add button on the control, I then add the item to a temp schopping cart table through RowCommand event, which works well. I want to use the bound functionalities (Update, delete, etc..) of the child Gridview control which is also bound, but the SQL query is depends on an item within a row of the Parent Gridview. Parent:<asp:GridView ID="GridView5" runat="server" AllowPaging="True"                 &nbs...

Getting the control id of a control inside gridview control
 uhmm.. a little bit confusing regarding my subject because i dont know how to say the way my problem is how can i get the id of a control (e.g. textbox) inside the gridview... and the textbox is in the templatefield... is there any way i can get its id??  hoping i could get a reply as soon as possible... Regards,MhaeyPlease remember to click “Mark as Answer” on the post that helps you.. =) What do you want's to do by getting the id of the Text box? Do you want's to find particular Textbox with certain id ? Kamran ShahidSr. Software Engineer(MCP,,MC...

OnBubbleEvent with Button (child control) in GridView (parent control)
I have a button (created at runtime) inside the gridview.  I'm having a hard time telling the grid view that row 1 (the row which was selected when the button is clicked) is selected. Here's my code so far:  protected void ContentsGrid_RowCreated(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { counter++; //Display Imagebutton for View in column 1 ImageButton imgView = new ImageButton(); imgView.ID = "imgView" + c...

Nested GridViews
I have nested one GridView inside another so that each row in the parent has zero or more children. The child GridViews shows up inline with the parent row.  How do I get it to position itself below the parent row?   Hi:   I'm not quite sure what do you want to achieve and think it's better to clarify your requirement at first. Could you please elaborate your problem and maybe a screenshot is helpful to make it clear.   FYI, you can consider to add rows in parent GridView's PreRender event handler if my understanding is correct: ...

How to add values to template control fields textbox control in GridView..
Hi all,    <asp:GridView ID="GridView1" EnableViewState="true" DataKeyNames="LicenseTemplateID"                       runat="server" AutoGenerateColumns="False" OnSelectedIndexChanged="GridView1_SelectedIndexChanged"                       Width="345px">                       <Columns>                           <asp:Templa...

get edit template control value in Gridview
 I have a gridview that has two edit item templates which have controls textbox and a label I want to get the value of the controls when I update the gridview and add that to the update parameters. I keep getting object reference not set to an instance of an object for the label and the textbox. I cannot figure this out.I can't believe this has stumped me as I know I have done it before and it is very simple I must be over looking something. here is my vb here is my vb Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewU...

Web resources about - GridView child of GridView - How to get value of a Template Control in the Child GridView -

GridView SelectedItem Binding Gotcha in WinRT
Last night when I was doing some WinRT hacking I was trying to setup databinding to the selected item in the GridView control and I ran into ...

CNW Group
Home Services Beyond the Wire About CNW Financials Webcasts Events My CNW All News Releases Advanced Search Gridview Latest News Releases All ...

CNW Group
... Services Beyond the Wire About CNW my CNW CNW Access CNW Directories Financials Webcasts Events my CNW All News Releases Advanced Search Gridview ...

CNW Group
Home Services Beyond the Wire About CNW Financials Webcasts Events My CNW All News Releases Add a Filter Gridview Latest News Releases All Today ...

New CmdLets of Powershell 2.0
New CmdLets of Powershell 2.0

Price Drop: Softbox
... objects- create product reflection- changing the background with something more interestingUse it as:- softbox- honeycomb softbox- gridview ...

Profile.aspx: ASP Alliance
.NET,ASP,ASP.NET,SQL,XML,HTML,ADO,ADO.NET,JavaScript,JScript,CSharp,VBScript and VB tutorials from AspAlliance.

Quick Answers - CodeProject
Questions - Free source code and tutorials for Software developers and Architects.; Updated: 25 Oct 2012 - Upcoming stories is a community based news site edited by our members. It specialises in .NET development techniques, technologies and tools including ...

View Features - ExtendASP
Call 847-681-9827 or Request a Demo View Features Testimonials Pricing About Us Coming Soon ExtendASP exposes every feature, more than any other ...

Resources last updated: 1/22/2016 8:57:31 PM