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 2286
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: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
| |