Link to home
Start Free TrialLog in
Avatar of rito1
rito1

asked on

Updating Multiple Gridview Rows Simultaneously

Hi All

I am looking vor a VB solution that enables me to load a Gridview with all loaded rows to be editable and that can be updated Simultaneously via 1 button click event.

Does anyone know of any?

Rit
Avatar of cmhunty
cmhunty

Instead of binding the columns using asp:BoundField in the gridview, create a template field and build up your item template columns with textboxes, dropdowns etc and set the values to the data. For example:

                <asp:TemplateField HeaderText="First Name">
                    <ItemTemplate>
                        <asp:TextBox ID="tbFirstName" runat="server" Text='<%# Eval("FirstName") %>'></asp:TextBox>
                    </ItemTemplate>
                </asp:TemplateField>

Then you'll need to save the primary key against each row - best to do this in the datakeynames of the grid view.

When the update button is pressed, you can iterate through the rows of the gridview and make an update statement based on the values on the text boxes. This can then be executed.

Avatar of rito1

ASKER

thanks cmhunty,

Please could you share with me which event I would use to perform the update action and also an example of how to iterate thru the rows of the gridview?

many thanks

Rit
ASKER CERTIFIED SOLUTION
Avatar of cmhunty
cmhunty

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rito1

ASKER

Excellent, thanks cmhunty. I'll give it a try.

Rit
what if its wasnt a textbox ?????  what if it was a dropdownlist
Avatar of rito1

ASKER

Hi trjmkztdg,

Instead of this...

CType(gvr.FindControl("tbFirstName"), TextBox).Text

I believe you would change it to either of these depending on whether you want to obtain the dropdownlist's selected value or selected text...

CType(gvr.FindControl("tbFirstName"), DropDownList).SelectedValue
CType(gvr.FindControl("tbFirstName"), DropDownList).SelectedItem.Text

Hope this is what you were looking for.

Rit