我有一个gridview使用列表作为它的数据源,这个列表填充使用实体框架,并传递给我的方法,这里的数据绑定到我的网格视图控件。我似乎在编辑一行时遇到问题。GridView的OnRowEditing事件处理程序没有触发
在设计师,我已经添加属性网格视图有OnRowEditing处理程序,我增加了一个按钮,进行编辑,但我OnRowEditing事件处理程序不点火。断点没有命中。
我的GridView控件
<asp:GridView runat="server"
ID="grdNotes"
OnRowCommand="grdNotes_RowCommand"
AllowPaging="true"
AllowSorting="true"
EnableTheming="true"
AutoGenerateColumns="false"
OnPageIndexChanging="grdNotes_PageIndexChanging"
OnSorting="grdNotes_Sorting"
AlternatingRowStyle-BorderColor="Yellow"
PageSize="3"
AlternatingRowStyle-BackColor="Yellow"
OnRowEditing="grdNotes_RowEditing"
OnRowDeleting="grdNotes_RowDeleting"
DataKeyNames="NotesID" >
<Columns>
<asp:BoundField HeaderText="Title" DataField="NotesTitle" SortExpression="NotesTitle">
<ItemStyle Height="20px" Width="150px" />
</asp:BoundField>
<asp:BoundField HeaderText="Text" DataField="NotesText" SortExpression="NotesText">
<ItemStyle Height="20px" Width="250px" />
</asp:BoundField>
<%-- <asp:ButtonField CommandName="EditRow" DataTextField="Edit" HeaderText="Edit" />
<asp:ButtonField CommandName="DeleteRow" DataTextField="Delete" HeaderText="Delete" />--%>
<asp:CommandField ShowEditButton="true" />
<asp:CommandField ShowDeleteButton="true" />
<asp:CommandField ShowCancelButton="true" />
</Columns>
</asp:GridView>
背后
代码我取回从Page_Init实体框架的数据。我也有全局变量
private List<NotesModel> list = new List<NotesModel>();
NotesModel nm = new NotesModel();
protected void Page_Init(object sender, EventArgs e)
{
NoteSearch ns = new NoteSearch(Business.ContextHelper.CurrentContext);
string[] urlArray = Request.RawUrl.Split('/');
string t = urlArray[4];
string[] relatedID = t.Split('=');
if (!IsPostBack)
{
// urlArray[3] is profile type , relatedID[1] is ID
list = ns.GetBasicNoteResults(nm, urlArray[3], relatedID[1]);
}
else
{
urlArray = Request.UrlReferrer.AbsoluteUri.Split('/');
t = urlArray[6];
relatedID = t.Split('=');
list = ns.GetBasicNoteResults(nm, urlArray[5], relatedID[1]);
}
GenerateGrid(list);
btnNotes.Text = "Notes: " + list.Count.ToString();
}
我的绑定方法
private void GenerateGrid(List<NotesModel> list)
{
grdNotes.DataSource = list;
grdNotes.DataBind();
int count = grdNotes.Rows.Count;
//// Hide headers we don't want to expose
//grdNotes.HeaderRow.Cells[0].Visible = false;
//grdNotes.HeaderRow.Cells[3].Visible = false;
//grdNotes.HeaderRow.Cells[4].Visible = false;
//grdNotes.HeaderRow.Cells[5].Visible = false;
//for (int i = 0; i < count; i++)
//{
// // Loop through rows and hide cells
// grdNotes.Rows[i].Cells[0].Visible = false;
// grdNotes.Rows[i].Cells[3].Visible = false;
// grdNotes.Rows[i].Cells[4].Visible = false;
// grdNotes.Rows[i].Cells[5].Visible = false;
//}
// Finally add edit/delete buttons for these click event handlers
}
我注意到最后一件事是,当我将鼠标悬停在编辑行LinkButton的,没有查询字符串,同我在分页网格的底部和我的标题。点击任何网格控件的用户转到:
http://localhost:8192/website/Company
,而不是
http://localhost:8192/website/Company/Advertiser/?id=8879
摘要
我的GridView控件的事件处理程序不火。我错过了什么来完成这项工作?
只是curiouse,做我的回答帮助你出来呢?你有没有弄清楚这个标记是什么? – jadarnel27 2013-05-22 17:01:21