G
Guest
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.
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.