Accessing webform textbox.text from a loop
I'm trying to extract the text from 20 textboxes in a webform and place the information into my database using entity framework. The project builds fine but I keep getting a null error exception on the quicklistitems.Item = ((TextBox)FindControl("txtListItem" + i)).Text; line during testing. I'm not sure if this is the right track or if there is a better class/method to use for pulling data from web controls with loops. I would appreciate any help anyone may be able to provide.
for (int i = 1; i <= 20; i++)
{
var quicklistitems = new QuickListItem();
quicklistitems.ListID = quicklist.ID;
quicklistitems.Item = ((TextBox)FindControl("txtListItem" + i)).Text;
context.QuickListItems.AddObject(quicklistitems);
}
context.SaveChanges();
Thanks,
FOD
|