Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Professionals
ASP.NET 3.5 Professionals If you are an experienced ASP.NET programmer, this is the forum for your 3.5 questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Professionals section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old August 10th, 2011, 01:34 PM
Registered User
Join Date: Aug 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default GridView w/ StoredProc: Editing/Updating Values (C#)

Hello All,

I've been looking all over for a tutorial on how to do this correctly. I will admit, I am fairly new to .Net.

So far, I have successfully populated a GridView using a Stored Procedure. The next step would be to be able to use the Edit/Update feature of the GridView to allow users to update certain fields.

The GridView databinding occurs in the codebehind, so the examples that use SQLDataSource have been useless so far.

Any help is greatly appreciated!!

.aspx GridView:
<asp:GridView ID="gvStudentDiagnoses" runat="server" DataKeyNames="Diagnosis_ID,Person_ID,Start_Date"
        AutoGenerateColumns="False" CellPadding="5" CellSpacing="5" 
        AllowSorting="True"  EnableModelValidation="True" 
        ForeColor="#333333" GridLines="None"
          onrowupdating="gvStudentDiagnoses_RowUpdating" >
        <AlternatingRowStyle BackColor="White" />
            <asp:BoundField DataField="Group" HeaderText="Diagnosis Group"  ReadOnly="true" />
            <asp:BoundField DataField="Diagnosis" HeaderText="Diagnosis Name"  ReadOnly="true" />
            <asp:BoundField DataField="Start_Date" HeaderText="Start Date" />
            <asp:BoundField DataField="End_Date" HeaderText="End Date" />
            <asp:CommandField ShowEditButton="True" />
            <asp:BoundField DataField="Diagnosis_ID" HeaderText="Diagnosis_ID" />
aspx.cs Codebehind for Stored procedure:
//new sqlconnection
            using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["Trillium_testConnectionString"].ConnectionString))
                //new sql command to retrieve data from stored procedure
                SqlCommand cmd = new SqlCommand("wcdsb_sp_SpecEd_StudentData", cn);
                cmd.CommandType = CommandType.StoredProcedure;

                //add parameters to store proc call from request query string
                cmd.Parameters.Add("@UserID", SqlDbType.VarChar).Value = usrName;
                cmd.Parameters.Add("@School_Year", SqlDbType.VarChar).Value = strSclYr;
                cmd.Parameters.Add("@School", SqlDbType.VarChar).Value = strSchl;
                cmd.Parameters.Add("@Grade", SqlDbType.VarChar).Value = strGrd;

                //specify output parameter
                SqlParameter outparam = cmd.Parameters.Add("@DataSet", SqlDbType.VarChar);
                outparam.Value = "StudentDetails";

                //new adapter
                SqlDataAdapter da = new SqlDataAdapter(cmd);

                using (da)
                        //create new DataTable to store output data
                        DataTable StudentDetails = new DataTable();

                        //bind main gridview with DataTable
                        gvStudentDiagnoses.DataSource = StudentDetails;
                        //Bind TextBoxes with specific rows in DataTable
                        txtStudentName.Text = StudentDetails.Rows[0]["Student_Name"].ToString();
                        txtSchoolName.Text = StudentDetails.Rows[0]["School_Name"].ToString();
                        txtSchoolYear.Text = StudentDetails.Rows[0]["School_Year"].ToString();
                        txtStudentGrade.Text = StudentDetails.Rows[0]["Grade"].ToString();
                        txtLastMod.Text = StudentDetails.Rows[0]["Last_Update_Date_Time"].ToString();

                        hyplAddNewDiag.NavigateUrl = "~/AddNewDiagnosis.aspx?Person_ID=" + Request.QueryString["Person_ID"] + "&School_Year=" + strSclYr;

                    catch (Exception ex) //catch any errors
                        lblErrorMessage.Text = "Error retrieving data: " + ex.Message;

The question I have is: what do I do for these?? Please help!
protected void gvStudentDiagnoses_RowEditing(object sender, GridViewEditEventArgs e)
protected void gvStudentDiagnoses_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
protected void gvStudentDiagnoses_RowUpdating(object sender, GridViewUpdateEventArgs e)
Old November 5th, 2012, 05:50 AM
Posts: n/a
Default net grid

Dapfor provide a easily and informative tutorial for net grid which is very helpful tutorial you can visit in dapfor. com
Received Infraction

Similar Threads
Thread Thread Starter Forum Replies Last Post
GridView Column Editing snufse ASP.NET 2.0 Basics 4 December 15th, 2008 08:59 AM
editing and updating a gridview sarah lee ASP.NET 2.0 Basics 2 December 22nd, 2006 05:45 AM
Editing Updating Sorting an Unbound Gridview Robby ASP.NET 2.0 Professional 5 March 22nd, 2006 10:41 AM
Visual Basic code for Updating (Editing) DataSet11 connijean VB Databases Basics 0 May 5th, 2004 05:53 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.