Row is null after formview insert??
Hi
My screen has a gridview for Orders, followed by a formview for editing or inserting orders.This is followed by another gridview containing parts used on the order, followed by another formview for inserting new parts after clicking an Add Part button.
The button runs the following code:
protected void buttAddParts_Click(object sender, EventArgs e)
{
//Insert Order - Add Parts button
try
{
this.fvSloParts.ChangeMode(FormViewMode.Insert);
if (this.fvSloParts.Row.RowState == DataControlRowState.Insert)
{
if (fvSloParts.Row.RowType == DataControlRowType.DataRow)
{
// Set the sloID field to the same as parent
TextBox myText2 = (TextBox)fvSloParts.FindControl("sloIDTextBox1");
if (myText2 != null)
{
TextBox myText3 = (TextBox)fvSingleLineOrders.FindControl("txtSloId" );
int number = Convert.ToInt32(myText3.Text);
myText2.Text = number.ToString();
gvSingleLineOrders.DataSourceID = "SqlSingleLineOrderList";
gvSingleLineOrders.DataBind();
this.pnlSloParts.Visible = true;
this.pnlShowParts.Visible = false;
}
else
{
Tools.Log("Cannot find control sloIDTextBox1");
}
}
}
}
catch (Exception ex)
{
Tools.Log("buttAddParts_Click", ex);
}
}
After adding the part, there is an Insert button that completes the insert:
protected void InsertButton_Click1(object sender, EventArgs e)
{
//Insert Orders - Add Parts - Add Part button
this.pnlSloParts.Visible = false;
this.pnlShowParts.Visible = true;
gvSloParts.DataSourceID = "SqlSloParts";
gvSloParts.DataBind();
gvSingleLineOrders.DataSourceID = "SqlSingleLineOrderList";
gvSingleLineOrders.DataBind();
}
Now, when I go to add another part, it crashes on the line:
if (this.fvSloParts.Row.RowState == DataControlRowState.Insert)
Because Row is null. How do I make it work please?
Stapes
|