473,574 Members | 2,609 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Wrong event handler firing in DataGrid

Hey -

I'm writing a control that contains a DataGrid, and I'm unable to get
the update event to fire. When I click the update link, the edit event
fires.

heres the details...

my control overrides CreateChildCont rols and dynamically creates the
DataGrid, creates an EditCommandColu mn which it adds to the
DataGrid.Column s, and then adds several BoundColumns. I then create a
dummy dataset and bind it to the DataGrid. I then create and set an
EditCommandEven tHandler for the EditCommand, CancelCommand, and
UpdateCommand. finally I add the datagrid to the Control array.
...
in Render I tell the DataGrid to render.

When I run this, It looks right, and the edit and cancel buttons work
fine, but the update link fires the Edit event.

heres my code... any help on whats going on here would be really
appreciated.

private DataGrid dataGrid1;
private Label lblMsg;
private string messageText = "";
private DataSet myDataSet;

private string MessageText
{
get
{
return messageText;
}
set
{
messageText = value;
}
}
protected override void Render(HtmlText Writer output)
{
// Start Main Table
output.AddAttri bute("width", "100%");
output.RenderBe ginTag(HtmlText WriterTag.Table );

// Write the Message Text
output.RenderBe ginTag(HtmlText WriterTag.Thead );
output.RenderBe ginTag(HtmlText WriterTag.Tr);
output.AddAttri bute("class", "message");
output.AddAttri bute("colSpan", "2");
output.RenderBe ginTag(HtmlText WriterTag.Th);
output.Write(Me ssageText);
output.RenderEn dTag();
output.RenderEn dTag();
output.RenderEn dTag();

// Start Main table body
output.RenderBe ginTag(HtmlText WriterTag.Tbody );
output.RenderBe ginTag(HtmlText WriterTag.Tr);

// Write the DataGrid column
output.AddAttri bute("align", "center");
output.AddAttri bute("valign", "top");
output.RenderBe ginTag(HtmlText WriterTag.Td);
dataGrid1.Rende rControl(output );
output.RenderEn dTag();

output.RenderEn dTag(); // row
output.RenderEn dTag(); // main table body
output.RenderEn dTag(); // main table
}
public override ControlCollecti on Controls
{
get
{
EnsureChildCont rols();
return base.Controls;
}
}

protected override void CreateChildCont rols()
{
Controls.Clear( );

lblMsg = new Label();
Controls.Add(lb lMsg);

// DataGrid
dataGrid1 = new DataGrid();
dataGrid1.ID = "dataGrid";
dataGrid1.Enabl eViewState = true;
dataGrid1.AutoG enerateColumns = false;
FormatDataGrid( );
CreateEditCol() ;
CreateBoundCols ();
MakeParentTable ();
BindToDataGrid( );
dataGrid1.EditC ommand +=new
DataGridCommand EventHandler(da taGrid1_EditCom mand);
dataGrid1.Cance lCommand +=new
DataGridCommand EventHandler(da taGrid1_CancelC ommand);
dataGrid1.Updat eCommand += new
DataGridCommand EventHandler(da taGrid1_UpdateC ommand);
Controls.Add(da taGrid1);
}
private void FormatDataGrid( )
{
dataGrid1.CssCl ass = "DataGridTable" ;
dataGrid1.Heade rStyle.CssClass = "DataGridHeadin g";
dataGrid1.ItemS tyle.CssClass = "DataGridRo w";
dataGrid1.Alter natingItemStyle .CssClass = "DataGridAltRow ";
dataGrid1.EditI temStyle.CssCla ss = "DataGridEditRo w";
}

private void CreateEditCol()
{
EditCommandColu mn editCol = new EditCommandColu mn();

editCol.ButtonT ype = ButtonColumnTyp e.LinkButton;
editCol.CancelT ext = "Cancel";
editCol.EditTex t = "Edit";
editCol.UpdateT ext = "Update";

dataGrid1.Colum ns.Add(editCol) ;
}
private void CreateBoundCols ()
{
//create the bound cols in the grid
.... create bound cols for the datatable and add them
to the dataGrid...
dataGrid1.Colum ns.Add(myBoundC olumn);
}

