[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

How do i loop through my gridview to save changed data?

Posted on 2011-09-05
6
Medium Priority
?
327 Views
Last Modified: 2012-05-12
I've pulled some data, into a gridview control. The gridview contains text box controls that are editable. I'd like to save the data that gets edited when the user clicks the / a save button. How do i lool through the rows in the grid view, in the code behind (C#), to process (capture) the changed data for saving?
<asp:UpdatePanel runat="server" ID="upStudentLoginGrid" UpdateMode="Conditional">
    <ContentTemplate>
        <asp:GridView ID="gdvTimeRecs" runat="server" AutoGenerateColumns="false" CssClass="SignedInGrid"
            GridLines="None" AllowSorting="true" AllowPaging="true" PageSize="20" PageIndex="0"
            PagerStyle-HorizontalAlign="Center" OnRowDataBound="gdvTimeRecs_OnRowDataBound">
            <Columns>
                <asp:TemplateField HeaderText="Student Name" ItemStyle-CssClass="StudentName">
                    <ItemTemplate>
                        <asp:Label ID="lblStudentName" runat="server" CssClass="StudentNameLabel" Text='<%# Eval("StudentName") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Student ID">
                    <ItemTemplate>
                        <asp:Label ID="lblAthleteUid" runat="server" Text='<%# Eval("StudentId") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Time In">
                    <ItemTemplate>
                        <%--<asp:Label ID="lblTimeIn" runat="server" Text='<%# Eval("TimeIn") %>'></asp:Label>--%>
                        <asp:TextBox ID="tbxTimeIn" runat="server" Text='<%# Eval("TimeIn") %>' Width="150px"></asp:TextBox>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Time Out">
                    <ItemTemplate>
                        <%--<asp:Label ID="lblTimeOut" runat="server" Text='<%# Eval("TimeOut") %>'></asp:Label>--%>
                        <asp:TextBox ID="tbxTimeOut" runat="server" Text='<%# Eval("TimeOut") %>' Width="150px"></asp:TextBox>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
    </ContentTemplate>
</asp:UpdatePanel>

Open in new window

0
Comment
Question by:Michael Sterling
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 1

Author Comment

by:Michael Sterling
ID: 36486236
i should add that the button the user will click to save the changed data, is on a page that contains the user control that contains the grid...
0
 
LVL 1

Author Comment

by:Michael Sterling
ID: 36490599
@disrupt: based on your response, (the link) and the research / testing i've done (don't worry you'll get full credit ;-) ) i'm guessing that in order to "grab" the values that populate the grid, the values need to be in TextBox controls? in my code snippet below, ran against the same grid defined above,...i can get the text from the TextBox controls, but the not the <asp:Lable> control, (which on the code side I had to cast to a LiteralControl). Is there a way to grab the value of the label in the grid?
//i get the value that is in the TextBox, (test), but not the value //from the lable (test1)...

        string test = "";
        string test1;
        foreach (GridViewRow row in gdvTimeRecs.Rows)
        {
            TextBox txbx = (TextBox)row.FindControl("tbxTimeIn");
            
            if ( txbx != null)
                test = txbx.Text;

            test1 = ((LiteralControl)(row.Cells[0].Controls[0])).Text;

        }

Open in new window

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 16

Accepted Solution

by:
disrupt earned 2000 total points
ID: 36490759
have you tried:

Label testL = (Label)row.FindControl("lblAthleteUid");

0
 
LVL 16

Expert Comment

by:disrupt
ID: 36490774
If you have trouble using the code above and  picking it up you can use a recurisve find :)

http://sharpertutorials.com/recursive-findcontrol/

Note: you wont need to iterate through the gridview with the recursive find.
0
 
LVL 1

Author Closing Comment

by:Michael Sterling
ID: 36490839
that did it. seemed like i'd tried that before. but maybe i'd only tried something similar or close to that, and well,...almost only counts in horse shoes and hand grenades,... so thanks...
0

Featured Post

What’s Wrong with Your Cloud Strategy ?

Even as many CIOs are embracing a cloud-first strategy, the reality is that moving to the cloud is a lengthy process and the end-state is likely to be a blend of multiple clouds—public and private. Learn why multicloud solutions matter in this webinar by Nimble Storage.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question