Hi,everybody,
I just encountered a hard problem.First,I create a master page,and add some controls in the master page.Then I created another aspx page using the master page created before.
So,I add a gridview in this aspx page in the ContentPlaceHolder,like before,I did some basic actions,add,update,select etc.The problem is when I edit a row in the gridview,then update it,the cell's content became noting in it.
I try to set the breakpoint in the GridView1_RowUpdating event,and the I followed the sentence,but I got nothing in the cell,code following:
Code:
using (NorthwindEntities ctx = new NorthwindEntities())
{
var categoryid = (int)this.GridView1.DataKeys[e.RowIndex].Value;
var category = ctx.Categories.First(p => p.CategoryID == categoryid);
DropDownList ddlUpdateCategory = this.GridView1.Rows[e.RowIndex].Cells[2].FindControl("ddlUpdateCategory") as DropDownList;
if (ddlUpdateCategory.SelectedItem.Text.Trim() != category.CategoryName)
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "MyScript", "alert('Already Exists!');", true);
return;
}
category.CategoryName = ddlUpdateCategory.SelectedItem.Text.Trim();
category.Description = ((TextBox)this.GridView1.Rows[e.RowIndex].FindControl("txtDes")).Text.Trim();
ctx.SaveChanges();
}
GridView1.EditIndex = -1;
BindGridView();
What an odd thing! You konw, when I did the same thing in another newly-created aspx page without master page, it worked fine.
I just wonder if it had something with the master page.If I use the master page, the findcontrol() method just conuln't find the textbox control in the EditItemTemplate.
Who can help me? The problem has been bothering me for a couple of hours.
Thanks in advance!