Hello AG,
Based on my experience, no matter we bind GridView through
DataSourceControl or normal data object collection, the RowCommand and
other Row based postback event(RowUpdating, RowEditing .... ) should work.
For your scenario, I think it is likely a page or control specific issue.
Here is a smiple test page with a GridView that bind to a custom class
Array, and I use a submit button and image button in the TemplateColumn,
also a submit button(with CommandName="Insert") in the footer template,
all
these buttons can trigger the RowXXX event correctly. I've included the
complete page's aspx and codebehind source below, you can test it on your
side to see whether it works.
==============aspx===============
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="false" OnRowCommand="GridView1_RowCommand"
OnRowDeleting="GridView1_RowDeleting" OnRowEditing="GridView1_RowEditing"
ShowFooter="True">
<Columns>
<asp:BoundField DataField="CategoryID"
HeaderText="CategoryID" />
<asp:BoundField DataField="CategoryName"
HeaderText="CategoryName" />
<asp:BoundField DataField="Description"
HeaderText="Description" />
<asp:TemplateField HeaderText="TemplateField">
<ItemTemplate>
<asp:Button ID="btnEdit" runat="server" Text="Edit"
CommandName="Edit" />
<asp:ImageButton ID="imgBtn" runat="server"
ImageUrl="
http://wcf.netfx3.com/Themes/default/images/logo.gif"
CommandName="Edit" />
</ItemTemplate>
<FooterTemplate>
<asp:Button ID="btnInsert" runat="server" Text="Insert"
CommandName="Insert" />
</FooterTemplate>
</asp:TemplateField>
<asp:CommandField ShowDeleteButton="True" />
</Columns>
</asp:GridView>
</div>
</form>
</body>
============================
=========code behind==============
public partial class dataaccess_CustomVOGridView : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindGrid();
}
}
private void BindGrid()
{
CategoryVO[] categories = new CategoryVO[10];
for (int i = 0; i < categories.Length; i++)
{
CategoryVO vo = new CategoryVO();
vo.CategoryID = i + 1;
vo.CategoryName = "Category_" + vo.CategoryID;
vo.Description = "Description of " + vo.CategoryName;
categories
= vo;
}
GridView1.DataSource = categories;
GridView1.DataBind();
}
protected void GridView1_RowCommand(object sender,
GridViewCommandEventArgs e)
{
Response.Write("<br/>GridView1_RowCommand: " + e.CommandName);
}
protected void GridView1_RowDeleting(object sender,
GridViewDeleteEventArgs e)
{
Response.Write("<br/>GridView1_RowDeleting " + e.RowIndex);
}
protected void GridView1_RowEditing(object sender,
GridViewEditEventArgs e)
{
Response.Write("<br/>GridView1_RowEditing " + e.NewEditIndex);
}
}
==========================
=========custom class===============
public class CategoryVO
{
private int _id;
private string _name;
private string _description;
public CategoryVO()
{
}
public CategoryVO(int id, string name, string description)
{
_id = id;
_name = name;
_description = description;
}
public int CategoryID
{
get { return _id; }
set { _id = value; }
}
public string CategoryName
{
get { return _name; }
set { _name = value; }
}
public string Description
{
get { return _description; }
set { _description = value; }
}
}
=================================
Please feel free to let me know if you have any further questions or new
finding.
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.