Ch 15 exercise 2 don't need to call DataBind
Hi Imar,
In the solution for Ch. 15 exercise 2, you state that "Because the DropDownList control hasn't been data bound yet, it doesn't contain any items. Therefore you need to call DataBind() first."
However, I have found that this code works just fine for me in Reviews.aspx.cs
int _genreId;
protected void Page_Load(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(Request.QueryString.Get("Ge nreId")) && Page.IsPostBack == false)
{
_genreId = Convert.ToInt32(Request.QueryString.Get("GenreId") );
DropDownList1.SelectedValue = Convert.ToString(_genreId);
}
}
I have run some tests and find that it seems to work for new inserts, editing review without changing genre, and editing review and changing review's genre. Am I missing something here? Is there a case where this isn't going to work? Or are you incorrect about needing to DataBind? Why does this work when I am not calling DropDownList1.DataBind();?
Thanks.
|