473,770 Members | 2,065 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DataGrid ItemCommand???

hi all,
i am having problem with using itemcommand of datagrid by way of asp:image
button.
i have put an image button in a datagrid item template and have set
CommandName="De leteRecord" and have coded a switch to handle the event.
I have done this vb.net and it works fine..put in c# i can not catch the
item command..i stepped into code
via debug mode.. its just doest enter the dgrCaseType_Ite mCommand...
I AM TOTALLY CLULESS.....WHA T AM I MISSING...
PLZ see code below.........

<asp:DataGrid ID="dgrCaseType " Runat="server" AutoGenerateCol umns="False"
Width="100%" BorderWidth="2"
BorderColor="#f fffff" HeaderStyle-HorizontalAlign ="Center"
AllowSorting="T rue" EnableViewState ="True">
<AlternatingIte mStyle CssClass="bg-ltgray"></AlternatingItem Style>
<Columns>
<asp:BoundColum n HeaderText="Def ault Owner"
HeaderStyle-CssClass="menu_ gray" DataField="CSPe rsonnell"
HeaderStyle-Width="150"></asp:BoundColumn >
<asp:TemplateCo lumn HeaderStyle-CssClass="menu_ gray"
HeaderStyle-Width="150" HeaderText="Opt ions"
ItemStyle-HorizontalAlign ="Center">
<ItemTemplate >
<asp:ImageButto n ID="imgEdit" CommandName="Ed itRecord"
ImageUrl="../../Images/icon_edit.gif"
AlternateText=" Edit" Runat="server"
Height="16" Width="16"
EnableViewState ="False"></asp:ImageButton >

<asp:ImageButto n ID="imgDelete" CommandName="De leteRecord"
ImageUrl="../../Images/icon_trash.gif"
AlternateText=" Delete" Runat="server"
Height="16" Width="16"
EnableViewState ="False"></asp:ImageButton >
</ItemTemplate>
</asp:TemplateCol umn>

</Columns>
</asp:DataGrid>

Then I have coded the following:

protected System.Web.UI.W ebControls.Data Grid dgrCaseType;

protected void dgrCaseType_Ite mCommand(object source,
System.Web.UI.W ebControls.Data GridCommandEven tArgs e)
{
switch(e.Comman dName)
{
case "EditRecord ":
string s=e.Item.Cells[7].Text;
break;
case "DeleteReco rd":

break;
}
}

private void InitializeCompo nent()
{
this.Load += new System.EventHan dler(this.Page_ Load);
this.dgrCaseTyp e.ItemDataBound += new
System.Web.UI.W ebControls.Data GridItemEventHa ndler(this.dgrC aseType_ItemDat aBound);
}

Thanks in advance..
-Sami.
Nov 18 '05 #1
2 5357
You need to wire the event handler for the DataGrid's ItemCommand event? Do
yiou have it done in code-behind in InitializeCompo nent method? (It looks
like dgrCaseType.Ite mCommand += new
DataGridCommand EventHandler(me thod_name);..., which seems to be missing
there)

If you don't have it code-behind, you can wiree it on aspx on DataGrid's
declaration:

.... OnItemCommand=" dgrCaseType_Ite mCommand" ...

or make up similar wiring in InitializeCompo nent as for other events.
--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
http://blogs.aspadvice.com/joteke

"Syed Sami R. Shah" <Syed Sami R. Sh**@discussion s.microsoft.com> wrote in
message news:4D******** *************** ***********@mic rosoft.com...
hi all,
i am having problem with using itemcommand of datagrid by way of asp:image
button.
i have put an image button in a datagrid item template and have set
CommandName="De leteRecord" and have coded a switch to handle the event.
I have done this vb.net and it works fine..put in c# i can not catch the
item command..i stepped into code
via debug mode.. its just doest enter the dgrCaseType_Ite mCommand...
I AM TOTALLY CLULESS.....WHA T AM I MISSING...
PLZ see code below.........

