473,698 Members | 2,873 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Cells.Controls

This is the code of a DataGrid:

<asp:DataGrid ID="dgCart" OnEditCommand=" EditCart"
OnCancelCommand ="CancelUpda te" OnDeleteCommand ="DeleteFromCar t"
OnItemCommand=" ButtonClicked" OnPreRender="Ch angeWidth"
OnUpdateCommand ="UpdateCart " AutoGenerateCol umns="false"
runat="server">

<Columns>

<asp:TemplateCo lumn HeaderText="S.N .">
<ItemTemplate >
<asp:Label ID="lblSNo" Text='<%# Container.ItemI ndex + 1 %>'
runat="server"/>.
</ItemTemplate>
</asp:TemplateCol umn>

<asp:TemplateCo lumn HeaderText="ID" >
<ItemTemplate >
<asp:Label ID="lblPID" Text='<%# Container.DataI tem("ProductID" ) %>'
runat="server"/>
</ItemTemplate>
</asp:TemplateCol umn>

<asp:TemplateCo lumn HeaderText="NAM E">
<ItemTemplate >
<asp:Label ID="lblPName" Text='<%# Container.DataI tem("ProductNam e")
%>' runat="server"/>
</ItemTemplate>
</asp:TemplateCol umn>

<asp:TemplateCo lumn HeaderText="DES CRIPTION">
<ItemTemplate >
<asp:Label ID="lblDescript ion" Text='<%#
Container.DataI tem("ProductDes cription") %>' runat="server"/>
</ItemTemplate>
</asp:TemplateCol umn>

<asp:TemplateCo lumn HeaderText="PRI CE">
<ItemTemplate >
<asp:Label ID="lblPrice" Text='<%# Container.DataI tem("UnitPrice" ) %>'
runat="server"/>
</ItemTemplate>
</asp:TemplateCol umn>

<asp:BoundColum n DataField="Quan tity" HeaderText="QTY ."/>

<asp:TemplateCo lumn HeaderText="SUB-TOTAL">
<ItemTemplate >
<asp:Label ID="lblSubTotal " Text='<%# Container.DataI tem("Total") %>'
runat="server"/>
</ItemTemplate>
</asp:TemplateCol umn>

<asp:EditComman dColumn EditText="EDIT" CancelText="CAN CEL"
HeaderText="EDI T" UpdateText="UPD ATE"/>

<asp:ButtonColu mn CommandName="de lete" HeaderText="DEL ETE"
Text="DELETE"/>

</Columns>

</asp:DataGrid>

Note that only the *QTY* column is a BoundColumn. Hence when a user
clicks *EDIT*, this column becomes editable i.e. it changes to a
TextBox.

This is the UpdateCommand event function named *UpdateCart*

Sub UpdateCart(obj As Object, ea As DataGridCommand EventArgs)
..........
..........
dgCart.DataBind ()

Response.Write( "Text: " & CType(ea.Item.C ells(5).Control s(0),
TextBox).Text & "<br>")
Response.Write( "Val: " & CType(ea.Item.C ells(0).Control s(0),
Label).Text)
End Sub

The first Response.Write line outputs the correct text. So for e.g.
when in the editable mode, if a user enters 10 in the TextBox of the
BoundColumn, the first Response.Write correctly outputs 10.

Using the second Response.Write line, I want to retrieve the text of
the row under the *S.N.* column that was just updated but it generates
the following error:

Unable to cast object of type 'System.Web.UI. LiteralControl' to type
'System.Web.UI. WebControls.Lab el'.

If I am not mistaken, ASP.NET adds a LiteralControl on either side of
a Label control. In other words, a Label control is always sandwiched
between 2 LiteralControls . Please correct me if I am wrong. & I guess
that's the reason why the above error gets thrown but if I change the
index of the Cells in the second Response.Write line from 0 to 1 or 2
or 3 or 4 to retrieve the *ID*, *NAME*, *DESCRIPTION* & *PRICE*
respectively, then ASP.NET still generates the above error!

Now why changing the Cells index in the second Response.Write line
from 0 to 1 or 2 or 3 or 4 generating the same error?

I know I can use FindControl instead of using the Cells & Controls
index but I would like to know what's causing the above error when the
Cells index is changed from 0 to 1 or 2 or 3 or 4.

Mar 12 '07 #1
0 1491

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

Similar topics

0
1226
by: Kumar | last post by:
try this Dim mycheck As CheckBox = CType(dgWelcomePacks.Items (i).Cells(7).Controls(1), CheckBox) regards, Kumar. >-----Original Message-----
5
2372
by: Ariel Gimenez | last post by:
Morning! After several hours breaking my mind, finally my code works, but i think is trash-code, can someone tellme how is the correct way to access the value of my cells within a datagrid?... in some cases i can access the values with e.Item.Cells.Text, but in other cases i have to do weird thinks like the following: TextBox pp; //I know...disgusting!!! pp= (TextBox) e.Item.Cells.Controls ; int id = Convert.ToInt32(pp.Text );
2
3677
by: JDavies | last post by:
Hi All I am dynamically Creating DropDownList boxes for a Survey form. These DropdownLists are added to Table Cells programatically. I tried to loop thru the controls on the form but it doesnt seem to work right, the loop appears below: for each cntl in page.controls(1).controls ddlId = cntl.Id
1
1789
by: Stephan Bour | last post by:
I need to build a string from the content of a datalist containing a nested datagrid. This properly returns the data from the first cell in the datagrid: String first = GridItem.Cells.Text; However, I can't seem to apply the same technique to the datalist as ³Cells² is not implemented. How does one retrieve the text from a datalist cell then? Thanks, Stephan.
2
2701
by: Craig Buchanan | last post by:
Is there a way to add a row to a datagrid during the ItemDataBound event? I would like to add a 'header' row before the start of a group of rows. Thanks, Craig Buchanan
4
1725
by: EMW | last post by:
For my ASP.NET program I want to use the datagrid as a sort of planning tool. Based on the information in a XML file, a cell of the datagrid must show an image... Well, this is what I would like it to do, but is it possible and how can I place an image in a web-datagrid cell? rg,
0
1634
by: cwbp17 | last post by:
I'm having trouble updating individual datagrid cells. Have two tables car_master (columns include Car_ID, YEAR,VEHICLE) and car_detail (columns include Car_ID,PRICE,MILEAGE,and BODY);both tables have a FK relationship on CAR_ID so the oracledataadapter1 select statement(CommandText) is: select car_master.car_id, car_master.year,car_master.vehicle,car_detail.car_id AS EXPR1,
1
5912
by: jobs | last post by:
Can somebody tell me why Jobno and Value BoundFields are not available during the command SaveParm ? i enter text into the box for Value and hit the Save button, but all I see is the Parmvalue. Thanks in advance for any help or information!!
1
2055
by: bgernon | last post by:
I have a table that consists of two rows with three cells each row. The cells contain textboxes. I am able to successfully add a new row with textboxes when a button is clicked. The problem is retaining the newly added row with the filled in textboxes on the next button click. I think I am handling my viewstate incorrectly. This code adds the new row: Private Sub addRowsInTable() Dim TextID As Integer Dim TextIDCount...
0
8683
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9170
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
9031
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
8876
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...
1
6531
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
4372
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...
1
3052
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
2
2341
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.