asked on
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="ddlSelectStudent" runat="server" AutoPostBack="True" DataSourceID="sdsSelectStudent" DataTextField="StudentFirstName" DataValueField="StudentId" OnSelectedIndexChanged="ddlSelectStudent_SelectedIndexChanged"></asp:DropDownList>
<br />
<table id="tblEditBasicProfile" runat="server" style="width: 600px" border="1">
<tr>
<th>First Name</th>
<td class="TableLabel">
<asp:Label ID="lblFirstName" class="TableLabel" runat="server"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtFirstName" class="TableTextBox" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<th>Middle Name</th>
<td class="TableLabel">
<asp:Label ID="lblMiddleName" class="TableLabel" runat="server"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtMiddleName" class="TableTextBox" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<th>Last Name</th>
<td class="TableLabel">
<asp:Label ID="lblLastName" class="TableLabel" runat="server"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtLastName" class="TableTextBox" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<th>SPED</th>
<td class="TableLabel">
<asp:CheckBox ID="CkBxSPED" runat="server" />
</td>
<td>
<asp:CheckBox ID="CkBxEditSPED" runat="server" />
</td>
</tr>
<tr ID="CommandRow">
<th>
</th>
<td>
<asp:Button ID="btnEdit" runat="server" Text="Edit" OnClick="btnEdit_Click" /><br />
</td>
<td>
<asp:Button ID="btnUpdateStudentProfile" runat="server" Text="Update" Visible="false" OnClick="btnUpdateStudentProfile_Click" />
<asp:Button ID="btnCancelEditStudentProfile" runat="server" Text="Cancel" Visible="false" OnClick="btnCancelEditStudentProfile_Click" />
</td>
</tr>
</table>
</div>
<asp:SqlDataSource ID="sdsSelectStudent" runat="server" ConnectionString="<%$ ConnectionStrings:XXXXXXXXX %>" SelectCommand="usp..." SelectCommandType="StoredProcedure">
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:XXXXXXXXX %>" SelectCommand="SELECT [StudentId], [StudentFirstName], [StudentMiddleName], [StudentLastName], [SPED] FROM [StudentInfo] WHERE ([StudentId] = @StudentId)">
<SelectParameters>
<asp:ControlParameter ControlID="ddlSelectStudent" Name="StudentId" PropertyName="SelectedValue" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Student_Profile : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void ddlSelectStudent_SelectedIndexChanged(object sender, EventArgs e)
{
btnEdit.Visible = true;
btnUpdateStudentProfile.Visible = false;
btnCancelEditStudentProfile.Visible = false;
DataView dv = (DataView)SqlDataSource1.Select(DataSourceSelectArguments.Empty);
foreach (DataRowView drv in dv)
{
lblFirstName.Text = drv["StudentFirstName"].ToString();
lblMiddleName.Text = drv["StudentMiddleName"].ToString();
lblLastName.Text = drv["StudentLastName"].ToString();
string statusCkBxSPED = drv["SPED"].ToString();
{
if (statusCkBxSPED == "1")
CkBxSPED.Checked = true;
}
}
protected void btnEdit_Click(object sender, EventArgs e)
{
btnEdit.Visible = false;
btnUpdateStudentProfile.Visible = true;
btnCancelEditStudentProfile.Visible = true;
DataView dv = (DataView)SqlDataSource1.Select(DataSourceSelectArguments.Empty);
foreach (DataRowView drv in dv)
{
txtFirstName.Text = drv["StudentFirstName"].ToString();
txtMiddleName.Text = drv["StudentMiddleName"].ToString();
txtLastName.Text = drv["StudentLastName"].ToString();
string status2CkBxSPED = drv["SPED"].ToString();
{
if (status2CkBxSPED == "1")
CkBxEditSPED.Checked = true;
}
}
}
protected void btnUpdateStudentProfile_Click(object sender, EventArgs e)
{
string StudentId = (String)ddlSelectStudent.SelectedValue;
int intSPED = 0;
if (CkBxEditSPED.Checked == true)
intSPED = 1;
string connStr2 = System.Configuration.ConfigurationManager.ConnectionStrings["XXXXXXXXX"].ConnectionString;
SqlConnection conn2 = new SqlConnection(connStr2);
SqlCommand cmd = new SqlCommand("usp...", conn2);
cmd.CommandType = CommandType.StoredProcedure;
{
cmd.Parameters.Add("@StudentId", StudentId);
cmd.Parameters.Add("@StudentFirstName", txtFirstName.Text);
cmd.Parameters.Add("@StudentMiddleName", txtMiddleName.Text);
cmd.Parameters.Add("@StudentLastName", txtLastName.Text);
cmd.Parameters.Add("@SPED", intSPED);
conn2.Open();
cmd.ExecuteNonQuery();
conn2.Close();
Response.Redirect("../_TeacherPages/StartInsert.aspx", true);
}
}
}