<asp:DataGrid ID="dgrCaseType " Runat="server" AutoGenerateCol umns="False"
Width="100%" BorderWidth="2"
BorderColor="#f fffff" HeaderStyle-HorizontalAlign ="Center"
AllowSorting="T rue" EnableViewState ="True">
<AlternatingIte mStyle CssClass="bg-ltgray"></AlternatingItem Style>
<Columns>
<asp:BoundColum n HeaderText="Def ault Owner"
HeaderStyle-CssClass="menu_ gray" DataField="CSPe rsonnell"
HeaderStyle-Width="150"></asp:BoundColumn >
<asp:TemplateCo lumn HeaderStyle-CssClass="menu_ gray"
HeaderStyle-Width="150" HeaderText="Opt ions"
ItemStyle-HorizontalAlign ="Center">
<ItemTemplate >
<asp:ImageButto n ID="imgEdit" CommandName="Ed itRecord"
ImageUrl="../../Images/icon_edit.gif"
AlternateText=" Edit" Runat="server"
Height="16" Width="16"
EnableViewState ="False"></asp:ImageButton >

<asp:ImageButto n ID="imgDelete" CommandName="De leteRecord"
ImageUrl="../../Images/icon_trash.gif"
AlternateText=" Delete" Runat="server"
Height="16" Width="16"
EnableViewState ="False"></asp:ImageButton >
</ItemTemplate>
</asp:TemplateCol umn>

</Columns>
</asp:DataGrid>

Then I have coded the following:

protected System.Web.UI.W ebControls.Data Grid dgrCaseType;

protected void dgrCaseType_Ite mCommand(object source,
System.Web.UI.W ebControls.Data GridCommandEven tArgs e)
{
switch(e.Comman dName)
{
case "EditRecord ":
string s=e.Item.Cells[7].Text;
break;
case "DeleteReco rd":

break;
}
}

private void InitializeCompo nent()
{
this.Load += new System.EventHan dler(this.Page_ Load);
this.dgrCaseTyp e.ItemDataBound += new
System.Web.UI.W ebControls.Data GridItemEventHa ndler(this.dgrC aseType_ItemDat aBound);
}

Thanks in advance..
-Sami.

Nov 18 '05 #2
first off, you aren't hooking up the ItemCommand event...you are hooking up
the ItemDataBound however...you need this:

this.dgrCaseTyp e.ItemCommand+= new
DataGridCommand EventHandler(dg rCaseType_ItemC ommand);

in your InitializeCompo nent (or page_load).
Secondly, assuming you have the above, you also need to make sure that you
aren't rebinding on postback, if so you'll lose ur event...

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Syed Sami R. Shah" <Syed Sami R. Sh**@discussion s.microsoft.com> wrote in
message news:4D******** *************** ***********@mic rosoft.com...
hi all,
i am having problem with using itemcommand of datagrid by way of asp:image
button.
i have put an image button in a datagrid item template and have set
CommandName="De leteRecord" and have coded a switch to handle the event.
I have done this vb.net and it works fine..put in c# i can not catch the
item command..i stepped into code
via debug mode.. its just doest enter the dgrCaseType_Ite mCommand...
I AM TOTALLY CLULESS.....WHA T AM I MISSING...
PLZ see code below.........

<asp:DataGrid ID="dgrCaseType " Runat="server" AutoGenerateCol umns="False"
Width="100%" BorderWidth="2"
BorderColor="#f fffff" HeaderStyle-HorizontalAlign ="Center"
AllowSorting="T rue" EnableViewState ="True">
<AlternatingIte mStyle CssClass="bg-ltgray"></AlternatingItem Style> <Columns>
<asp:BoundColum n HeaderText="Def ault Owner"
HeaderStyle-CssClass="menu_ gray" DataField="CSPe rsonnell"
HeaderStyle-Width="150"></asp:BoundColumn >
<asp:TemplateCo lumn HeaderStyle-CssClass="menu_ gray"
HeaderStyle-Width="150" HeaderText="Opt ions"
ItemStyle-HorizontalAlign ="Center">
<ItemTemplate >
<asp:ImageButto n ID="imgEdit" CommandName="Ed itRecord"
ImageUrl="../../Images/icon_edit.gif"
AlternateText=" Edit" Runat="server"
Height="16" Width="16"
EnableViewState ="False"></asp:ImageButton >

