473,768 Members | 2,926 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Strange Datagrid Update Problem

Hi,

I'm having a strange problem with the update function of a datagrid:

I have a datagrid, the first column lists item names from a database.
Second column is an EditCommandColu mn, and then I have a couple of
button columns after that to deal with row deletes etc.

The problem is occuring in the method that I have specified should
deal with the update event:

protected void nameEditUpdate( object sender, DataGridCommand EventArgs
e)

Because the first column I know contains the item that is getting
updated, I try:

tmpTextBox = (TextBox)e.Item .Cells[0].Controls[0];

To get the control, before looking at its Text property. However,
when I try this I get:

System.InvalidC astException: Specified cast is not valid.

So to try and figure out what is going on, I have tried looking at the
type being returned by e.Item.Cells[0].Controls[0], which turns out to
be type System.Web.UI.L iteralControl, the name and text properties of
it are blank. This has just confused me even more.

Anyone have any idea just what might be going on?

Appreciated!
Nov 19 '05 #1
2 1085
Use FindControl instead of hard coding the position in the Controls collection.
Otherwise iterate over the Controls collection until you find your TextBox
(I bet it's at position Controls[1]). What's happening is that there's whitespace
in your template after the <ItemTemplate > and before your <asp:TextBox> and
that's the LiteralControl you're seeing.

-Brock
DevelopMentor
http://staff.develop.com/ballen
Hi,

I'm having a strange problem with the update function of a datagrid:

I have a datagrid, the first column lists item names from a database.
Second column is an EditCommandColu mn, and then I have a couple of
button columns after that to deal with row deletes etc.

The problem is occuring in the method that I have specified should
deal with the update event:

protected void nameEditUpdate( object sender, DataGridCommand EventArgs
e)

Because the first column I know contains the item that is getting
updated, I try:

tmpTextBox = (TextBox)e.Item .Cells[0].Controls[0];

To get the control, before looking at its Text property. However,
when I try this I get:

System.InvalidC astException: Specified cast is not valid.

So to try and figure out what is going on, I have tried looking at the
type being returned by e.Item.Cells[0].Controls[0], which turns out to
be type System.Web.UI.L iteralControl, the name and text properties of
it are blank. This has just confused me even more.

Anyone have any idea just what might be going on?

Appreciated!


Nov 19 '05 #2
Thanks Brock. I would never have guessed that whitespace would be a
member of the controls collection!

On Sat, 11 Jun 2005 07:06:34 -0700, Brock Allen
<ba****@NOSPAMd evelop.com> wrote:
Use FindControl instead of hard coding the position in the Controls collection.
Otherwise iterate over the Controls collection until you find your TextBox
(I bet it's at position Controls[1]). What's happening is that there's whitespace
in your template after the <ItemTemplate > and before your <asp:TextBox> and
that's the LiteralControl you're seeing.

-Brock
DevelopMento r
http://staff.develop.com/ballen


Nov 19 '05 #3

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

Similar topics

4
5357
by: Glenn Owens | last post by:
I have a DataGrid web control which I've dynamically populated with template columns to be used for bulk-editting. Generally, all of the columns are textbox and/or dropdownlist child controls. Currently everything is working. I can find the updated rows/columns by parsing the posted data collection against the DataGrid DataSource. However, when there is a large amount of DataGridItems (rows) the update processing can take a while. ...
1
4338
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):
14
2131
by: Lars Netzel | last post by:
A little background: I use three Datagrids that are in a child parent relation. I Use Negative Autoincrement on the the DataTables and that's workning nice. My problem is when I Update these grid and write to the database and I set the new Primary Keys and related Fields to the new asigned atuonumbers in the Access.
9
2728
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()
0
9407
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
10171
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
10015
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...
0
9842
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8840
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...
1
7384
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5280
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5425
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3931
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.