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" AutoGenerateColumns="False" BackColor="Navy"

BorderColor="IndianRed" BorderStyle="Solid" Font-Names="Verdana" Font-Size="X-Small" DataSourceID="SqlDataSource_grid" AllowPaging="True" AllowSorting="True" ForeColor="White" DataKeyNames="legid">


<asp:CommandField ShowEditButton="True" CancelImageUrl="~/App_Graphics/quit.gif" CancelText="" EditImageUrl="~/App_Graphics/EditGrid.GIF" EditText="" UpdateImageUrl="~/App_Graphics/save.gif" UpdateText="" ButtonType="Image" />

<asp:BoundField DataField="StartDate" HeaderText="Start Date" ReadOnly="True" />

<asp:BoundField DataField="EndDate" HeaderText="End Date" ReadOnly="True" />

<asp:BoundField DataField="CounterpartDealRef" HeaderText="CP Deal Ref" ReadOnly="True" />


<asp:TemplateField HeaderText="Preliminary Settlement Price" ><ItemTemplate>

<asp:Label ID=lblPreliminary runat=server Text='<%# Bind("PrimarySettlementPrice") %>' />



<asp:TextBox runat="server" ID=txtPrimaryPrice Text='<%# Bind("PrimarySettlementPrice") %>'></asp:TextBox>




<asp:TemplateField HeaderText="Agreed Settlement Price"><ItemTemplate>

<asp:Label ID=lblAgreed runat=server Text='<%# Bind("AgreedSettlementPrice") %>' />



<asp:TextBox runat="server" ID=txtAgreedPrice Text='<%# Bind("AgreedSettlementPrice") %>'></asp:TextBox>





<asp:BoundField DataField="Volume" HeaderText="Volume" ReadOnly="True" />

<asp:BoundField DataField="Price" HeaderText="Price" ReadOnly="True" />

<asp:BoundField DataField="TotalVolume" HeaderText="Total Volume" ReadOnly="True" />

<asp:BoundField DataField="InstrumentName" HeaderText="Instrument" ReadOnly="True" />

<asp:BoundField DataField="NominalValue" HeaderText="Nominal Value" ReadOnly="True" />

<asp:BoundField DataField="Strike" HeaderText="Strike" ReadOnly="True" />

<asp:BoundField DataField="DeliveryDate" HeaderText="Delivery Date" ReadOnly="True" />

<asp:TemplateField HeaderText="LegId" SortExpression="LegId">


<asp:Label ID="lblLegID" runat="server" Text='<%# Bind("LegId") %>'></asp:Label>



<asp:TextBox runat="server" ID=txtLegID Text='<%# Bind("LegId") %>'></asp:TextBox>







<RowStyle BackColor="#FFFF66" ForeColor="#333333" />

<EditRowStyle BackColor="#FFFF66" Font-Names="Verdana" Font-Size="X-Small" ForeColor="#333333" />

<PagerStyle ForeColor="White" />

<AlternatingRowStyle BackColor="White" ForeColor="#333333" />


&nbsp;<br />


<asp:SqlDataSource ID="SqlDataSource_grid" runat="server" ConnectionString="<%$ ConnectionStrings:DealCaptureDev %>" SelectCommand="sp_get_single_deal" SelectCommandType="StoredProcedure" UpdateCommand="Update trDealLeg Set PrimarySettlementPrice=@primarysettlement, AgreedSettlementprice=@agreedsettlement, LastUpdate=GetDate(), LastUpdateBy=Session('userid') Where LegID=@legid" EnableCaching="True" ConflictDetection="CompareAllValues" ProviderName="System.Data.SqlClient">


<asp:QueryStringParameter DefaultValue="" Name="dealnum" QueryStringField="deal"

Type="String" />



<asp:ControlParameter ControlID="txtLegId" PropertyName="Text" Name="legId" />

<asp:ControlParameter ControlID="txtPrimarySettlement" Name="primarysettlement" PropertyName="Text" />

<asp:ControlParameter ControlID="txtAgreedSettlement" Name="agreedsettlement" PropertyName="Text"/>

<asp:SessionParameter DefaultValue="" Name="userid" SessionField="userid" />




