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:
Code:
<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"
onrowcancelingedit="gvStudentDiagnoses_RowCancelingEdit"
onrowediting="gvStudentDiagnoses_RowEditing"
onrowupdating="gvStudentDiagnoses_RowUpdating" >
<AlternatingRowStyle BackColor="White" />
<Columns>
<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" />
</asp:GridView>
aspx.cs Codebehind for Stored procedure:
Code:
//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)
{
try
{
//create new DataTable to store output data
DataTable StudentDetails = new DataTable();
da.Fill(StudentDetails);
//bind main gridview with DataTable
gvStudentDiagnoses.DataSource = StudentDetails;
gvStudentDiagnoses.DataBind();
//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!
Code:
protected void gvStudentDiagnoses_RowEditing(object sender, GridViewEditEventArgs e)
Code:
protected void gvStudentDiagnoses_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
Code:
protected void gvStudentDiagnoses_RowUpdating(object sender, GridViewUpdateEventArgs e)