Hello all,
Im wondering why my OnItemDataBound gets fired twice here. I got this sample
code from somewhere online.. and when I put a break point in the method...
it hits the method twice for each row rendered...
Any insights??
Thanks!
Girish
------------
ASPX File
-----------
<%@ Page language="c#" Inherits="Maste rDetail.Custome rOrderDataGrid"
EnableViewState ="False" CodeBehind="Cus tomerOrderDataG rid.aspx.cs"
AutoEventWireup ="false" %>
<HTML>
<body style="FONT: x-small Verdana, Arial, sans-serif">
<!-- Begin Web Form -->
<form id="CustomerOrd erDataGrid" method="post" runat="server">
<p><a href="/DayOfDotNet/">Parent Directory</a></p>
<!-- Begin DataGrid -->
<asp:DataGrid id="CustomerDat aGrid" runat="server"
AutoGenerateCol umns="False" CellPadding="2"
CellSpacing="0" Font-Names="Verdana, Arial, sans-serif"
BorderColor="Bl ack" BorderWidth="1"
GridLines="Hori zontal"
OnItemDataBound ="CustomerDataG rid_OnItemDataB ound" EnableViewState ="False">
<AlternatingIte mStyle BackColor="Tan" ></AlternatingItem Style>
<ItemStyle Font-Size="X-Small"></ItemStyle>
<HeaderStyle Font-Size="Small" Font-Names="Arial" Font-Bold="True"
ForeColor="Whit e" BackColor="Maro on"></HeaderStyle>
<Columns>
<asp:BoundColum n Visible="False"
DataField="Cust omerID"></asp:BoundColumn >
<asp:TemplateCo lumn HeaderText="Cus tomer">
<ItemStyle VerticalAlign=" Top"></ItemStyle>
<ItemTemplate >
<b>
<%# DataBinder.Eval (Container.Data Item, "CompanyNam e") %>
</b>
<br>
<%# DataBinder.Eval (Container.Data Item, "Address" ) %>
.. <br>
<%# DataBinder.Eval (Container.Data Item, "City" ) %>
,
<%# DataBinder.Eval (Container.Data Item, "Region") %>
<%# DataBinder.Eval (Container.Data Item, "PostalCode " ) %>
<br>
<br>
<%# DataBinder.Eval (Container.Data Item, "ContactNam e" ) %>
<br>
<%# DataBinder.Eval (Container.Data Item, "ContactTit le" ) %>
<br>
<%# DataBinder.Eval (Container.Data Item, "Phone" ) %>
</ItemTemplate>
</asp:TemplateCol umn>
</Columns>
</asp:DataGrid>
<!-- End DataGrid -->
</form>
<!-- End Web Form -->
</body>
</HTML>
CODE BEHIND
-----------------
using System;
using System.Data;
using System.Data.Sql Client;
using System.Drawing;
using System.Web;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.H tmlControls;
using System.Configur ation;
namespace MasterDetail
{
public class CustomerOrderDa taGrid : System.Web.UI.P age
{
protected DataGrid CustomerDataGri d;
private DataSet ds = new DataSet();
private void Page_Load(objec t sender, System.EventArg s e)
{
string sqlStmt = "SELECT top 1 * FROM Customers; SELECT * FROM Orders";
string conString = "server=localho st;database=Nor thwind;uid=sa;p wd=;";
SqlDataAdapter sda = new SqlDataAdapter( sqlStmt, conString);
sda.Fill(ds);
ds.Tables[0].TableName = "Customers" ;
ds.Tables[1].TableName = "Orders";
CustomerDataGri d.DataSource = ds.Tables["Customers"];
CustomerDataGri d.DataBind();
}
//Use the OnItemDataBound event handler to dynamically add an embedded
DataGrid
protected void CustomerDataGri d_H(object sender, DataGridItemEve ntArgs e)
{
//When each row is created in the DataGrid, eval the ItemType
if(e.Item.ItemT ype == ListItemType.It em ||
e.Item.ItemType == ListItemType.Al ternatingItem)
{
//If the ItemType is Item or AlternatingItem ,
//Create a new DataGrid object named OrdersDataGrid
}
}
override protected void OnInit(EventArg s e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeCompo nent();
base.OnInit(e);
}
private void InitializeCompo nent()
{
this.CustomerDa taGrid.ItemCrea ted += new
System.Web.UI.W ebControls.Data GridItemEventHa ndler(this.Cust omerDataGrid_It emCreated);
this.CustomerDa taGrid.ItemData Bound += new
System.Web.UI.W ebControls.Data GridItemEventHa ndler(this.Cust omerDataGrid_On ItemDataBound);
this.Load += new System.EventHan dler(this.Page_ Load);
}
private void CustomerDataGri d_ItemCreated(o bject sender,
System.Web.UI.W ebControls.Data GridItemEventAr gs e)
{
int i=1;
i=10 + 12;
}
}
} 2 1995
Hi Girish,
Try remove the
this.CustomerDa taGrid.ItemData Bound += new
System.Web.UI.W ebControls.Data GridItemEventHa ndler(this.Cust omerDataGrid_On ItemDataBound);
line in the InitializeCompo nent() because you already call this event on the
html-design OnItemDataBound ="CustomerDataG rid_OnItemDataB ound".
Hope that helps.
KD
"Girish" wrote: Hello all,
Im wondering why my OnItemDataBound gets fired twice here. I got this sample code from somewhere online.. and when I put a break point in the method... it hits the method twice for each row rendered...
Any insights??
Thanks! Girish
------------ ASPX File ----------- <%@ Page language="c#" Inherits="Maste rDetail.Custome rOrderDataGrid" EnableViewState ="False" CodeBehind="Cus tomerOrderDataG rid.aspx.cs" AutoEventWireup ="false" %> <HTML> <body style="FONT: x-small Verdana, Arial, sans-serif"> <!-- Begin Web Form --> <form id="CustomerOrd erDataGrid" method="post" runat="server"> <p><a href="/DayOfDotNet/">Parent Directory</a></p> <!-- Begin DataGrid --> <asp:DataGrid id="CustomerDat aGrid" runat="server" AutoGenerateCol umns="False" CellPadding="2" CellSpacing="0" Font-Names="Verdana, Arial, sans-serif" BorderColor="Bl ack" BorderWidth="1" GridLines="Hori zontal" OnItemDataBound ="CustomerDataG rid_OnItemDataB ound" EnableViewState ="False"> <AlternatingIte mStyle BackColor="Tan" ></AlternatingItem Style> <ItemStyle Font-Size="X-Small"></ItemStyle> <HeaderStyle Font-Size="Small" Font-Names="Arial" Font-Bold="True" ForeColor="Whit e" BackColor="Maro on"></HeaderStyle> <Columns> <asp:BoundColum n Visible="False" DataField="Cust omerID"></asp:BoundColumn > <asp:TemplateCo lumn HeaderText="Cus tomer"> <ItemStyle VerticalAlign=" Top"></ItemStyle> <ItemTemplate > <b> <%# DataBinder.Eval (Container.Data Item, "CompanyNam e") %> </b> <br> <%# DataBinder.Eval (Container.Data Item, "Address" ) %> .. <br> <%# DataBinder.Eval (Container.Data Item, "City" ) %> , <%# DataBinder.Eval (Container.Data Item, "Region") %> <%# DataBinder.Eval (Container.Data Item, "PostalCode " ) %> <br> <br> <%# DataBinder.Eval (Container.Data Item, "ContactNam e" ) %> <br> <%# DataBinder.Eval (Container.Data Item, "ContactTit le" ) %> <br> <%# DataBinder.Eval (Container.Data Item, "Phone" ) %> </ItemTemplate> </asp:TemplateCol umn> </Columns> </asp:DataGrid> <!-- End DataGrid --> </form> <!-- End Web Form --> </body> </HTML>
CODE BEHIND ----------------- using System; using System.Data; using System.Data.Sql Client; using System.Drawing; using System.Web; using System.Web.UI; using System.Web.UI.W ebControls; using System.Web.UI.H tmlControls; using System.Configur ation;
namespace MasterDetail { public class CustomerOrderDa taGrid : System.Web.UI.P age { protected DataGrid CustomerDataGri d; private DataSet ds = new DataSet();
private void Page_Load(objec t sender, System.EventArg s e) { string sqlStmt = "SELECT top 1 * FROM Customers; SELECT * FROM Orders"; string conString = "server=localho st;database=Nor thwind;uid=sa;p wd=;";
SqlDataAdapter sda = new SqlDataAdapter( sqlStmt, conString);
sda.Fill(ds); ds.Tables[0].TableName = "Customers" ; ds.Tables[1].TableName = "Orders";
CustomerDataGri d.DataSource = ds.Tables["Customers"]; CustomerDataGri d.DataBind(); }
//Use the OnItemDataBound event handler to dynamically add an embedded DataGrid protected void CustomerDataGri d_H(object sender, DataGridItemEve ntArgs e) { //When each row is created in the DataGrid, eval the ItemType if(e.Item.ItemT ype == ListItemType.It em || e.Item.ItemType == ListItemType.Al ternatingItem) { //If the ItemType is Item or AlternatingItem , //Create a new DataGrid object named OrdersDataGrid } }
override protected void OnInit(EventArg s e) { // // CODEGEN: This call is required by the ASP.NET Web Form Designer. // InitializeCompo nent(); base.OnInit(e); }
private void InitializeCompo nent() { this.CustomerDa taGrid.ItemCrea ted += new System.Web.UI.W ebControls.Data GridItemEventHa ndler(this.Cust omerDataGrid_It emCreated); this.CustomerDa taGrid.ItemData Bound += new System.Web.UI.W ebControls.Data GridItemEventHa ndler(this.Cust omerDataGrid_On ItemDataBound); this.Load += new System.EventHan dler(this.Page_ Load);
}
private void CustomerDataGri d_ItemCreated(o bject sender, System.Web.UI.W ebControls.Data GridItemEventAr gs e) { int i=1; i=10 + 12; } } }
Thanks a mil Calvin. This solves my problem.
Girish
"Calvin KD" <Ca******@discu ssions.microsof t.com> wrote in message
news:E0******** *************** ***********@mic rosoft.com... Hi Girish, Try remove the this.CustomerDa taGrid.ItemData Bound += new
System.Web.UI.W ebControls.Data GridItemEventHa ndler(this.Cust omerDataGrid_On ItemDataBound); line in the InitializeCompo nent() because you already call this event on the html-design OnItemDataBound ="CustomerDataG rid_OnItemDataB ound".
Hope that helps. KD
"Girish" wrote:
Hello all,
Im wondering why my OnItemDataBound gets fired twice here. I got this sample code from somewhere online.. and when I put a break point in the method... it hits the method twice for each row rendered...
Any insights??
Thanks! Girish
------------ ASPX File ----------- <%@ Page language="c#" Inherits="Maste rDetail.Custome rOrderDataGrid" EnableViewState ="False" CodeBehind="Cus tomerOrderDataG rid.aspx.cs" AutoEventWireup ="false" %> <HTML> <body style="FONT: x-small Verdana, Arial, sans-serif"> <!-- Begin Web Form --> <form id="CustomerOrd erDataGrid" method="post" runat="server"> <p><a href="/DayOfDotNet/">Parent Directory</a></p> <!-- Begin DataGrid --> <asp:DataGrid id="CustomerDat aGrid" runat="server" AutoGenerateCol umns="False" CellPadding="2" CellSpacing="0" Font-Names="Verdana, Arial, sans-serif" BorderColor="Bl ack" BorderWidth="1" GridLines="Hori zontal" OnItemDataBound ="CustomerDataG rid_OnItemDataB ound" EnableViewState ="False"> <AlternatingIte mStyle BackColor="Tan" ></AlternatingItem Style> <ItemStyle Font-Size="X-Small"></ItemStyle> <HeaderStyle Font-Size="Small" Font-Names="Arial" Font-Bold="True" ForeColor="Whit e" BackColor="Maro on"></HeaderStyle> <Columns> <asp:BoundColum n Visible="False" DataField="Cust omerID"></asp:BoundColumn > <asp:TemplateCo lumn HeaderText="Cus tomer"> <ItemStyle VerticalAlign=" Top"></ItemStyle> <ItemTemplate > <b> <%# DataBinder.Eval (Container.Data Item, "CompanyNam e") %> </b> <br> <%# DataBinder.Eval (Container.Data Item, "Address" ) %> .. <br> <%# DataBinder.Eval (Container.Data Item, "City" ) %> , <%# DataBinder.Eval (Container.Data Item, "Region") %> <%# DataBinder.Eval (Container.Data Item, "PostalCode " ) %> <br> <br> <%# DataBinder.Eval (Container.Data Item, "ContactNam e" ) %> <br> <%# DataBinder.Eval (Container.Data Item, "ContactTit le" ) %> <br> <%# DataBinder.Eval (Container.Data Item, "Phone" ) %> </ItemTemplate> </asp:TemplateCol umn> </Columns> </asp:DataGrid> <!-- End DataGrid --> </form> <!-- End Web Form --> </body> </HTML>
CODE BEHIND ----------------- using System; using System.Data; using System.Data.Sql Client; using System.Drawing; using System.Web; using System.Web.UI; using System.Web.UI.W ebControls; using System.Web.UI.H tmlControls; using System.Configur ation;
namespace MasterDetail { public class CustomerOrderDa taGrid : System.Web.UI.P age { protected DataGrid CustomerDataGri d; private DataSet ds = new DataSet();
private void Page_Load(objec t sender, System.EventArg s e) { string sqlStmt = "SELECT top 1 * FROM Customers; SELECT * FROM Orders"; string conString = "server=localho st;database=Nor thwind;uid=sa;p wd=;";
SqlDataAdapter sda = new SqlDataAdapter( sqlStmt, conString);
sda.Fill(ds); ds.Tables[0].TableName = "Customers" ; ds.Tables[1].TableName = "Orders";
CustomerDataGri d.DataSource = ds.Tables["Customers"]; CustomerDataGri d.DataBind(); }
//Use the OnItemDataBound event handler to dynamically add an embedded DataGrid protected void CustomerDataGri d_H(object sender, DataGridItemEve ntArgs e) { //When each row is created in the DataGrid, eval the ItemType if(e.Item.ItemT ype == ListItemType.It em || e.Item.ItemType == ListItemType.Al ternatingItem) { //If the ItemType is Item or AlternatingItem , //Create a new DataGrid object named OrdersDataGrid } }
override protected void OnInit(EventArg s e) { // // CODEGEN: This call is required by the ASP.NET Web Form Designer. // InitializeCompo nent(); base.OnInit(e); }
private void InitializeCompo nent() { this.CustomerDa taGrid.ItemCrea ted += new System.Web.UI.W ebControls.Data GridItemEventHa ndler(this.Cust omerDataGrid_It emCreated); this.CustomerDa taGrid.ItemData Bound += new System.Web.UI.W ebControls.Data GridItemEventHa ndler(this.Cust omerDataGrid_On ItemDataBound); this.Load += new System.EventHan dler(this.Page_ Load);
}
private void CustomerDataGri d_ItemCreated(o bject sender, System.Web.UI.W ebControls.Data GridItemEventAr gs e) { int i=1; i=10 + 12; } } } This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Funbeat |
last post by:
Hi everybody,
I'm facing with the following problem (bug ?) :
A page is calling another one (export.aspx) for exporting data to
excel.
The tecnhique used is to create a Excel-MIME stream for viewing it
directly in the browser.
(below is a sample code)
|
by: Wayne Wengert |
last post by:
I have an ASP.NET page in which I include a datalist that is bound to a
datareader. I am trying to use the OnItemDataBound event to change the
contents of the NavigateURL property of a hyperlink. I am getting an error I
do not understand. Any explinations woul;d be appreciated. The error report
is:
Compiler Error Message: BC30408: Method...
|
by: Nimrod Cohen |
last post by:
Hi
During the page_load of my Aspx page "http://myMachine/MyWebApp/Quote.aspx" , i write to the response an html that embeds a form with the action pointing out to the same aspx page
i.e
Response.Write( "<html><head></head><body><form action="http://myMachine/MyWebApp/Quote.aspx" name="QuoteForm" method="POST"><input type="hidden"...
|
by: Rippo |
last post by:
Hi
I have a Master page that opens up a db connection, performs a couple
of global routines in the page_load event. All of my other web pages in
my web app then inherits this Master Page
I also have a page_load event on all of the other pages. I am finding
however that the page_load event on the template page is being fired
twice.
|
by: rmccinc |
last post by:
OK, I am running into some issues that I cant figure out a work-around.
I am not going to post code cause I figured out WHY my issue is
happening:
-I have a datagrid, and a button that fires a click event.
-The Datagrids onitemdatabound event dynamically creates validation
controls per values from other columns in the datagrid, one of...
| |
by: scottiedog |
last post by:
I didn't notice this until I put debug lines but when a char is send to textbox via button event, e.g. click button1, this happen
KeyDow
KeyDow
KeyPres
KeyU
KeyU
where button2 will do this
|
by: Anup |
last post by:
Hi Group,
In my application I am using a datagrid, now I m implementing sorting
for that datagrid,
I am changing the flag for ascending and descending when SortCommand
event of datagrid is fired.
Now the problem I am facing is that the Sort Command event is being
fired twice even if I click the header in datagrid only once thus my
flag...
|
by: TS |
last post by:
I have this custom data list control and i override the onItemDatabound
event. After upgrading to vs 2005, this event is not always getting called,
though it does at other times. No changes were made when upgrading to 2.0
is there any reason for this because of .net 2.0?
thanks
|
by: Daniel |
last post by:
I've created a custom control including some Literal ( constructed
with html markup) and an ImageButton firing event ( add a vote ).
public event VoteCommandEventHandler VoteCommand;
protected override void CreateChildControls()
{
LiteralControl ltrBeforeVote = new
LiteralControl(buildMarkupBeforeVoteButton());...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |