A DataGrid displays 8 columns - ProductID, ProductName, Description,
Price, Quantity, Sub-Total, Edit & Delete. *Edit* is a
EditCommandColumn, *Delete* is a ButtonColumn & *Quantity* is a
BoundColumn. If the *Edit* link is clicked, the *Quantity* column
changes to the editable mode with a TextBox & the text under the
*Edit* column of the corresponding row gets replaced by 2 hyperlinks -
Update & Cancel.
This is the DataGrid code:
<asp:DataGrid ID="dgCart" OnEditCommand="EditCart"
OnCancelCommand="CancelUpdate" OnDeleteCommand="DeleteFromCart"
OnUpdateCommand="UpdateCart" runat="server">
<Columns>
<asp:TemplateColumn HeaderText="ProductID">
<ItemTemplate>
<asp:Label ID="lblPID" Text=<%# Container.DataItem("ProductID") %>
runat="server"/>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="ProductName">
<ItemTemplate>
<asp:Label ID="lblPName" Text=<%# Container.DataItem("ProductName") %>
runat="server"/>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Description">
<ItemTemplate>
<asp:Label ID="lblDescription" Text=<%#
Container.DataItem("ProductDescription") %runat="server"/>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Price">
<ItemTemplate>
<asp:Label ID="lblPrice" Text=<%# Container.DataItem("UnitPrice") & ".
00" %runat="server"/>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn HeaderText="Quantity" DataField="Quantity"/>
<asp:TemplateColumn HeaderText="Sub-Total">
<ItemTemplate>
<asp:Label ID="lblSubTotal" Text=<%# Container.DataItem("UnitPrice") *
Container.DataItem("Quantity") & ".00" %runat="server"/>
</ItemTemplate>
</asp:TemplateColumn>
<asp:EditCommandColumn EditText="Edit" CancelText="Cancel"
HeaderText="Edit" UpdateText="Update"/>
<asp:ButtonColumn CommandName="delete" HeaderText="Delete"
Text="Delete" runat="server"/>
</Columns>
</asp:DataGrid>
Assume that the DataGrid displays 5 rows. Also assume that under the
*Price* column, the 4th item is 200 & under the *Quantity* column, the
4th item is 10. To retrieve these 2 values in the OnUpdateCommand
event function of the DataGrid, the following code will suffice:
============================
Sub UpdateCart(obj As Object, ea As DataGridCommandEventArgs)
Response.Write("Price: " & CType(ea.Item.Cells(3).Controls(1),
Label).Text)
Response.Write("Quantity: " & CType(ea.Item.Cells(4).Controls(0),
TextBox).Text)
End Sub
============================
The above code correctly retrieves the price as 200 & the quantity as
10 but what I don't understand is to get the price, why I have to use
Controls(1) but to get the quantity, I have to use Controls(0). Can
someone please explain me this?
Moreover if I use Controls(0) to retrieve the price like this:
============================
Response.Write("Price: " & CType(ea.Item.Cells(3).Controls(0),
Label).Text)
============================
then ASP.NET generates the following error:
Unable to cast object of type 'System.Web.UI.LiteralControl' to type
'System.Web.UI.WebControls.Label'.
On the other hand, if I use Controls(1) to retrieve the quantity like
this:
============================
Response.Write("Quantity: " & CType(ea.Item.Cells(4).Controls(1),
TextBox).Text)
============================
then ASP.NET generates the following error:
Specified argument was out of the range of valid values. Parameter
name: index.
How do I understand when to use Controls(0) & when to use Controls(1)?
Someone please explain me this. I am getting too confused. 2 2292
On Feb 23, 6:49 am, r...@rediffmail.com wrote:
A DataGrid displays 8 columns - ProductID, ProductName, Description,
Price, Quantity, Sub-Total, Edit & Delete. *Edit* is a
EditCommandColumn, *Delete* is a ButtonColumn & *Quantity* is a
BoundColumn. If the *Edit* link is clicked, the *Quantity* column
changes to the editable mode with a TextBox & the text under the
*Edit* column of the corresponding row gets replaced by 2 hyperlinks -
Update & Cancel.
This is the DataGrid code:
<asp:DataGrid ID="dgCart" OnEditCommand="EditCart"
OnCancelCommand="CancelUpdate" OnDeleteCommand="DeleteFromCart"
OnUpdateCommand="UpdateCart" runat="server">
<Columns>
<asp:TemplateColumn HeaderText="ProductID">
<ItemTemplate>
<asp:Label ID="lblPID" Text=<%# Container.DataItem("ProductID") %>
runat="server"/>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="ProductName">
<ItemTemplate>
<asp:Label ID="lblPName" Text=<%# Container.DataItem("ProductName") %>
runat="server"/>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Description">
<ItemTemplate>
<asp:Label ID="lblDescription" Text=<%#
Container.DataItem("ProductDescription") %runat="server"/>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Price">
<ItemTemplate>
<asp:Label ID="lblPrice" Text=<%# Container.DataItem("UnitPrice") & ".
00" %runat="server"/>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn HeaderText="Quantity" DataField="Quantity"/>
<asp:TemplateColumn HeaderText="Sub-Total">
<ItemTemplate>
<asp:Label ID="lblSubTotal" Text=<%# Container.DataItem("UnitPrice") *
Container.DataItem("Quantity") & ".00" %runat="server"/>
</ItemTemplate>
</asp:TemplateColumn>
<asp:EditCommandColumn EditText="Edit" CancelText="Cancel"
HeaderText="Edit" UpdateText="Update"/>
<asp:ButtonColumn CommandName="delete" HeaderText="Delete"
Text="Delete" runat="server"/>
</Columns>
</asp:DataGrid>
Assume that the DataGrid displays 5 rows. Also assume that under the
*Price* column, the 4th item is 200 & under the *Quantity* column, the
4th item is 10. To retrieve these 2 values in the OnUpdateCommand
event function of the DataGrid, the following code will suffice:
============================
Sub UpdateCart(obj As Object, ea As DataGridCommandEventArgs)
Response.Write("Price: " & CType(ea.Item.Cells(3).Controls(1),
Label).Text)
Response.Write("Quantity: " & CType(ea.Item.Cells(4).Controls(0),
TextBox).Text)
End Sub
============================
The above code correctly retrieves the price as 200 & the quantity as
10 but what I don't understand is to get the price, why I have to use
Controls(1) but to get the quantity, I have to use Controls(0). Can
someone please explain me this?
Moreover if I use Controls(0) to retrieve the price like this:
============================
Response.Write("Price: " & CType(ea.Item.Cells(3).Controls(0),
Label).Text)
============================
then ASP.NET generates the following error:
Unable to cast object of type 'System.Web.UI.LiteralControl' to type
'System.Web.UI.WebControls.Label'.
On the other hand, if I use Controls(1) to retrieve the quantity like
this:
============================
Response.Write("Quantity: " & CType(ea.Item.Cells(4).Controls(1),
TextBox).Text)
============================
then ASP.NET generates the following error:
Specified argument was out of the range of valid values. Parameter
name: index.
How do I understand when to use Controls(0) & when to use Controls(1)?
Someone please explain me this. I am getting too confused.
Can someone please explain me?
On Feb 24, 5:47 pm, r...@rediffmail.com wrote:
On Feb 23, 6:49 am, r...@rediffmail.com wrote:
A DataGrid displays 8 columns - ProductID, ProductName, Description,
Price, Quantity, Sub-Total, Edit & Delete. *Edit* is a
EditCommandColumn, *Delete* is a ButtonColumn & *Quantity* is a
BoundColumn. If the *Edit* link is clicked, the *Quantity* column
changes to the editable mode with a TextBox & the text under the
*Edit* column of the corresponding row gets replaced by 2 hyperlinks -
Update & Cancel.
This is the DataGrid code:
<asp:DataGrid ID="dgCart" OnEditCommand="EditCart"
OnCancelCommand="CancelUpdate" OnDeleteCommand="DeleteFromCart"
OnUpdateCommand="UpdateCart" runat="server">
<Columns>
<asp:TemplateColumn HeaderText="ProductID">
<ItemTemplate>
<asp:Label ID="lblPID" Text=<%# Container.DataItem("ProductID") %>
runat="server"/>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="ProductName">
<ItemTemplate>
<asp:Label ID="lblPName" Text=<%# Container.DataItem("ProductName") %>
runat="server"/>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Description">
<ItemTemplate>
<asp:Label ID="lblDescription" Text=<%#
Container.DataItem("ProductDescription") %runat="server"/>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Price">
<ItemTemplate>
<asp:Label ID="lblPrice" Text=<%# Container.DataItem("UnitPrice") & ".
00" %runat="server"/>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn HeaderText="Quantity" DataField="Quantity"/>
<asp:TemplateColumn HeaderText="Sub-Total">
<ItemTemplate>
<asp:Label ID="lblSubTotal" Text=<%# Container.DataItem("UnitPrice") *
Container.DataItem("Quantity") & ".00" %runat="server"/>
</ItemTemplate>
</asp:TemplateColumn>
<asp:EditCommandColumn EditText="Edit" CancelText="Cancel"
HeaderText="Edit" UpdateText="Update"/>
<asp:ButtonColumn CommandName="delete" HeaderText="Delete"
Text="Delete" runat="server"/>
</Columns>
</asp:DataGrid>
Assume that the DataGrid displays 5 rows. Also assume that under the
*Price* column, the 4th item is 200 & under the *Quantity* column, the
4th item is 10. To retrieve these 2 values in the OnUpdateCommand
event function of the DataGrid, the following code will suffice:
============================
Sub UpdateCart(obj As Object, ea As DataGridCommandEventArgs)
Response.Write("Price: " & CType(ea.Item.Cells(3).Controls(1),
Label).Text)
Response.Write("Quantity: " & CType(ea.Item.Cells(4).Controls(0),
TextBox).Text)
End Sub
============================
The above code correctly retrieves the price as 200 & the quantity as
10 but what I don't understand is to get the price, why I have to use
Controls(1) but to get the quantity, I have to use Controls(0). Can
someone please explain me this?
Moreover if I use Controls(0) to retrieve the price like this:
============================
Response.Write("Price: " & CType(ea.Item.Cells(3).Controls(0),
Label).Text)
============================
then ASP.NET generates the following error:
Unable to cast object of type 'System.Web.UI.LiteralControl' to type
'System.Web.UI.WebControls.Label'.
On the other hand, if I use Controls(1) to retrieve the quantity like
this:
============================
Response.Write("Quantity: " & CType(ea.Item.Cells(4).Controls(1),
TextBox).Text)
============================
then ASP.NET generates the following error:
Specified argument was out of the range of valid values. Parameter
name: index.
How do I understand when to use Controls(0) & when to use Controls(1)?
Someone please explain me this. I am getting too confused.
Can someone please explain me?- Hide quoted text -
- Show quoted text -
Isn't there anyone who can explain me this? I thought this must be one
of the most basic questions in ASP.NET! This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: TD |
last post by:
This is the code under a command button -
Dim ctl As Control
For Each ctl In Me.Controls
If ctl.BackColor <> RGB(255, 255, 255) Then
ctl.BackColor = RGB(255, 255, 255)
End If
Next ctl
|
by: Mark Johnson |
last post by:
Sometimes Controls that have been added to a GroupBox do not show up.
What I am doing :
1) I am not using the designer, but create all the Controls per hand:
groupBoxProdukt_01 = new...
|
by: Steve Drake |
last post by:
All,
I have a CONTROL that contains 1 control (Control ONE), the 1 control that
it can contain 1 or 2 control (Control A and B).
Control A, raises and event and Control ONE receives this event...
|
by: Robert Howells |
last post by:
Perhaps I'm just too new at this to pull it off, or perhaps it's just bad
architecture. I'd appreciate some feedback on the the wisdom (or lack
thereof) in attempting the following:
I'm not new...
|
by: Sacha Korell |
last post by:
I'm trying to load a drop-down list with all DropDownList control names from
another page.
How would I be able to find those DropDownList controls? The FindControl
method will only find a...
|
by: dhnriverside |
last post by:
Hi peeps,
I'm trying to create some controls textboxes at runtime, based on the number
of items in a IETreeView that are checked. That I can do, I've got a place
holder and I can create the...
|
by: Cor |
last post by:
Hi,
I start a new thread about a discussion from yesterday (or for some of us
this morning). It was a not so nice discussion about dynamically removing
controls from a panel or what ever.
It...
|
by: Mike Bulava |
last post by:
I have created a base form that I plan to use throughout my application let
call the form form1. I have Built the project then add another form that
inherits from form1, I add a few panel controls...
|
by: Arpan |
last post by:
Consider the following code which retrieves data from a SQL Server 2005
DB table & displays it in a DataGrid:
<script runat="server">
Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs)...
|
by: Ryan |
last post by:
Ok.. I have a form with lots of stuff on it; a tool strip panel, menu strip,
data binding elements (dataset, binding source, table adapter), tab control
with 7 tab pages, each page contains a...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
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...
|
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,...
|
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...
|
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: 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...
|
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...
| |