If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
Bored? Visit http://www.kaelisspace.com/
Is it generating the edit button in the first column (default)?
If it is, cell 0 has that, not your item template.
Edit: never mind, this is in the row editing event - the cell hasn't generated the edit template yet I don't think.
I'm testing to confirm that notion.
Edit#2: confirmed with test code.
Why aren't you binding that drop down? Then you wouldn't have to worry about it...
__________________
If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
Bored? Visit http://www.kaelisspace.com/
This is full test code, using Northwind, showing binding the drop down list and showing that the event RowEditing is actually still looking at the item template, not edit item template.
I thought that might be the case when I noticed (breakpoints and tracing) that the GridView did not yet have an edit row set. It was -1.
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class FunWithGridView : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
object o = GridView1.Rows[e.NewEditIndex].Cells[4].FindControl("Label1"); // this works
object o2 = GridView1.Rows[e.NewEditIndex].Cells[4].FindControl("ddlCategory"); // this doesn't
int i = 0; // put breakpoint here to test
}
}
__________________
If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
Bored? Visit http://www.kaelisspace.com/
I found this, and it addresses the issue with handling edit, why it doesn't work, and getting the edit item template controls via the RowCreated event. http://forums.asp.net/p/1010076/1661205.aspx
__________________
If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
Bored? Visit http://www.kaelisspace.com/