views:

693

answers:

3

My page is a bulk order form that has many products and various size options.

I've got a gridview that has a 3 static columns with labels. There are then some dynamically built columns.

Each of the dynamically built columns have a textbox in them. The textbox is for quantity.

Trying to either update the server with the quantity entered each time a textbox is changed (possibly ontextchanged event) or loop though each of the rows column by column and gather all the items that have a quantity and process those items and their quantities all at once (via button onclick).

If I put the process that builds the GridView behind a if(!Page.IsPostBack) then the when a textchanged event fires the gridview only gets the static fields and the dynamic ones are gone.

If I remove the if(!Page.IsPostBack) the process to gather and build the page is too heavy on processing and takes too long to render the page again.

Some advice would be appreciated.

Thanks

A: 

hi tnriverfish,

how do you build the dynamic columns? are you handling events such rowdatabound, rowcreated, or are you rendering injected html with something like:

<asp:Gridview ...>
<Columns>
    <asp:TemplateField ...>    
        <ItemTemplate>   
           <%# GetDynamicHtml(Container.DataItem) %>
        </ItemTemplate>
    </asp:TemplateField
...

Is ajax an option?

I've been working with full postbacks and haven't learned much in the way of using ajax to send back information... its on my list :-)I actually finished this piece of my project. The number of columns was a variable (based on size options for the particular items displayed).I'll post what I used below.
tnriverfish
A: 

I ended up building the columns dynamically in part by modifying and using the GridViewTemplate.cs I found here.

Since my textboxes were named based on their column name (which was based on the size options) I was able to loop through the size options and use FindControl to get the text box and its value.

protected void cmdSave_OnClick(object sender, EventArgs e)
{
    ArrayList itemsOrdered = new ArrayList();
    foreach (GridViewRow gvr in gvMainOrderForm.Rows)
    {
        Label lblItemId = (Label)(gvr.FindControl("lblItemId"));
        string itemId = lblItemId.Text;
        foreach (string availableOption in availableOptions)
        {
            TextBox tb = (TextBox)(gvr.FindControl("tb" + availableOption));
            if (tb != null && tb.Text != "")
            {
                ArrayList itemOrdered = new ArrayList();
                itemOrdered.Add(itemId);
                itemOrdered.Add(availableOption);
                itemOrdered.Add(tb.Text);
                itemsOrdered.Add(itemOrdered);
            }
        }
    }
}

If the value was not empty then I built a small array that had the product ID, size option and quantity.

Now I'll be able to use the itemsOrdered to modify my shopping cart.

tnriverfish
A: 

I have a similar problem, I built an extended GridView which adds an "Edit" column, with nice looking textboxes in each row, so when the user clicks on Add column the "edit column" Visible state is set to true and it comes up, buen then when I click the Save button to get the data from the textboxes, immediately after the event fires the gridview is set to null and the data int he textboxes is gone.

any clues?

urielafs