Stored procedure and ASP .net

.aspx

<fieldset>
<div>
<asp:GridView ID="gvwReviewTheory" runat="server" AutoGenerateColumns="False" GridLines="None"
AllowPaging="False" AllowSorting="True" CssClass="mGrid" PagerStyle-CssClass="pgr"
AlternatingRowStyle-CssClass="alt">
<Columns>
<asp:TemplateField HeaderText="Roll">
<ItemTemplate>
<asp:Label ID="lblStudentId" Text='<% #Eval("StudentId") %>' runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Attendance (30)">
<ItemTemplate>
<asp:Label ID="lblAttendance" Text='<% #Eval("Attendance") %>' runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Section A (105)">
<ItemTemplate>
<asp:Label ID="lblSectionA" Text='<% #Eval("SectionA") %>' runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Section B (105)">
<ItemTemplate>
<asp:Label ID="lblSectionB" Text='<% #Eval("SectionB") %>' runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Total CT (60)">
<ItemTemplate>
<asp:Label ID="lblTotalClassTest" Text='<% #Eval("TotalClassTest") %>' runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Total (300)">
<ItemTemplate>
<asp:Label ID="lblTotal" Text='<% #Eval("Total") %>' runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Total (%)">
<ItemTemplate>
<asp:Label ID="lblPercentTotal" Text='<% #Eval("PercentTotal") %>' runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Grace">
<ItemTemplate>
<asp:TextBox ID="txtGrace" SkinID="special" runat="server" Text='<% #Eval("Grace") %>' onKeyPress="return isNumberKey(event)"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
<div align="center">
<asp:Button ID="btnSubmit" runat="server" Text="Update" OnClick="btnSubmit_Click" />
</div>
</fieldset>

.aspx.cs

void BindGrid()
{
String ConString = ConfigurationManager.ConnectionStrings["RegistrationandExamination"].ConnectionString.ToString();
String SqlString = "sp_ReviewResult";
SqlCommand cmd = new SqlCommand();
SqlConnection con = new SqlConnection(ConString);
con.Open();
cmd.Connection = con;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = SqlString;
cmd.Parameters.AddWithValue("@TermId", ddlTermId.Text);
cmd.Parameters.AddWithValue("@CourseId", ddlCourseId.Text);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
DataTable dt = ds.Tables[0];
gvwReviewTheory.DataSource = dt;
gvwReviewTheory.DataBind();
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
String strTermId = ddlTermId.Text.Trim();
String strCourseId = ddlCourseId.Text.Trim();
try
{
foreach (GridViewRow grRow in gvwReviewTheory.Rows)
{
String ConString = ConfigurationManager.ConnectionStrings["RegistrationandExamination"].ConnectionString.ToString();
String SqlString = "sp_GraceTheory";
SqlCommand cmd = new SqlCommand();
SqlConnection con = new SqlConnection(ConString);
con.Open();
Label lblStudentId = ((Label)grRow.FindControl("lblStudentId"));
TextBox txtGrace = ((TextBox)grRow.FindControl("txtGrace"));
Int32 StudentId = Convert.ToInt32(lblStudentId.Text);
Decimal Grace = Convert.ToDecimal(txtGrace.Text);
cmd.Connection = con;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = SqlString;
cmd.Parameters.AddWithValue("@TermId", strTermId);
cmd.Parameters.AddWithValue("@CourseId", strCourseId);
cmd.Parameters.AddWithValue("@StudentId", StudentId);
cmd.Parameters.AddWithValue("@Grace", Grace);
cmd.ExecuteNonQuery();
con.Close();
}
}
catch (SqlException sqlex)
{
}
BindGrid();
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s