Hello AG,
Based on my experience, no matter we bind GridView through
DataSourceContr ol or normal data object collection, the RowCommand and
other Row based postback event(RowUpdati ng, 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="In sert") 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.
==============a spx============ ===
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server"
AutoGenerateCol umns="false" OnRowCommand="G ridView1_RowCom mand"
OnRowDeleting=" GridView1_RowDe leting" OnRowEditing="G ridView1_RowEdi ting"
ShowFooter="Tru e">
<Columns>
<asp:BoundFie ld DataField="Cate goryID"
HeaderText="Cat egoryID" />
<asp:BoundFie ld DataField="Cate goryName"
HeaderText="Cat egoryName" />
<asp:BoundFie ld DataField="Desc ription"
HeaderText="Des cription" />
<asp:TemplateFi eld HeaderText="Tem plateField">
<ItemTemplate >
<asp:Button ID="btnEdit" runat="server" Text="Edit"
CommandName="Ed it" />
<asp:ImageButto n ID="imgBtn" runat="server"
ImageUrl="http://wcf.netfx3.com/Themes/default/images/logo.gif"
CommandName="Ed it" />
</ItemTemplate>
<FooterTemplate >
<asp:Button ID="btnInsert" runat="server" Text="Insert"
CommandName="In sert" />
</FooterTemplate>
</asp:TemplateFie ld>
<asp:CommandFie ld ShowDeleteButto n="True" />
</Columns>
</asp:GridView>
</div>
</form>
</body>
=============== =============
=========code behind========= =====
public partial class dataaccess_Cust omVOGridView : System.Web.UI.P age
{
protected void Page_Load(objec t sender, EventArgs e)
{
if (!IsPostBack)
{
BindGrid();
}
}
private void BindGrid()
{
CategoryVO[] categories = new CategoryVO[10];
for (int i = 0; i < categories.Leng th; i++)
{
CategoryVO vo = new CategoryVO();
vo.CategoryID = i + 1;
vo.CategoryName = "Category_" + vo.CategoryID;
vo.Description = "Descriptio n of " + vo.CategoryName ;
categories[i] = vo;
}
GridView1.DataS ource = categories;
GridView1.DataB ind();
}
protected void GridView1_RowCo mmand(object sender,
GridViewCommand EventArgs e)
{
Response.Write( "<br/>GridView1_RowC ommand: " + e.CommandName);
}
protected void GridView1_RowDe leting(object sender,
GridViewDeleteE ventArgs e)
{
Response.Write( "<br/>GridView1_RowD eleting " + e.RowIndex);
}
protected void GridView1_RowEd iting(object sender,
GridViewEditEve ntArgs e)
{
Response.Write( "<br/>GridView1_RowE diting " + 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/subscripti...ult.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/subscripti...t/default.aspx.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.