Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > DataGrid ItemCommand???

Reply
Thread Tools

DataGrid ItemCommand???

 
 
=?Utf-8?B?U3llZCBTYW1pIFIuIFNoYWg=?=
Guest
Posts: n/a
 
      10-22-2004
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.........

<aspataGrid 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>
</aspataGrid>

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.
 
Reply With Quote
 
 
 
 
Teemu Keiski
Guest
Posts: n/a
 
      10-22-2004
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. http://www.velocityreviews.com/forums/(E-Mail Removed)> wrote in
message news:(E-Mail Removed)...
> 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.........
>
> <aspataGrid 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>
> </aspataGrid>
>
> 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.



 
Reply With Quote
 
 
 
 
Karl Seguin
Guest
Posts: n/a
 
      10-22-2004
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. (E-Mail Removed)> wrote in
message news:(E-Mail Removed)...
> 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.........
>
> <aspataGrid 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>
> </aspataGrid>
>
> 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.



 
Reply With Quote
 
Rahim Rahim is offline
Junior Member
Join Date: Mar 2008
Posts: 1
 
      03-10-2008
Hi all,
I have a datagrid in which a link button is there.The problem is after clicking the link button it takes long time to fire the event. But the appliaction have same features in other page where it works fine. Can you suggest what to do. I have reset the iis-server too.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Datagrid: how cut short display of a long description in a datagrid column Brian K. Williams ASP .Net 0 03-02-2004 08:35 PM
RE: Datagrid: how cut short display of a long description in a datagrid column =?Utf-8?B?U3VyZXNo?= ASP .Net 0 03-02-2004 08:31 PM
datagrid in datagrid BK Kim ASP .Net 1 03-02-2004 06:34 AM
Call Datagrid Command column outside datagrid Dave ASP .Net 0 11-20-2003 11:11 AM
To all Gurus: How can I edit/update a DataGrid in a DataGrid (nested DataGrid)? Possible? Andreas Klemt ASP .Net Datagrid Control 0 10-08-2003 01:19 AM



Advertisments