473,396 Members | 1,921 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

OnItemCreated?

Consider the following code which populates a DataGrid with the items
of a string array:

Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs)
If (ViewState("Colors") Is Nothing) Then
arrColors = New String(3) {"red", "blue", "pink", "white"}
ViewState("Colors") = arrColors
Else
arrColors = ViewState("Colors")
End If

'creating a DataTable with 2 columns - ID & Color,
'adding the DataTable to a DataSet, adding rows
'to the DataTable & finally populating the DataSet

dgColors.DataBind()
End Sub

Sub ChangeColor(ByVal obj As Object, ByVal ea As DataGridItemEventArgs)
Dim intIndex As Integer = ea.Item.ItemIndex
Response.Write("Index: " & intIndex & "<br>")
End Sub

<form runat="server">
<asp:DataGrid ID="dgColors" OnItemCreated="ChangeColor" runat="server">
<Columns>
<asp:TemplateColumn HeaderText="ID">
<ItemTemplate>
<asp:Label ID="lblID" runat="server"><%# Container.DataItem("ID")
%></asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="Color" HeaderText="COLOR"/>
<asp:EditCommandColumn HeaderText="CHANGE" EditText="EDIT"
UpdateText="CHANGE" CancelText="CANCEL"/>
</Columns>
</asp:DataGrid>
</form>

Note the Response.Write line in the sub "ChangeColor". That line
produces the following output:

Index: -1
Index: 0
Index: 1
Index: 2
Index: 3
Index: -1

Now where from is the value "-1" coming, that too, not once but twice?

Thanks,

Arpan

Aug 9 '06 #1
1 1544
Arpan,

That should be for the header and footer rows of the data grid.

Regards,
Augustin

"Arpan" wrote:
Consider the following code which populates a DataGrid with the items
of a string array:

Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs)
If (ViewState("Colors") Is Nothing) Then
arrColors = New String(3) {"red", "blue", "pink", "white"}
ViewState("Colors") = arrColors
Else
arrColors = ViewState("Colors")
End If

'creating a DataTable with 2 columns - ID & Color,
'adding the DataTable to a DataSet, adding rows
'to the DataTable & finally populating the DataSet

dgColors.DataBind()
End Sub

Sub ChangeColor(ByVal obj As Object, ByVal ea As DataGridItemEventArgs)
Dim intIndex As Integer = ea.Item.ItemIndex
Response.Write("Index: " & intIndex & "<br>")
End Sub

<form runat="server">
<asp:DataGrid ID="dgColors" OnItemCreated="ChangeColor" runat="server">
<Columns>
<asp:TemplateColumn HeaderText="ID">
<ItemTemplate>
<asp:Label ID="lblID" runat="server"><%# Container.DataItem("ID")
%></asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="Color" HeaderText="COLOR"/>
<asp:EditCommandColumn HeaderText="CHANGE" EditText="EDIT"
UpdateText="CHANGE" CancelText="CANCEL"/>
</Columns>
</asp:DataGrid>
</form>

Note the Response.Write line in the sub "ChangeColor". That line
produces the following output:

Index: -1
Index: 0
Index: 1
Index: 2
Index: 3
Index: -1

Now where from is the value "-1" coming, that too, not once but twice?

Thanks,

Arpan

Aug 9 '06 #2

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

Similar topics

0
by: Sam | last post by:
Hi, I have a class that receives a DataGrid control and populates it. However, I need to do an OnItemCreated event because if I'm missing data in a certain column, I display a HyperLink control...
5
by: Yan Wang | last post by:
Hi! Does anyone know how to get the text in textbox field which is in HeaderTemplate of a DataGrid? In the following code, I can not get text of "tbName". I typed something in that box. I can...
0
by: Jim Heavey | last post by:
I have a DataList and I want to add some Javascript to a button in the Datalist. I am guessing that I will use the "OnItemCreated" event to find my control and then load the java script to the...
0
by: Jim Heavey | last post by:
I have a DataList and I want to add some Javascript to a button in the Datalist. I am guessing that I will use the "OnItemCreated" event to find my control and then load the java script to the...
4
by: z. f. | last post by:
Hi, i stated that this is an advanced question because i have a post from few days ago that i received answers to with suggestions that looked good but did not work, so please if you post a...
2
by: Jesper Ordrup Christensen | last post by:
Hi all, I've designed a webform that has the following controls: 1. dropdown with autopostback 2. datagrid with an OnItemCreated event The idea is that the dropdown defines a filter. ...
1
by: Mauritsius | last post by:
I have a simple page where I would like to modify a repeater (bounded to a dataset) if a button (outside the repeater) is clicked or not. I tried to solve this with a button click event that...
3
by: Arpan | last post by:
A DataGrid displays data from a DataSet. The DataGrid has the OnItemCreated event. Assume that the OnItemCreated event calls a sub named "InEditMode()". The DataGrid gets rendered as soon as this...
1
by: rn5a | last post by:
In the .NET2.0 SDK Documentation, the DataGrid's OnItemCreated method is described as thus: The ItemCreated event is raised when an item in the DataGrid control is created, both during...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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,...
0
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...

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.