Timmy, I am very well aware of whatever you have said & thanks for the
same. Actually my primary intention of posting that question was to get
my confusions clarified on the difference between the firing of the
Page_Load sub & the DataGrid's OnItemCreated event.
Consider the following code snippet:
<script runat="server">
Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs)
'connecting to a database table, retrieving
'records & display them in the DataGrid
DataGrid1.DataBind()
End Sub
Sub CreateItem(ByVal obj As Object, ByVal ea As
DataGridItemEventArgs)
Dim intIndex As Integer = ea.Item.ItemIndex
'some code here
DataGrid1.DataBind()
End Sub
</script>
<form runat="server">
<asp:DataGrid ID="DataGrid1" OnItemCreated="CreateItem"
AutoGenerateColumns="false" runat="server">
<Columns>
<asp:TemplateColumn HeaderText="Name">
<ItemTemplate>
<asp:Label ID="lblName" runat="server"><%# Container.DataItem("Name")
%></asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="Adr" HeaderText="Address"/>
<asp:BoundColumn DataField="City" HeaderText="City"/>
<asp:BoundColumn DataField="State" HeaderText="State"/>
<asp:BoundColumn DataField="Ctry" HeaderText="Country"/>
<asp:EditCommandColumn HeaderText="CHANGE" EditText="EDIT"
UpdateText="CHANGE" CancelText="CANCEL" runat="server"/>
</Columns>
</asp:DataGrid>
</form>
When the user comes to this page for the first time, "Page_Load" will
execute first after which the "OnItemCreated" event will be fired. Next
the user clicks the "EDIT" link. If I am not mistaken, this means that
ASP.NET will have to create this page again right from the scratch when
the "EDIT" link is clicked (please do correct me if I am wrong). Under
such circumstances, will "Page_Load" execute before the "OnItemCreated"
event fires or will the "OnItemCreated" event fire before "Page_Load"
executes?
Thanks,
Arpan
timmy123 narra wrote:
Hi,
The ItemCreated event is raised when an item in the DataGrid control is
created, both during round-trips and at the time data is bound to the
control.
The ItemCreated event is commonly used to control the content and
appearance of a row in the DataGrid control.
Sub Item_Created(sender As Object, e As DataGridItemEventArgs)
Label1.Text = Label1.Text & " " & e.Item.ItemIndex
End Sub 'Item_Created
<asp:DataGrid id="ItemsGrid" runat="server"
BorderColor="black"
BorderWidth="1"
CellPadding="3"
ShowFooter="true"
OnItemCreated="Item_Created"
AutoGenerateColumns="true">
Regards
bhar
knowledge is power
http://www.vkinfotek.com
*** Sent via Developersdex http://www.developersdex.com ***