private void MakeParentTable ()
{
// Create a new DataTable.
System.Data.Dat aTable myDataTable = new DataTable("Pare ntTable");
// Declare variables for DataColumn and DataRow objects.
DataColumn myDataColumn;
DataRow myDataRow;
... add a few columns, and then populate a few rows...
}

private void BindToDataGrid( )
{
// Turn off AutoGenerate of Columns
// Set DataSource
dataGrid1.DataS ource = myDataSet; //,"ParentTabl e"

// Bind
dataGrid1.DataB ind();
}
private void dataGrid1_EditC ommand(object sender,
DataGridCommand EventArgs e)
{
MessageText = "Edit link was clicked.";
dataGrid1.EditI temIndex = e.Item.ItemInde x;
dataGrid1.DataB ind();
}
private void dataGrid1_Cance lCommand(object sender,
DataGridCommand EventArgs e)
{
MessageText = "Cancel was clicked";
dataGrid1.EditI temIndex = -1;
dataGrid1.DataB ind();
}
private void dataGrid1_Updat eCommand(object sender,
DataGridCommand EventArgs e)
{
MessageText = "Update link was clicked";

dataGrid1.EditI temIndex = -1;
dataGrid1.DataB ind();
}

Dec 8 '06 #1
0 1525

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

Similar topics

0
1353
by: SteveC | last post by:
In my ASP.NEt codebehind, I declare a public var for a DataGrid. Then in the TextChanged event handler for a TextBox, I create a <div> tag, stuff it inside the form, then instance a DataGrid and put it inside the <div> tag. In the web page, I can click on any row in the grid, and when the page posts back, the grid goes away. That is good....
0
5731
by: Oz | last post by:
Hi Using VS.NET 2003, Windows XP SP1, We have a page which has been developed using ASP.NET. On it, is a button which when clicked is supposed to add some data to a table. When the button is selected, it causes the ServerClick event to be called twice. Here's the code: You'll see that there are two grids on the page, and that the...
3
2710
by: Utter Newbie | last post by:
Anyone know what could be the problem? I gave the button in the footer a command name but when the button is clicked the datagrid_itemcommand event is never fired (tracing it in the debugger)? It is strange... All buttons in the item list work and cause the event... Just not my footer button... I added the button in the footer template of the...
5
1957
by: csgraham74 | last post by:
Hi guys, I posted regarding this issue the other day but i still dont have an answer to my problem. Basically i have imported asp.net pages from dreamweaver into visual studio. Ive added a few controls that ive copied in from another asp.net page that i built within visual studio. The problem is that the asp:button does not fir an event...
2
3366
by: Deepesh | last post by:
Good day, I have a specific case of the DataGrid in my solution which is causing the ItemCommand Event Not Firing. So I'm creating a "Skinnable" set of controls. I seperate the actual ASCX file and .CS file. When I initialize my .CS file, in that code there is a method that goes: Page.LoadControl(FILENAME) Which associates a .ascx file...
4
4147
by: EvelynAnd Ethan | last post by:
Hi, ItemCommand event not firing from a dynamic user control ,WHERE A DATAGRID HAS BUTTON,when i click on the linkbutton first time the itemcommand event doesnt fire,second time event fires up any answers?? Regards,
1
3078
by: Mark Gilkes | last post by:
I have a DataGrid which I am adding to the page dynamically at the Init stage of the page load. The DataGrid has AutoGenerateColumns turned off, has BoundColumns and is bound to a DataView for its’ data source. I have also added a TemplateColumn which is defined in a derived class and contains an ImageButton. The derived TemplateColumn class...
7
3562
by: rsaffy | last post by:
I am having trouble with my dynamically created button's event handling. I read that the buttons need to be recreated on every trip to the server, but how exactly do you do that when the datagrid the button is added to is created at run time? here is code from my aspx page......
19
4738
by: Daniela Roman | last post by:
Hello, I try to fire an event under a button click event and maybe anybody can give a clue please. I have let's say a WEB grid with PageIndexChanged event: private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
0
7814
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, 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...
0
8075
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8253
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7827
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...
0
8109
tracyyun
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...
1
5632
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5316
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...
1
2253
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1356
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.