Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

save all gridview updates

Posted on 2011-02-25
3
Medium Priority
?
213 Views
Last Modified: 2012-05-11
have a gridview with checkboxes - allow the user to check/uncheck a row. how do i save all the changes instead of going row by row edits?

asp:GridView ID="grdvwD" runat="server" AutoGenerateColumns="False" 
    CellPadding="4" ForeColor="#333333" 
    GridLines="None" DataKeyNames="ID" AllowSorting="True" 
    ondatabound="grdvwD_DataBound" onsorting="grdvwD_Sorting">
    <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
    <Columns>
        <asp:TemplateField>
           <ItemTemplate>
                <asp:CheckBox ID="chkStatus" runat="server" />
           </ItemTemplate>                    
        </asp:TemplateField>
        <asp:BoundField DataField="ID" HeaderText="ID" SortExpression="ID" InsertVisible="False" ReadOnly="True" Visible="False" />
        <asp:TemplateField HeaderText="Active"  SortExpression="Active" >
           <ItemTemplate >
                <asp:Label ID="lblActive" runat="server" Text='<%# Eval("Active") %>'></asp:Label>
           </ItemTemplate>                    
        </asp:TemplateField>
        <asp:BoundField DataField="Center Name" HeaderText="Center Name" 
            SortExpression="Center Name" />
    </Columns>
    <EditRowStyle BackColor="#999999" />
    <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
    <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
    <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
    <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
    <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
    <SortedAscendingCellStyle BackColor="#E9E7E2" />
    <SortedAscendingHeaderStyle BackColor="#506C8C" />
    <SortedDescendingCellStyle BackColor="#FFFDF8" />
    <SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</asp:GridView>

<asp:Button ID="btnSave" runat="server" Text="Save" onclick="btnSave_Click" />



protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                loadDataGrid();
            }
	}


protected void loadDataGrid()
        {
            SQLQryString = "select from db tbl";
            SQLCmd = new SqlCommand(SQLQryString);

            using (SQLCon = new SqlConnection(SQLConnectionString))
            {
                SQLCmd.Connection = SQLCon;

                SQLCon.Open();
                SQLCmd.ExecuteNonQuery();

                SQLDR = SQLCmd.ExecuteReader();

                grdvwD.DataSource = SQLDR;
                grdvwD.DataBind();
            }
        }


        protected void btnSave_Click(object sender, EventArgs e)
        {
            //saveDataGrid();

        }

Open in new window

0
Comment
Question by:vicomin
[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
  • 2
3 Comments
 
LVL 13

Accepted Solution

by:
Rahul Agarwal earned 2000 total points
ID: 34981092
you can use the following code:

foreach (GridViewRow currentRow in grdHierarchy.Rows)

{if (((CheckBox)currentRow.FindControl("chkSelect")).Checked == true)

{

Get the template name and save it in database
}
}


0
 

Author Comment

by:vicomin
ID: 34982046
does this make sense? but I'm not sure how to do this or get the databound value of ID


protected void btnSave_Click(object sender, EventArgs e)
        {
            //string rowId = string.Empty;
            //string activeValue = string.Empty;

            //update each row - use value of ID and value of lblActive
            foreach (GridViewRow currentRow in grdvwD.Rows)
            {
                //how do i get the id when it is a bound field? do i need to convert it to a template field?

                Label lbl = (Label)currentRow.FindControl("lblActive");

                //update the row
                saveDataGrid(rowId, lbl.Text); //method call to update database table
            }
        }

Open in new window

0
 

Author Comment

by:vicomin
ID: 34982905
one more quick question - what i've got modifies all of the rows even if the user did not change anything. how do i detect only the changed rows?
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

618 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