G
Guest
Hi,
Im very new to c#, so forgive me if this is a really stupid question.
Im trying to create a form for entering purchase requests.
For each line item I have a quantity, a description unit cost and total cost.. all textboxes.
Next to this I have a button that will add a new set of textboxes so people can have more than one line item.
As it is now, when you push the button the textboxes appear, and everything below them is moved down accordingly, just as it should.
However, if you push the button AGAIN, the new textboxes are created, everything gets pushed down, but the previous line of created textboxes are gone.
this is how I am doing it now:
private void btnMore_Click(object sender, System.EventArgs e)
{
// local variables for base position of objects that will move
int budgetbase = 672;
int ctlbase = 672;
int chargesbase = 600;
int morebase = 456;
int clearreqbase = 848;
int textboxbase = 456;
lineitems = Convert.ToInt32(ViewState["counter"]);
lineitems++;
ViewState["counter"] = lineitems;
// increment lineitems and calculate offset
offset = lineitems * 30;
Control frm = FindControl("Form1");
txtStatus.Text = lineitems.ToString();
// create a new quantity textbox
tb = new TextBox();
tb.ID = "Quantity"+ViewState["counter"].ToString();
tb.Style["Position"]="Absolute";
tb.Style["Left"] = "56px";
tb.Style["Top"] = System.Convert.ToString(textboxbase + offset) + "px";
tb.Width=64;
tb.Height=24;
frm.Controls.Add(tb);
tb = new TextBox();
// create a new item description textbox
tb.ID = "ItemDescription"+lineitems.ToString();
tb.Style["Position"]="Absolute";
tb.Style["Left"] = "144px";
tb.Style["Top"] = System.Convert.ToString(textboxbase + offset) + "px";
tb.Width=608;
tb.Height=24;
frm.Controls.Add(tb);
etc...
// move panels down 30 px
pnlBudget.Style["Top"] = System.Convert.ToString(budgetbase + offset) + "px";
pnlCharges.Style["Top"] = System.Convert.ToString(chargesbase + offset) + "px";
pnlCTI.Style["Top"] = System.Convert.ToString(ctlbase + offset) + "px";
//move buttons
btnMore.Style["Top"]= System.Convert.ToString(morebase + offset) + "px";
btnPurchasReq.Style["Top"]= System.Convert.ToString(clearreqbase + offset) + "px";
btnClear.Style["Top"]= System.Convert.ToString(clearreqbase + offset) + "px";
}
I have also tried setting up an array of textboxes, but I got the same result, so I have a feeling there is something else that my feeble newbie mind is not grasping here.
Thanks for any advice, and I appologize for the long post.
thanks
Jason
Im very new to c#, so forgive me if this is a really stupid question.
Im trying to create a form for entering purchase requests.
For each line item I have a quantity, a description unit cost and total cost.. all textboxes.
Next to this I have a button that will add a new set of textboxes so people can have more than one line item.
As it is now, when you push the button the textboxes appear, and everything below them is moved down accordingly, just as it should.
However, if you push the button AGAIN, the new textboxes are created, everything gets pushed down, but the previous line of created textboxes are gone.
this is how I am doing it now:
private void btnMore_Click(object sender, System.EventArgs e)
{
// local variables for base position of objects that will move
int budgetbase = 672;
int ctlbase = 672;
int chargesbase = 600;
int morebase = 456;
int clearreqbase = 848;
int textboxbase = 456;
lineitems = Convert.ToInt32(ViewState["counter"]);
lineitems++;
ViewState["counter"] = lineitems;
// increment lineitems and calculate offset
offset = lineitems * 30;
Control frm = FindControl("Form1");
txtStatus.Text = lineitems.ToString();
// create a new quantity textbox
tb = new TextBox();
tb.ID = "Quantity"+ViewState["counter"].ToString();
tb.Style["Position"]="Absolute";
tb.Style["Left"] = "56px";
tb.Style["Top"] = System.Convert.ToString(textboxbase + offset) + "px";
tb.Width=64;
tb.Height=24;
frm.Controls.Add(tb);
tb = new TextBox();
// create a new item description textbox
tb.ID = "ItemDescription"+lineitems.ToString();
tb.Style["Position"]="Absolute";
tb.Style["Left"] = "144px";
tb.Style["Top"] = System.Convert.ToString(textboxbase + offset) + "px";
tb.Width=608;
tb.Height=24;
frm.Controls.Add(tb);
etc...
// move panels down 30 px
pnlBudget.Style["Top"] = System.Convert.ToString(budgetbase + offset) + "px";
pnlCharges.Style["Top"] = System.Convert.ToString(chargesbase + offset) + "px";
pnlCTI.Style["Top"] = System.Convert.ToString(ctlbase + offset) + "px";
//move buttons
btnMore.Style["Top"]= System.Convert.ToString(morebase + offset) + "px";
btnPurchasReq.Style["Top"]= System.Convert.ToString(clearreqbase + offset) + "px";
btnClear.Style["Top"]= System.Convert.ToString(clearreqbase + offset) + "px";
}
I have also tried setting up an array of textboxes, but I got the same result, so I have a feeling there is something else that my feeble newbie mind is not grasping here.
Thanks for any advice, and I appologize for the long post.
thanks
Jason