This is a migrated thread and some comments may be shown as answers.

Textbox in edit form questions

1 Answer 24 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Laura
Top achievements
Rank 1
Laura asked on 24 Sep 2008, 06:27 PM
I have a grid of users. In the edit form for editing or adding a user,
I have a 2 embedded grids - one is the default chosen package and there is one
price associated with that package, and the price is a hidden column in the
embedded grid. I take that price, and put it in a textbox to put in the form.
The second embedded grid is a list of additional items that can be added to
the existing package, and each line item can have it's own price, and I have
a column template of a radnumeric textbox that the user enters a price if they
want to add the item. I also have a textbox placed under the chosen package
price that should show the total price of all additional items chosen. And
finally I want a 3rd text box showing the grand total price.

I got the first text box working fine. My first problem is that
when a user changes the price in the grid, my footer and textbox of totals
do  not change.
I have the text box being set in the itemdatabound call for the grid:


  if (e.Item is GridDataItem)
            {
                GridDataItem dataItem = e.Item as GridDataItem;
                 string price = dataItem["Price"].Text;

                if (price == "")
                    price = "0";
                int fieldValue = Convert.ToInt32(price);

                int total = int.Parse(TextBoxTotalAlaCartePrice.Text);
                total += fieldValue;
                TextBoxTotalAlaCartePrice.Text = total.ToString();
            }
            if (e.Item is GridFooterItem)
            {
                GridFooterItem footerItem = e.Item as GridFooterItem;
                int total = int.Parse(TextBoxTotalAlaCartePrice.Text);
                footerItem["Price"].Text = "total: " + total.ToString();
            }



And I also have an event handler when the user changes the
radnumeric text box, and I change the total there too:

 protected void RadNumericTextBox1_TextChanged(object sender, EventArgs e)
    {
        RadNumericTextBox ntb = (RadNumericTextBox)sender;
      
        string id = (ntb.NamingContainer as GridDataItem)["service_id"].Text.Trim();
        string price = ntb.Value.ToString();
        int nPrice = Convert.ToInt32(ntb.Value);
        int nTotalPrice = Convert.ToInt32(TextBoxTotalAlaCartePrice.Text);
        nTotalPrice += nPrice;
        TextBoxTotalAlaCartePrice.Text = nTotalPrice.ToString();  //textbox that holds total alacarte price
       
     //call to stored procedure to update temporary table with price change
        Insert_update_price(TextBoxTempTableName.Text, TextBoxAdditionalItemsPackageCdAla.Text, Convert.ToInt32(id), Convert.ToInt32(price));

    }


Any insight would be greatly appreciated.

Thanks,
Laura

1 Answer, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 29 Sep 2008, 06:54 PM
Hi Laura,

The sample code you provided seems correct. The only discrepancy between the code and the description is the following:

You said you are using all those controls when editing or adding a user, i.e. in the edit form of an item. If so, your item check in the ItemDataBound event needs to be for a GridEditFomItem and GridEditFormInsertItem respectively for edit and insert:

if(e.Item is GridEditFormItem && e.Item.IsInEditMode)
{
//...
}

Greetings,
Veli
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
Laura
Top achievements
Rank 1
Answers by
Veli
Telerik team
Share this question
or