As seen above, controls such as txtPrimarySettlement are referenced but the update is not successful. The text boxes are within the GridEditSettlement gridview.  In the .aspx code I cannot use FindControl (at least I don't think it will work).

So the questions are:  Is it possible to reference the child controls, if so - how?  Is there another way to do this, such as in the vb code behind - in the either the gridview's RowUpdating event or the SQLDataSource's Updating event.

What is the best approach?  Anyone come up against this issue before?



11/22/2006 2:39:35 AM 29906 articles. 0 followers. Follow

1 Replies

Similar Articles

[PageSpeed] 39
Get it on Google Play
Get it on Apple App Store

You could try this way:

code in gridview:
                <asp:TemplateField HeaderText="company name" SortExpression="camcompany">
                        <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("camcompany") %>'></asp:TextBox>
                        <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("camcompany") %>'></asp:TextBox>
                        <asp:Label ID="Label2" runat="server" Text='<%# Bind("camcompany") %>'></asp:Label>

code in sqlDataSource:


                <asp:Parameter Name="camcompany" Type="String" />


 You can specify a row and access the controls within that row:

  Dim lastName As String = selectRow.Cells(1).Text

You can access the individual cells of the GridViewRow object by using the Cells property. If a cell contains other controls, you can retrieve a control from the cell by using the Controls collection of the cell. You can also use the FindControl method of the cell to find the control, if the control has an ID specified.

see for details.

Hope it helps.

Young Fang
11/28/2006 1:59:01 AM

Similar Artilces:

code for Custom paging without using sqldatasource control and sql datasource control for gridview...........
 code for Custom paging without using sqldatasource control and sql datasource control for gridview...........i need code for how to show all pagenumbers in gridview with custom paging in gridview..............It is very urgent................................. T.Ashok Kumar  suppose that we have a table like thisCountryId  identity intCountryTitle    nvarchar(50)you can use this sql command for paging the dataUSE [CyberOffice]GO/****** Object:  StoredProcedure [dbo].[CountryGetListPaged]    Script Date: 09/17/2008 14:01:06 ******/SET A...

Trying to use the FAQ " Sorting and paging in the GridView control when not using data source controls "Sorting and paging in the GridView control when not using..."
and I am not getting the results I had hoped for.  I keep getting a "Compiler Error Message: CS0123: No overload for 'AdhocJobGridView_PageIndexChanged' matches delegate 'System.EventHandler'".   Here is my event handling... protected void AdhocJobGridView_PageIndexChanged(object sender, GridViewPageEventArgs e){ try { AdhocJobGridView.DataSource = wsBaseInfoArray; AdhocJobGridView.PageIndex = e.NewPageIndex; AdhocJobGridView.DataBind(); }catch (Exception ex) {throw ex; }   Here is my aspx... <asp:GridView ID="AdhocJobGridView...

How to change the SQL used for the GridView, when using a control parameter in the datasource
I'm using a GridVeiw with and Access database. I want to allow users to select a date and then update the GridView to show only data entered after that date. So my question is, how do I modify the SQL used by the datagrid? I'm using a control parameter as part of my AccessDataSource and I think that is what I'm having trouble figuring out how to include. Here is my datasource, with the control parameter in the the GridView. The GridView works fine with these initial settings settings. <asp:AccessDataSource ID="AccessDataSourceForwView" runat="server" ConflictDetection="Compa...

Converting a gridView using an Sql Datasource to a gridview who is not using an SQL DataSource
How can i rewrite this page so that i doesnt make use of an SqlDataSource?  <%@ Control Language="C#" AutoEventWireup="true" CodeFile="LoginHistory.ascx.cs" Inherits="Private_UserControls_WebUserControl" %> <html> <head> <%--<link rel="stylesheet" href="BaldwinPortal.css" mce_href="BaldwinPortal.css" type="text/css" />--%> <title>Login History</title> </head> <body style="margin:0 0 0 0;padding:0 0 0 0"> ...

What control do I use (or do I not use a control at all...)
Okay so here's the story so far. I am making a blog to be incorporated into a website. Well, I'm doing the blog from scratch. I'm using MySQL to source all the data via MySQL .NET/Connector. Now while developing the script, I used DataReader and Response.Write to show the blog topics. Now that it has come to put it under a design (I'm using a Master Page for that), I've hit the problem. Response.Write shows all the topics before any of the design elements could be incorporated. So that (more or less) is out of question. So next I looked into the data presentation controls. I looked up GridVi...

Problem using two gridviews when using selected value of 1st to control datasource of 2nd
 I have a page with 2 gridviews. When you select a row in the first gridview, the DataKey of that row gets passed to the second gridview, which then displays a list of related records. I've read at that there can be issues around page lifecycle timing that can affect what I'm doing so I've tried to follow the instructions there. However, I'm still having problems.Here's the flow of what I want to happen:a) User clicks row in gridview1.b) Postback occurs.c) gridview1 is selected, gridview2 shows records relating...

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....

VB.NET Codebehind Code to Update SQL Server 2005 Using SQLDataSource Control?
Hi, I am a newbie in using ASP.NET 2.0 and ADO.NET.  I wrote a hangman game and want to record statistics at the end of each game.  I will create and update records in the database for each authenticated user as well as a record for the Anonymous, unauthenticated user.  After a win or loss has occurred, I want to programmatically use the SQLDataSource control to increment the statistics counters for the appropriate record in the database (note I don't want to show anything or get user input for this function). I need a VB.NET codebehind example that will show me how I sho...

GridView child of 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? GridViewParent-- GridViewChild (Edit - Template Field containing this GridViewChild)----- TextBox inside Template Field in GridViewChild. Thank you.Peace in ChristMarco Napoli 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...

Use property value in custom control child control
Hello, I am creating a custom control and I have the following property:   <Bindable(True), Category("Appearance"), DefaultValue(""), Localizable(True)> Property Text() As String     Get       Dim s As String = CStr(ViewState("Text"))       If s Is Nothing Then         Return String.Empty       Else         Return s       End If     End Get     Set(ByVal Value As String)       ViewState("Tex...

using controlS to control a gridview
This question is probably posted but i did not bother to look at 10,000+ posts so i am sorry. I've seen the tutorial where he builds a dataset and uses a gridview and controls the gridview with the drop down list box. What i am trying to do is to control the gridview with 2 drop down list boxes. First select the Country you life in and then the State. I've looked at the grid view properties but couldn't find where i can add another parameter. Is it possible to control a grid view (or any form of displaying the information) with more than 1 controller? Thank You.  ...

How do you get value from a control in GridView using a OnRowCommand?
In the GridView I have an OnRowCommand call that I use to highlight the selected row's background. But the main function is to get an id assigned to a label's text property and pass it to another method that build another gv as child set. Presently, it yells at me with a null exception error (System.NullReferenceException: Object reference not set to an instance of an object.) - can't handle this rejection... I will kidly appreciate any help, here is the code:protected void gvCommodity_RowCommand(object sender, GridViewCommandEventArgs e) {  if (e.CommandName == "S...

Datagrid(.net 1.1) to GridView(.net 2.0) and using the RowUpdating event how to extract the values from the controls.
Ok  This is the settings: I use a Viewgrid with only itemtemplate colums for example. <asp:TemplateField HeaderText="Test"><ItemTemplate><asp:Label id="LBL_Test" text='<%# DataBinder.Eval(Container.DataItem, "Test1") %>' runat="server" meta:resourcekey="LBL_TestResource1"></asp:Label></font></ItemTemplate> <EditItemTemplate><asp:TextBox ID="HDN_Test" Text='<%# DataBinder.Eval(Container.DataItem, "Test1") %>' Runat="server" meta:resourcekey="HDN_TestResource1" /></EditItemTemplate></asp:TemplateField>  The ...

Problem in Using DropDownList Control to select a selected row of SqlDataSource that is under GridView Control
Hi all,In my SQL Server Management Studio Express, I have a database "ChemDatabase" that has a table "LabData"  formatted in the following way: SampleID int PRIMARY KEY, SampleName nvarchar(25), ChemicalName, nvarchar(25), Concentration decimal(6.2) with 5 rows of records in this .dbo table. In my Visual Web Developer Express, I created a website "RPD-TCE" for extracting a row of record from the LabData table by using a DropDownList, a GridView and a SqlDataSource.  I want to click DropDownList to list one number of S...

Web resources about - Issue with getting values from child controls in a gridview, to use for the update using a SQLDataSource control -

Top Ranked Articles
Top Ranked Articles - Free source code and tutorials for Software developers and Architects.; Updated: 23 Feb 2013

Using The LINQDataSource
-*+There is a new datasource control available in Visual Studio that works in much the same way as the SQLDataSource and the ObjectDataSource. ...

Gabriel Mongeon
Archive - Gabriel Mongeon

M ore d otnet .NET Interview Questions, ASP.NET, C#, VB.NET, XML, SQL Check Out √ .NET NOTES OOPS in .NET .NET ...

Architectural Overview of the Windows Presentation Foundation Beta 1 Release
Introduction Windows Presentation Foundation Beta 1 Windows Integration New Features WinFX SDK Exploring the New Features Introducing "Express" ...

About Mikesdotnetting
I started this site as somewhere to store answers to bits and pieces that I see asked frequently in the forums at . Rather than type ...

Using MiniProfiler with SqlDataSource ASP.NET WebForms Control
public class ProfiledSqlDataSource : SqlDataSource{ protected override DbProviderFactory GetDbProviderFactory() { // get the "base" DbProviderFactory ...

ASP.NET Pivot Table - RadPivotGrid for ASP.NET AJAX
... reports. RadPivotGrid allows easy customization of all data reports. Try now! Use any declarative data source control (AccessDataSource, SqlDataSource, ...

Sign on
Sign On • Join • Forums Home User Name * Password * Remember me next time ( I forgot my password ) SUBMIT YOUR WTF Content Random Article All ...

ComboBox Sample
ComboBox is an ASP.NET AJAX control that, like the AutoCompleteExtender , combines the flexibility of a TextBox with a list of options that users ...

Resources last updated: 12/17/2015 4:43:06 PM