SELECT SUM(saveEveryMon) AS total FROM Retirement
Thursday, July 3, 2014
bind data to html table from database in asp.net
1) design page
<table width="90%" cellpadding="10" cellspacing="1" style="padding-top: 10px; margin-top: 10px;
height: auto;">
<%=getWhileLoopData() %>
<tr>
<td bgcolor="#FCEBCF" class="text">
Your Investment Need
</td>
<td bgcolor="#FCEBCF" class="text">
<asp:Label ID="lblinvestmentneed" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td bgcolor="#FCEBCF" class="text">
Your Current Income
</td>
<td bgcolor="#FCEBCF" class="text">
<asp:Label ID="lblincome" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td bgcolor="#FCEBCF" class="text">
Monthly Balance After Investments
</td>
<td bgcolor="#FCEBCF" class="text">
<asp:Label ID="lblresult" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:Label ID="lblwarning" runat="server" Style="color: Red; font-weight: bold; float: right;"></asp:Label>
</td>
</tr>
<tr>
<td>
</td>
<td>
</td>
</tr>
</table>
2) code behind
public string getWhileLoopData()
{
string htmlStr = "", cmdstr = "";
double LumpSum;
string LeadId = Convert.ToString(Session["LeadId"]);
if (LeadId != "")
{
cmdstr = @"SELECT CalculatorName, saveEveryMon
FROM GoalPlanning
WHERE (ClientId = '" + Session["LeadId"] + "')";
}
else
{
cmdstr = @"SELECT CalculatorName, saveEveryMon
FROM GoalPlanningForGuest";
}
myConnection.Open();
SqlCommand cmd = new SqlCommand(cmdstr, myConnection);
SqlDataReader reader = cmd.ExecuteReader();
double investmentNeed = 0;
double Result = 0;
while (reader.Read())
{
string calculatorName = reader.GetString(0);
string GoalAmount = reader.GetString(1);
investmentNeed = investmentNeed + Convert.ToDouble(GoalAmount);
htmlStr += "<tr><td width='40%' bgcolor='#FCEBCF' class='text'>" + calculatorName + "</td><td width='60%' bgcolor='#FCEBCF' class='text'>" + GoalAmount + "</td></tr>";
}
myConnection.Close();
balanceDetails(investmentNeed, LeadId);
return htmlStr;
}
<table width="90%" cellpadding="10" cellspacing="1" style="padding-top: 10px; margin-top: 10px;
height: auto;">
<%=getWhileLoopData() %>
<tr>
<td bgcolor="#FCEBCF" class="text">
Your Investment Need
</td>
<td bgcolor="#FCEBCF" class="text">
<asp:Label ID="lblinvestmentneed" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td bgcolor="#FCEBCF" class="text">
Your Current Income
</td>
<td bgcolor="#FCEBCF" class="text">
<asp:Label ID="lblincome" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td bgcolor="#FCEBCF" class="text">
Monthly Balance After Investments
</td>
<td bgcolor="#FCEBCF" class="text">
<asp:Label ID="lblresult" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:Label ID="lblwarning" runat="server" Style="color: Red; font-weight: bold; float: right;"></asp:Label>
</td>
</tr>
<tr>
<td>
</td>
<td>
</td>
</tr>
</table>
2) code behind
public string getWhileLoopData()
{
string htmlStr = "", cmdstr = "";
double LumpSum;
string LeadId = Convert.ToString(Session["LeadId"]);
if (LeadId != "")
{
cmdstr = @"SELECT CalculatorName, saveEveryMon
FROM GoalPlanning
WHERE (ClientId = '" + Session["LeadId"] + "')";
}
else
{
cmdstr = @"SELECT CalculatorName, saveEveryMon
FROM GoalPlanningForGuest";
}
myConnection.Open();
SqlCommand cmd = new SqlCommand(cmdstr, myConnection);
SqlDataReader reader = cmd.ExecuteReader();
double investmentNeed = 0;
double Result = 0;
while (reader.Read())
{
string calculatorName = reader.GetString(0);
string GoalAmount = reader.GetString(1);
investmentNeed = investmentNeed + Convert.ToDouble(GoalAmount);
htmlStr += "<tr><td width='40%' bgcolor='#FCEBCF' class='text'>" + calculatorName + "</td><td width='60%' bgcolor='#FCEBCF' class='text'>" + GoalAmount + "</td></tr>";
}
myConnection.Close();
balanceDetails(investmentNeed, LeadId);
return htmlStr;
}
write in text file in asp.net
protected void imgyellow_Click(object sender, ImageClickEventArgs e)
{
StreamWriter writer;
string txtfilepath = Server.MapPath("../csspath.txt");
using (writer = new StreamWriter(txtfilepath))
{
writer.WriteLine("~/CSS/calculator.css,~/CSS/ddsmoothmenu.css");
writer.Close();
}
}
{
StreamWriter writer;
string txtfilepath = Server.MapPath("../csspath.txt");
using (writer = new StreamWriter(txtfilepath))
{
writer.WriteLine("~/CSS/calculator.css,~/CSS/ddsmoothmenu.css");
writer.Close();
}
}
Wednesday, July 2, 2014
call javascript function from codebehind in asp.net
ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "ClientScript", "ShowContentPopup();", true);
split string in asp.net
string Argument = "shekhar,amit";
string[] arg = new string[2];
arg = Argument.ToString().Split(',');
Session["LeadId"] = arg[0];
Session["ClientName"] = arg[1];
string[] arg = new string[2];
arg = Argument.ToString().Split(',');
Session["LeadId"] = arg[0];
Session["ClientName"] = arg[1];
get current date in sql
SELECT GETDATE() AS Expr1
FROM StudentAttendence
StudentAttendence --- TableName
FROM StudentAttendence
StudentAttendence --- TableName
get number of records from database with recorddate less than current date in sql
SELECT COUNT(*)
FROM SessionSchedule
WHERE (ID = @sessionScheduleId) AND (fromDate <= GETDATE())
FROM SessionSchedule
WHERE (ID = @sessionScheduleId) AND (fromDate <= GETDATE())
Subscribe to:
Posts (Atom)