OnItemCreated DataGrid?

A

Arpan

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 ASPX
page loads in the browser. Now since the DataGrid has got its
OnItemCreated event, will it's event function i.e. "InEditMode()"
execute before the Page_Load sub executes or will it execute after the
Page_Load sub gets executed?

Thanks,

Arpan
 
T

timmy123 narra

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
 
T

timmy123 narra

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
 
A

Arpan

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

OnItemCreated? 1
ViewState? 1
IsPostBack 4
Problem of Cast/Datagrid - Code Behind Bis (felix) 2
DataRow Delete Method 5
Dynamic BoundColumn 2
DataBind In ItemDataBound Event 1
Page_Load & ButtonClick? 17

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top