<asp:ImageButto n ID="imgDelete" CommandName="De leteRecord"
ImageUrl="../../Images/icon_trash.gif"
AlternateText=" Delete" Runat="server"
Height="16" Width="16"
EnableViewState ="False"></asp:ImageButton >
</ItemTemplate>
</asp:TemplateCol umn>

</Columns>
</asp:DataGrid>

Then I have coded the following:

protected System.Web.UI.W ebControls.Data Grid dgrCaseType;

protected void dgrCaseType_Ite mCommand(object source,
System.Web.UI.W ebControls.Data GridCommandEven tArgs e)
{
switch(e.Comman dName)
{
case "EditRecord ":
string s=e.Item.Cells[7].Text;
break;
case "DeleteReco rd":

break;
}
}

private void InitializeCompo nent()
{
this.Load += new System.EventHan dler(this.Page_ Load);
this.dgrCaseTyp e.ItemDataBound += new
System.Web.UI.W ebControls.Data GridItemEventHa ndler(this.dgrC aseType_ItemDat a
Bound); }

Thanks in advance..
-Sami.

Nov 18 '05 #3

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

Similar topics

8
7932
by: Ashish Shridharan | last post by:
Hi All I have been trying to add a control to the header cell of a datagrid on my ASP.NET page. These controls are defined in the HTML as ASP.NET web controls. They are being added into the header of the datagrid in the "ItemDataBound" method of the grid. However, once, they are added in the grid, i seem to lose the event handler for the same control. Is there anyone who has tried this before and knows why this is hapenning ??
0
1292
by: Solomon Shaffer | last post by:
I am trying to add some link buttons to a datagrid template column at runtime and trying to wire these buttons up to the ItemCommand event (or any event when clicked!). The ItemCommand event works fine if I add the controls at design time in the HTML, but does not seem to catch when I add the control dynamically in the code behind. The datagrid renders just fine, just no ItemCommand event... I have included some code snipplets below. Any...
0
1986
by: Colin Ramsay | last post by:
Hi all, I don't normally post swathes of code like this but I am truly banging my head off my desk here... I've dynamically created a datagrid within a usercontrol. There are two columns which contain buttons to Edit & Delete rows. For some reason, the ItemCommand event which these should be connected to isn't firing.
2
3182
by: Daniel Walzenbach | last post by:
Hi, I created an ASP.NET Datagrid where a single row can be selected by clicking anywhere on the row (according to http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vstechart/html/vbtchTopQuestionsAboutASPNETDataGridServerControl.asp, Selecting Rows by Clicking Anywhere). Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, _ ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) _
4
2126
by: The Alchemist | last post by:
I am having a problem with a dynamically-generated Datagrid. It is important to point out that this problem does not exist with a design-time created Datagrid, but only with a dynamically generated Datagrid in a Web Custom Control (WCC) : The datagrid has LinkButton Column which has a select LinkButton for each row. When this button is clicked, the Datagrid raises its 'ItemCommand' event which captures the information for that row and...
2
3375
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 with my .CS file, allowing me to plug in any
3
3463
by: danc | last post by:
I have a datagrid with a checkbox and dropdown list in each row. Both set AutoPostBack to true and ItemCommand and OnSelectedIndexChanged events for these controls works fine when DataGrid is not paged. As soon as I turn on paging support, I no longer get events properly for any page except the first. 1) The DataGrid displays the page numbers on the top (and bottom). Whenever I click to go to a specific page number, the DropDownList's...
5
6703
by: Jeff User | last post by:
Hello ..NET 1.1, VS 2003, C# & asp.net I have tried to follow msdn instructions and samples but I can not get an event to fire for this button on the datagrid. There has to be something obvious missing here, but after 2 days I am ready to explode ! Please help. To create the Delete button I selected the grid in design view, clicked the "Columns" property and added the Delete button in the
1
5163
by: kevin | last post by:
Hi, I'm working with VS 2005 and Framework 2.0 I have a datagrid with a link and the selectedindexchanged will not fire. The page posts back but does nothing. Protected Sub DataGrid1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGrid1.SelectedIndexChanged Label2.Text = "what the H"
0
10057
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10002
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
9869
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8883
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7415
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5312
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5449
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3970
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
3
2816
bsmnconsultancy
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.