473,408 Members | 1,955 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

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="DeleteRecord" 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_ItemCommand...
I AM TOTALLY CLULESS.....WHAT AM I MISSING...
PLZ see code below.........

<asp:DataGrid ID="dgrCaseType" Runat="server" AutoGenerateColumns="False"
Width="100%" BorderWidth="2"
BorderColor="#ffffff" HeaderStyle-HorizontalAlign="Center"
AllowSorting="True" EnableViewState="True">
<AlternatingItemStyle CssClass="bg-ltgray"></AlternatingItemStyle>
<Columns>
<asp:BoundColumn HeaderText="Default Owner"
HeaderStyle-CssClass="menu_gray" DataField="CSPersonnell"
HeaderStyle-Width="150"></asp:BoundColumn>
<asp:TemplateColumn HeaderStyle-CssClass="menu_gray"
HeaderStyle-Width="150" HeaderText="Options"
ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:ImageButton ID="imgEdit" CommandName="EditRecord"
ImageUrl="../../Images/icon_edit.gif"
AlternateText="Edit" Runat="server"
Height="16" Width="16"
EnableViewState="False"></asp:ImageButton>

<asp:ImageButton ID="imgDelete" CommandName="DeleteRecord"
ImageUrl="../../Images/icon_trash.gif"
AlternateText="Delete" Runat="server"
Height="16" Width="16"
EnableViewState="False"></asp:ImageButton>
</ItemTemplate>
</asp:TemplateColumn>

</Columns>
</asp:DataGrid>

Then I have coded the following:

protected System.Web.UI.WebControls.DataGrid dgrCaseType;

protected void dgrCaseType_ItemCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
switch(e.CommandName)
{
case "EditRecord":
string s=e.Item.Cells[7].Text;
break;
case "DeleteRecord":

break;
}
}

private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
this.dgrCaseType.ItemDataBound += new
System.Web.UI.WebControls.DataGridItemEventHandler (this.dgrCaseType_ItemDataBound);
}

Thanks in advance..
-Sami.
Nov 18 '05 #1
2 5331
You need to wire the event handler for the DataGrid's ItemCommand event? Do
yiou have it done in code-behind in InitializeComponent method? (It looks
like dgrCaseType.ItemCommand += new
DataGridCommandEventHandler(method_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_ItemCommand" ...

or make up similar wiring in InitializeComponent 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**@discussions.microsoft.com> wrote in
message news:4D**********************************@microsof t.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="DeleteRecord" 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_ItemCommand...
I AM TOTALLY CLULESS.....WHAT AM I MISSING...
PLZ see code below.........

<asp:DataGrid ID="dgrCaseType" Runat="server" AutoGenerateColumns="False"
Width="100%" BorderWidth="2"
BorderColor="#ffffff" HeaderStyle-HorizontalAlign="Center"
AllowSorting="True" EnableViewState="True">
<AlternatingItemStyle CssClass="bg-ltgray"></AlternatingItemStyle>
<Columns>
<asp:BoundColumn HeaderText="Default Owner"
HeaderStyle-CssClass="menu_gray" DataField="CSPersonnell"
HeaderStyle-Width="150"></asp:BoundColumn>
<asp:TemplateColumn HeaderStyle-CssClass="menu_gray"
HeaderStyle-Width="150" HeaderText="Options"
ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:ImageButton ID="imgEdit" CommandName="EditRecord"
ImageUrl="../../Images/icon_edit.gif"
AlternateText="Edit" Runat="server"
Height="16" Width="16"
EnableViewState="False"></asp:ImageButton>

<asp:ImageButton ID="imgDelete" CommandName="DeleteRecord"
ImageUrl="../../Images/icon_trash.gif"
AlternateText="Delete" Runat="server"
Height="16" Width="16"
EnableViewState="False"></asp:ImageButton>
</ItemTemplate>
</asp:TemplateColumn>

</Columns>
</asp:DataGrid>

Then I have coded the following:

protected System.Web.UI.WebControls.DataGrid dgrCaseType;

protected void dgrCaseType_ItemCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
switch(e.CommandName)
{
case "EditRecord":
string s=e.Item.Cells[7].Text;
break;
case "DeleteRecord":

break;
}
}

private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
this.dgrCaseType.ItemDataBound += new
System.Web.UI.WebControls.DataGridItemEventHandler (this.dgrCaseType_ItemDataBound);
}

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.dgrCaseType.ItemCommand+=new
DataGridCommandEventHandler(dgrCaseType_ItemComman d);

in your InitializeComponent (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**@discussions.microsoft.com> wrote in
message news:4D**********************************@microsof t.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="DeleteRecord" 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_ItemCommand...
I AM TOTALLY CLULESS.....WHAT AM I MISSING...
PLZ see code below.........

<asp:DataGrid ID="dgrCaseType" Runat="server" AutoGenerateColumns="False"
Width="100%" BorderWidth="2"
BorderColor="#ffffff" HeaderStyle-HorizontalAlign="Center"
AllowSorting="True" EnableViewState="True">
<AlternatingItemStyle CssClass="bg-ltgray"></AlternatingItemStyle> <Columns>
<asp:BoundColumn HeaderText="Default Owner"
HeaderStyle-CssClass="menu_gray" DataField="CSPersonnell"
HeaderStyle-Width="150"></asp:BoundColumn>
<asp:TemplateColumn HeaderStyle-CssClass="menu_gray"
HeaderStyle-Width="150" HeaderText="Options"
ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:ImageButton ID="imgEdit" CommandName="EditRecord"
ImageUrl="../../Images/icon_edit.gif"
AlternateText="Edit" Runat="server"
Height="16" Width="16"
EnableViewState="False"></asp:ImageButton>

<asp:ImageButton ID="imgDelete" CommandName="DeleteRecord"
ImageUrl="../../Images/icon_trash.gif"
AlternateText="Delete" Runat="server"
Height="16" Width="16"
EnableViewState="False"></asp:ImageButton>
</ItemTemplate>
</asp:TemplateColumn>

</Columns>
</asp:DataGrid>

Then I have coded the following:

protected System.Web.UI.WebControls.DataGrid dgrCaseType;

protected void dgrCaseType_ItemCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
switch(e.CommandName)
{
case "EditRecord":
string s=e.Item.Cells[7].Text;
break;
case "DeleteRecord":

break;
}
}

private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
this.dgrCaseType.ItemDataBound += new
System.Web.UI.WebControls.DataGridItemEventHandler (this.dgrCaseType_ItemData
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
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...
0
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...
0
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...
2
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...
4
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...
2
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...
3
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...
5
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...
1
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...
0
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,...
0
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...

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.