Active Link function returning active class
<li class='<%#classActive(Eval("category_id").ToString()) %>'>
======================================================================
public string classActive(string id)
{
if (id == Convert.ToString(Request.QueryString["category_id"]))
{
return "active";
}
else return "";
}
Adrotator using xml
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:Timer ID="Timer1" runat="server" Interval="6000">
</asp:Timer>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
</Triggers>
<ContentTemplate>
<asp:AdRotator ID="AdRotator1" runat="server" Target="_blank" AdvertisementFile="~/App_Data/Ad.xml" />
</ContentTemplate>
</asp:UpdatePanel>
============================================================
In Appdata
<?xml version="1.0" encoding="utf-8" ?>
<Advertisements>
<Ad>
<ImageUrl>~/images/G_logo.png</ImageUrl>
<height>60</height>
<width>190</width>
<NavigateUrl>http://www.goldminedevelopers.net/</NavigateUrl>
<AlternateText>http://www.goldminedevelopers.net/</AlternateText>
<Impressions>10</Impressions>
<Keyword>Topic1</Keyword>
</Ad>
<Ad>
<ImageUrl>~/images/P_logo.png</ImageUrl>
<height>60</height>
<width>190</width>
<NavigateUrl>http://www.propcasa.com/</NavigateUrl>
<AlternateText>http://www.propcasa.com/</AlternateText>
<Impressions>10</Impressions>
<Keyword>Topic2</Keyword>
</Ad>
<Ad>
<ImageUrl>~/images/R_logo.png</ImageUrl>
<height>60</height>
<width>190</width>
<NavigateUrl>http://www.realtylounge.co.in</NavigateUrl>
<AlternateText>http://www.realtylounge.co.in</AlternateText>
<Impressions>10</Impressions>
<Keyword>Topic3</Keyword>
</Ad>
</Advertisements>
Back using Javascript
<tr>
<td colspan="2" align="right">
<a href="javascript:history.back()">
<img src="images/uplevel_16.gif" alt="back" />
</a>
</td>
</tr>
Calling Javascript using C# code to hide error or success msg after some time.
<script type="text/javascript">
function hideMsg() {
$('#<%=div_msg.ClientID%>').fadeOut(4000);
}
</script>
======================================================================
protected void Btn_Update_Click(object sender, EventArgs e)
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "uniquekey", "<script type='text/javascript'>hideMsg();</script>");
}
Capitalizing words in a string using c#
using System.Globalization;
protected void Page_Load(object sender, EventArgs e)
{
Page.Title = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(Request.QueryString["Title"].ToString().Replace("-", " ") + " : 3RCASA");
}
Changing color of text in gridview based on any condition.
protected void grid_resultDetail_RowDataBound(object sender, GridViewRowEventArgs e)
{
// Making incorrect ans red in final table.
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (Convert.ToString(e.Row.Cells[2].Text) != Convert.ToString(e.Row.Cells[3].Text))
{
e.Row.Cells[3].ForeColor = System.Drawing.Color.Red;
}
//Getting salary of each employee
//int Salary = int.Parse(e.Row.Cells[5].Text);
//if (Salary > 50000)
//{
// //Setting row back colour
// e.Row.BackColor = System.Drawing.Color.LightGreen;
//}
//else if (Salary < 20000)
//{
// e.Row.BackColor = System.Drawing.Color.Pink;
//}
}
}
Check Existing EmailId before updating
Alter procedure [dbo].[SP_UpdateUserDetailsByUserId]
@UserId int,
@FirstName nvarchar(200),
@LastName nvarchar(200),
@EmailID nvarchar(200),
@PhoneNo nvarchar (200),
@Country nvarchar (300),
@City nvarchar (200)
AS
BEGIN
if not exists (select EmailID from tbl_UserManagement where UserID != @UserId and EmailID=@EmailID)
begin
update tbl_UserManagement set FirstName = @FirstName,
LastName = @LastName, EmailID = @EmailID, PhoneNo = @PhoneNo, Country = @Country, City = @City
where UserID = @UserID
select @UserId
end
else
begin
select -1
end
END
Check user is logged in before posting data.
<script type="text/javascript">
function showpopup() {
var loggedin = '<%= returnStatus() %>';
if (loggedin == 'False') {
$("#newskloginForm").show();
$("#registerfromId1").hide();
$("#registerfromId2").show();
$("#registerfromId3").hide();
return false;
}
else return true;
}
</script>
=======================================================================
<asp:Button ID="btn_replysubmit" CssClass="replysubmitBoxBtn02" Text="Submit" OnClick="btn_replySubmit_Click " runat="server" OnClientClick="return showpopup()" />
=======================================================================
public bool returnStatus()
{
if (Convert.ToString(Session["User"]) != null && Convert.ToString(Session["User"]) != "")
return true;
else return false;
}
Clear TextBoxes
public void CleartextBoxes(Control parent)
{
foreach (Control c in parent.Controls)
{
if ((c.GetType() == typeof(TextBox)))
{
((TextBox)(c)).Text = "";
}
if (c.HasControls())
{
CleartextBoxes(c);
}
}
}
Checkbox
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
<script type="text/javascript">
$(function () {
$('#gallery a').lightBox();
});
function PopupCenter(pageURL, title, w, h) {
var left = (screen.width / 2) - (w / 2);
var top = (screen.height / 2) - (h / 2);
var targetWin = window.open(pageURL, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);
}
</script>
<style type="text/css">
#gallery
{
padding: 10px;
width: 520px;
}
#gallery ul
{
list-style: none;
}
#gallery ul li
{
display: inline;
}
#gallery ul img
{
border: 5px solid #3e3e3e;
border-width: 5px 5px 20px;
}
#gallery ul a:hover img
{
border: 5px solid #fff;
border-width: 5px 5px 20px;
color: #fff;
}
#gallery ul a:hover
{
color: #fff;
}
#gallery1
{
padding: 10px;
width: 520px;
}
#gallery1 ul
{
list-style: none;
}
#gallery1 ul li
{
display: inline;
}
#gallery1 ul img
{
border: 5px solid #3e3e3e;
border-width: 5px 5px 20px;
}
#gallery1 ul a:hover img
{
border: 5px solid #fff;
border-width: 5px 5px 20px;
color: #fff;
}
#gallery1 ul a:hover
{
color: #fff;
}
</style>
<script src="js/jquery.js" type="text/javascript"></script>
<script type="text/javascript">
var TargetBaseControl = null;
window.onload = function () {
try {
//get target base control.
TargetBaseControl =
document.getElementById('<%= this.grid_Image.ClientID %>');
}
catch (err) {
TargetBaseControl = null;
}
}
function TestCheckBox() {
if (TargetBaseControl == null) return false;
//get target child control.
var TargetChildControl = "CheckBox1";
//get all the control of the type INPUT in the base control.
var Inputs = TargetBaseControl.getElementsByTagName("input");
for (var n = 0; n < Inputs.length; ++n)
if (Inputs[n].type == 'checkbox' && Inputs[n].id.indexOf(TargetChildControl, 0) >= 0 && Inputs[n].checked) {
return false;
}
else {
return true;
}
}
alert('Please Select atleast one Case.');
return false;
}
</script>
<script type="text/javascript">
var count = 0;
function CountChkBx(id) {
var checkbox = document.getElementById(id);
if (checkbox.checked) {
if (count < 8 && checkbox.type == 'checkbox') {
count++;
checkbox.checked = true;
return true;
}
else {
alert('Maximum 8 records can be selected at a time');
checkbox.checked = false;
return false;
}
}
else {
count--;
checkbox.checked = false;
}
}
function setcount() {
count = 0;
}
</script>
<script type="text/javascript">
function SelectAllCheckboxes(chk) {
var i = 0;
if (chk.checked) {
$('#<%=grid_Image.ClientID %>').find("input:checkbox").each(function () {
if (this != chk) {
this.checked = chk.checked;
}
});
}
else {
$('#<%=grid_Image.ClientID %>').find("input:checkbox").each(function () {
this.checked = chk.checked;
});
}
}
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<div id="loading-header">
<div class="header-row">
<div class="span24">
<header>
<h1 class="header-main">Share Lead</h1>
</header>
<div style="padding: 7px 10px;">
<a href="manage_lead.aspx" style="border: 1px solid; padding: 3px; text-decoration: none;">
Manage Lead</a></div>
</div>
</div>
<div style="height: 25px;">
</div>
</div>
<div style="margin-top: 30px; text-align: center; width: 100%;">
<div id="div_message" runat="server" visible="false" class="header-mainnew" style="height: 25px;
width: 70%; text-align: left; padding: 0px 10px 10px 180px; margin-bottom: 10px;
margin-top: 0px; vertical-align: text-top;">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td valign="middle" width="25px">
<asp:Image ID="img_right" ImageUrl="~/images/button_ok.png" Height="30px" Width="30px"
runat="server" Visible="false" />
<asp:Image ID="img_error" ImageUrl="~/images/error.png" Height="30px" Width="30px"
runat="server" Visible="false" />
</td>
<td valign="middle">
<asp:Label ID="lblMsg" runat="server"></asp:Label>
</td>
</tr>
</table>
</div>
<div id="Div_Image" runat="server" style="text-align: left; width: 100%; padding-left: 50px;">
<table cellpadding="0" cellspacing="0" border="0" width="100%">
<tr>
<td height="10px">
</td>
</tr>
<tr>
<%-- <td height="40px" style="padding-top: 5px; font-size: 15px; padding-left: 50px;">
Total Comments <span style="height: 40px; color: #000000;">(<%=countAgent%>)</span>
</td>--%>
<td>
<asp:TextBox ID="txt_search" align="left" Height="20px" placeholder="Search By Agent Name, Email ID, Phone No"
runat="server" Width="320px"></asp:TextBox>
<asp:Button ID="btn_search" runat="server" Text="Search" OnClick="btn_search_Click">
</asp:Button>
</td>
</tr>
<tr>
<td height="20px">
</td>
</tr>
<tr>
<td colspan="2" height="10px" align="left">
<asp:GridView ID="grid_Image" runat="server" Width="90%" AutoGenerateColumns="False"
DataKeyNames="AgentID" CellPadding="3" ForeColor="#333333" GridLines="None" AllowPaging="true"
PageSize="30" OnPageIndexChanging="grid_Image_PageIndexChanging">
<RowStyle BackColor="#ffffff" HorizontalAlign="Center" />
<AlternatingRowStyle BackColor="#ffffff" HorizontalAlign="Center" />
<Columns>
<asp:TemplateField>
<HeaderTemplate>
Sr. No.
</HeaderTemplate>
<ItemTemplate>
<%# Container.DataItemIndex + 1 %>
<asp:HiddenField ID="hdn_AgentID" runat="server" Value='<%# Eval("AgentID") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="AgentName" HeaderText="Agent Name" SortExpression="AgentName"
HeaderStyle-ForeColor="White">
<HeaderStyle ForeColor="White"></HeaderStyle>
</asp:BoundField>
<asp:BoundField DataField="EmailID" HeaderText="Email ID " SortExpression="EmailID"
HeaderStyle-ForeColor="White">
<HeaderStyle ForeColor="White"></HeaderStyle>
</asp:BoundField>
<asp:BoundField DataField="PhoneNo" HeaderText="Phone No" SortExpression="PhoneNo"
HeaderStyle-ForeColor="White">
<HeaderStyle ForeColor="White"></HeaderStyle>
</asp:BoundField>
<asp:BoundField DataField="Subject" HeaderText="Subject" SortExpression="Subject"
HeaderStyle-ForeColor="White">
<HeaderStyle ForeColor="White"></HeaderStyle>
</asp:BoundField>
<asp:TemplateField>
<HeaderTemplate>
Select
<asp:CheckBox ID="chkheader" runat="server" onclick="javascript:SelectAllCheckboxes(this);" />
</HeaderTemplate>
<HeaderStyle HorizontalAlign="Center" Font-Size="Small" />
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" />
<asp:HiddenField ID="hdn_emailID" runat="server" Value='<%# Eval("EmailID") %>' />
<asp:HiddenField ID="hdn_agentName" runat="server" Value='<%# Eval("AgentName") %>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EmptyDataTemplate>
Sorry, no data found as your search criteria.</EmptyDataTemplate>
<EmptyDataRowStyle CssClass="header-mainnew2" HorizontalAlign="Left" ForeColor="Red"
VerticalAlign="Middle" />
<FooterStyle BackColor="#0190B9" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#0190B9" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#0190B9" Font-Bold="True" ForeColor="white" HorizontalAlign="Center" />
<EditRowStyle BackColor="#2461BF" />
</asp:GridView>
</td>
</tr>
<tr>
<td height="20px">
</td>
</tr>
<tr>
<td>
<asp:Button ID="btn_SentMail" runat="server" Text="Send Mail" OnClick="btn_SentMail_Click" />
</td>
</tr>
</table>
</div>
</div>
</asp:Content>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
public partial class AdminPanel_share_lead : System.Web.UI.Page
{
public double LeadID = 0;
public string LeadName = string.Empty;
public string LeadEmailID = string.Empty;
public string LeadContactNo = string.Empty;
public string LeadCity = string.Empty;
public string LeadDate;
public string LeadStatus = string.Empty;
public string Leadmessage = string.Empty;
protected static string countAgent = "0";
Class_Lead lead = new Class_Lead();
Class_Agent objAgent = new Class_Agent();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bindgrid();
}
}
protected void btn_search_Click(object sender, EventArgs e)
{
GetAllSearchAgents();
}
private void bindgrid()
{
try
{
objAgent.GetAllAgents();
if (objAgent.OperationStatus)
{
DataTable dt = objAgent.AgentTable;
grid_Image.DataSource = dt;
grid_Image.DataBind();
}
objAgent.SearchText = "";
objAgent.GetCountAllAgent();
if (objAgent.OperationStatus)
{
countAgent = Convert.ToString(objAgent.AgentTable.Rows[0]["AgentStatus"]);
}
}
catch (Exception ex)
{
lblMsg.Text = "Error : " + ex.Message;
div_message.Visible = true;
img_error.Visible = true;
img_right.Visible = false;
lblMsg.ForeColor = System.Drawing.Color.Red;
}
}
private void GetAllSearchAgents()
{
try
{
objAgent.SearchText = txt_search.Text.ToString().Trim();
objAgent.GetAllSearchAgents();
if (objAgent.OperationStatus)
{
grid_Image.DataSource = objAgent.AgentTable;
grid_Image.DataBind();
}
}
catch (Exception ex)
{
lblMsg.Text = "Error : " + ex.Message;
lblMsg.ForeColor = System.Drawing.Color.Red;
}
}
protected void grid_Image_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
grid_Image.PageIndex = e.NewPageIndex;
bindgrid();
}
protected void btn_SentMail_Click(object sender, EventArgs e)
{
try
{
string emailList = "";
string agentList = "";
foreach (GridViewRow row in grid_Image.Rows)
{
CheckBox chk = (CheckBox)row.FindControl("CheckBox1");
if (chk.Checked == true)
{
HiddenField hdn = (HiddenField)row.FindControl("hdn_emailID");
HiddenField hdn_agentName = (HiddenField)row.FindControl("hdn_agentName");
emailList += Convert.ToString(hdn.Value) + ",";
agentList += Convert.ToString(hdn_agentName.Value) + ",";
}
}
if (emailList.Length > 1)
{
emailList = emailList.Remove(emailList.Length - 1, 1);
agentList = agentList.Remove(agentList.Length - 1, 1);
string id = Request.QueryString["Id"].ToString();
lead.LeadID = Convert.ToInt32(id);
lead.Getleadbyid();
if (lead.OperationStatus != false)
{
LeadName = lead.LeadTable.Rows[0]["LeadName"].ToString();
LeadDate = Convert.ToDateTime(lead.LeadTable.Rows[0]["LeadDate"]).ToString("dd-MMM-yyyy");
LeadEmailID = lead.LeadTable.Rows[0]["LeadEmailID"].ToString();
LeadContactNo = lead.LeadTable.Rows[0]["LeadContactNo"].ToString();
Leadmessage = lead.LeadTable.Rows[0]["LeadQuery"].ToString();
LeadStatus = lead.LeadTable.Rows[0]["LeadStatus"].ToString();
string[] agents = agentList.Split(',');
string[] agentemailID = emailList.Split(',');
int AgentNo = 0;
foreach (string agent in agents)
{
string body = "Dear " + agent + "<br/><br/>Hear is an enquiry, Details is as below.<br/><br/>Name : " + LeadName + "<br/><br/>Phone No : " + LeadContactNo + "<br/><br/>Email ID : " + LeadEmailID + "<br/><br/>Message : " + Leadmessage + "<br/><br/>Thanks<br/><br/>Noida Extension Project";
string _emailid = agentemailID[AgentNo];
Class_Additionalresources.Sendmail(_emailid, "noidaextensionproject.com", body, "www.noidaextensionproject.com", "info@noidaextensionproject.com");
AgentNo++;
}
div_message.Visible = true;
lblMsg.Text = "Email sent successfully.";
lblMsg.ForeColor = System.Drawing.Color.Green;
img_error.Visible = false;
img_right.Visible = true;
}
else
{
}
}
else
{
ScriptManager.RegisterStartupScript(this, GetType(), "alertMessage", "alert('Please select atleast one agent to send email!');", true);
}
}
catch (Exception ex)
{
div_message.Visible = true;
lblMsg.Text = "Error : " + ex.Message;
lblMsg.ForeColor = System.Drawing.Color.Red;
img_error.Visible = true;
img_right.Visible = false;
}
}
}
<asp:TemplateField>
<HeaderTemplate>
Lead Date
</HeaderTemplate>
<ItemTemplate>
<%# Convert.ToDateTime(Eval("LeadDate")).ToString("dd/MM/yyyy")%>
</ItemTemplate>
</asp:TemplateField>
Clicking ++ of listview or repeater item will show more content in popup.
</script>
function ShowSubjects(divid)
{
var id=divid.id.toString().charAt(divid.id.toString().length-1);
var value=document.getElementById('ContentPlaceHolder1_Rpt_List_hdn_subject_'+id).value
$('#div_subjects_popup').text(value);
$("#newskloginForm").show();
}
</script>
======================================================================
<asp:ListView ID="Rpt_List" runat="server">
<ItemTemplate>
<div class="FpsBox_conatiner1">
<div class="FpsBox_conatiner1_inner">
<div class="FpsBox_containetTitle">
<h3>
<%# Eval("CollegeName") %></h3>
<span>
<%#Eval("City") %></span>
<div class="FpsBox_addContainer">
<h4>Course</h4>
-------------------------------------------------------------------------------------------------------------------------
<p>
<%#Eval("Course").ToString().Length> 50 ? Eval("Course").ToString().Replace(",",", ").Substring(0,50) + ".." : Eval("Course").ToString().Replace(",",", ") %>
<b class="subjectssel" onclick="ShowSubjects(this)" style="cursor: pointer;" id="moresubjects" runat="server" visible='<%#Eval("Course").ToString().Length> 50 %>'>++</b>
<asp:HiddenField ID="hdn_subject" runat="server" Value='<%# Convert.ToString(Eval("Course")).Replace(",",", ") %>' />
</p>
--------------------------------------------------------------------------------------------------------------------------
</div>
</div>
<div class="FpsBox_footerContainer">
<div class="FpsBox_FtView_hide">
<div class="FpsBox_FtView_hide_show">
<div class="FpsBox_FtViewdetails" id="div_viewdetail" runat="server">
<a href="javascript:void()" class="View_showp newskloginBt1" onclick='ShowDetail(<%# Container.DataItemIndex %>)'>View Details</a>
</div>
<div class="FpsBox_FtView_hide_show" id="div_detail" runat="server" style="display: none;">
<strong>Email:</strong> <span>
<%#Eval("EmailID") %></span>
<br />
<strong>Mob.No.</strong> <span>
<%#Eval ("PhoneNo")%></span>
</div>
</div>
</div>
<div class="FpsBox_FtLogo">
<a style="background: #3d272b;">C</a>
</div>
</div>
<div class="clearfix">
</div>
</div>
</div>
</ItemTemplate>
</asp:ListView>
=======================================================================
<div class="skLoginbg" id="newskloginForm">
<div class="skLogin_container">
<div class="SkclosepopupBtn"><span id="skclosearroBTN">×</span></div>
<div id="registerfromId1">
<div class="Doctpopuplogo">
<img src="images/Doctpopuplogo.png" alt="Doct.in" />
</div>
<div class="subjectFormmen">
<div class="skloginFornConWapper">
<div class="FpsBox_conatiner1_2Subject">
<div class="FpsBox_conatiner1_inner">
<div class="FpsBox_addContainer">
<h4 style="margin-top: -17px; padding-bottom: 10px;">Courses</h4>
<div id="div_subjects_popup">
<%--Math, English, Science, Chemistry, Biology, History--%> </div>
</div>
<div class="FpsBox_footerContainer">
</div>
<div class="clearfix"></div>
</div>
</div>
</div>
</div>
</div>
<div class="clearfix"></div>
</div>
</div>
Code complex
alter procedure SP_GetAllClient
(
@SearchText nvarchar(50)
)
as
Begin
Select a.*,(select sum(cast(TotalBillAmount as float)) as DebitAmount from tbl_Bill where tbl_Bill.ClientId=a.ClientId group by tbl_Bill.ClientId) as debitAmount,(select sum(cast(Amount as float)) as CreditAmount from tbl_Reciept where tbl_Reciept.ClientId=a.ClientId group by tbl_Reciept.ClientId) as creditamount from tbl_Client a
where (@SearchText='' or a.Name like @SearchText+'%' or a.Email like @SearchText+'%')
order by ClientId desc
End
------------------------------------------------------------------------------------------------------------------
public void GetAllClient()
{
try
{
SqlDataAdapter ad = new SqlDataAdapter();
DataTable Sqldatatable = new DataTable();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "SP_GetAllClient";
cmd.Parameters.AddWithValue("@SearchText", SearchText);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = Connection;
ad.SelectCommand = cmd;
OpenConnection();
ad.Fill(Sqldatatable);
ClientTable = Sqldatatable;
OperationStatus = true;
CloseConnection();
Sqldatatable.Dispose();
cmd.Dispose();
ad.Dispose();
}
catch (Exception ex)
{
ErrorMessage = "Error : " + ex.Message;
OperationStatus = false;
}
finally
{
CloseConnection();
}
}
-----------------------------------------------------------------------------------------------------------------------
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
bindgrid();
}
private void bindgrid()
{
try
{
objClient.SearchText = txt_search.Text.ToString();
objClient.GetAllClient();
if (objClient.OperationStatus)
{
grid_Client.DataSource = objClient.ClientTable;
grid_Client.DataBind();
}
}
catch (Exception ex)
{
lblMsg.Text = "Error : " + ex.Message;
div_message.Visible = true;
img_error.Visible = true;
img_right.Visible = false;
lblMsg.ForeColor = System.Drawing.Color.Red;
}
}
--------------------------------------------------------------------------------------------------------------------------
public string cal(string debitamount, string creditamount)
{
string amount = "0";
if (debitamount == "" || debitamount == null)
debitamount = "0";
if (creditamount == "" || creditamount == null)
creditamount = "0";
if (Convert.ToDouble(debitamount) > Convert.ToDouble(creditamount))
{
double calamount = Convert.ToDouble(debitamount) - Convert.ToDouble(creditamount);
amount = "<span style='color:red;'> - " + calamount.ToString("0.00") + "</span>";
}
else
{
double calamount = Convert.ToDouble(creditamount) - Convert.ToDouble(debitamount);
amount = "<span style='color:green;'> " + calamount.ToString("0.00") + "</span>";
}
return amount;
}
------------------------------------------------------------------------------------------------------------------------
<td colspan="2" height="10px" align="left">
<asp:GridView ID="grid_Client" runat="server" Width="100%" AutoGenerateColumns="False"
CellPadding="3" ForeColor="#333333" GridLines="None" AllowPaging="true" PageSize="30"
Font-Size="12px" OnPageIndexChanging="grid_Client_PageIndexChanging" OnRowDataBound="grid_Client_RowDataBound"
OnRowDeleting="grid_Client_RowDeleting">
<RowStyle BackColor="#EFF3FB" HorizontalAlign="Center" Font-Size="12px" />
<AlternatingRowStyle BackColor="#EFF3FB" HorizontalAlign="Center" />
<Columns>
<asp:TemplateField>
<HeaderTemplate>
Sr. No.
</HeaderTemplate>
<ItemTemplate>
<%# Container.DataItemIndex + 1 %>
<asp:HiddenField ID="hdn_id" runat="server" Value='<%# Eval("ClientId") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" HeaderStyle-ForeColor="White" />
<asp:BoundField DataField="Email" HeaderText="Email ID" SortExpression="Email" HeaderStyle-ForeColor="White" />
<asp:BoundField DataField="ContactNo" HeaderText="Contact No" HeaderStyle-ForeColor="White" />
<asp:BoundField DataField="ContactPerson" HeaderText="Contact Person" SortExpression="ContactPerson"
HeaderStyle-ForeColor="White" />
<asp:BoundField DataField="Address" HeaderText="Address" HeaderStyle-ForeColor="White" />
<asp:TemplateField ShowHeader="True" HeaderText="Debit" HeaderStyle-ForeColor="White">
<ItemTemplate>
<%#Eval("debitAmount").ToString()%>
</ItemTemplate>
</asp:TemplateField> <asp:TemplateField ShowHeader="True" HeaderText="Credit" HeaderStyle-ForeColor="White">
<ItemTemplate>
<%#Eval("creditamount").ToString()%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ShowHeader="True" HeaderText="Total Outstanding Amount" HeaderStyle-ForeColor="White">
<ItemTemplate>
<%#cal(Eval("debitAmount").ToString(), Eval("creditamount").ToString())%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ShowHeader="True" HeaderText="Update" HeaderStyle-ForeColor="White">
<ItemTemplate>
<a href='<%# GetUrl(Convert.ToString(Eval("ClientId"))) %>'>
<img src="images/update.png" alt="Update" height="25px" width="65" /></a>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ShowHeader="True" HeaderText="Update" HeaderStyle-ForeColor="White">
<ItemTemplate>
<a href='<%# GetUrlView(Convert.ToString(Eval("ClientId"))) %>'>
<img src="images/view.gif" alt="View" height="25px" width="65" /></a>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ButtonType="Image" HeaderText="Delete" ControlStyle-Width="20px"
ControlStyle-Height="20px" DeleteImageUrl="~/images/delete.png" ShowDeleteButton="True"
DeleteText="delete">
<ItemStyle Width="50px" />
</asp:CommandField>
</Columns>
<EmptyDataTemplate>
Sorry, no data found as your search criteria.</EmptyDataTemplate>
<EmptyDataRowStyle CssClass="header-mainnew2" HorizontalAlign="Left" ForeColor="Red"
VerticalAlign="Middle" />
<FooterStyle BackColor="#31302B" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#31302B" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#31302B" Font-Bold="True" ForeColor="white" HorizontalAlign="Center" />
<EditRowStyle BackColor="#2461BF" />
</asp:GridView>
</td>
Close all elements and show only current clicked element using jquery.
<script type="text/javascript">
$(document).ready(function () {
$(".recommentbtn").click(function () {
var divid = "#" + $(this).attr("id") + "div";
$(".div_rep").hide();
$(".hiddencommentBox").hide();
$(".sendmailusercomment").hide();
$(".div_InnerMail").hide();
$(".div_comntReply").hide();
$(".div_editcommentReply").hide();
$(divid).show();
$('html, body').animate({ scrollTop: $(divid).offset().top - 200 }, 'slow');
});
$(".replysubmitBoxBtn02close").click(function () {
var divid1 = "#" + $(this).attr("rel") + "div";
$(".div_rep").hide();
$(".hiddencommentBox").hide();
$(".sendmailusercomment").hide();
$(".div_InnerMail").hide();
$(".div_comntReply").hide();
$(".div_editcommentReply").hide();
$(divid1).hide();
$('html, body').animate({ scrollTop: $(divid1).offset().top - 200 }, 'slow');
});
$(".recommentbtn02").click(function () {
var divid2 = "#" + $(this).attr("id") + "div";
$(".div_rep").hide();
$(".hiddencommentBox").hide();
$(".sendmailusercomment").hide();
$(".div_InnerMail").hide();
$(".div_comntReply").hide();
$(".div_editcommentReply").hide();
$(divid2).show();
$('html, body').animate({ scrollTop: $(divid2).offset().top - 200 }, 'slow');
});
$(".recommentbtn04").click(function () {
var divid3 = "#" + $(this).attr("id") + "div";
$(".div_rep").hide();
$(".hiddencommentBox").hide();
$(".sendmailusercomment").hide();
$(".div_InnerMail").hide();
$(".div_comntReply").hide();
$(".div_editcommentReply").hide();
$(divid3).show();
$('html, body').animate({ scrollTop: $(divid3).offset().top - 200 }, 'slow');
});
$(".replysubmitBoxBtn02closeatag").click(function () {
var divid4 = "#" + $(this).attr("id") + "v";
$(".div_rep").hide();
$(".hiddencommentBox").hide();
$(".sendmailusercomment").hide();
$(".div_InnerMail").hide();
$(".div_comntReply").hide();
$(".div_editcommentReply").hide();
$(divid4).hide();
$('html, body').animate({ scrollTop: $(divid4).offset().top - 200 }, 'slow');
});
$(".replysubmitBoxBtn022closeatag").click(function () {
var divid5 = "#" + $(this).attr("id") + "div";
$(".div_rep").hide();
$(".hiddencommentBox").hide();
$(".sendmailusercomment").hide();
$(".div_InnerMail").hide();
$(".div_comntReply").hide();
$(".div_editcommentReply").hide();
$(divid5).hide();
$('html, body').animate({ scrollTop: $(divid5).offset().top - 200 }, 'slow');
});
$(".recommentbtn05").click(function () {
var divid6 = "#" + $(this).attr("id") + "div";
$(".div_rep").hide();
$(".hiddencommentBox").hide();
$(".sendmailusercomment").hide();
$(".div_InnerMail").hide();
$(".div_comntReply").hide();
$(".div_editcommentReply").hide();
$(divid6).show();
$('html, body').animate({ scrollTop: $(divid6).offset().top - 200 }, 'slow');
});
});
</script>
==================================================================================================================
<asp:Repeater ID="rpt_Comment" runat="server">
<ItemTemplate>
<div class="newcommentbox01">
<div class="reviviewTop_container">
<div class="newcommmetboxImg">
<%--<img src="images/userclientimg.jpg" alt="" />--%>
<img src='<%# string.IsNullOrEmpty(Eval("ProfileImagePath").ToString()) ? Page.ResolveUrl("~/images/userclientimg.jpg") : Page.ResolveUrl(Eval("ProfileImagePath").ToString()) %>' alt="" />
</div>
<div class="newcommmetboxContant">
<asp:HiddenField ID="hdn_cmntID" runat="server" Value='<%#Eval("CommentsID") %>' />
<asp:HiddenField ID="hdn_username" runat="server" Value='<%# Eval("UserName") %>' />
<asp:HiddenField ID="hdn_useremail" runat="server" Value='<%# Eval("EmailID") %>' />
<div class="newcommentuser_name"><%#Eval("UserName") %></div>
<span style="font-size: 12px;">@TeachYou</span>
<%--<div class="newcommentuser_email">
<img src="images/useremail.png" alt="" />
<%#Eval("EmailID") %>
</div>--%>
<div class="newcommentuser_date"><%#Eval("PostedDate","{0:d}") %> at <%#Eval("PostedDate","{0:t}") %></div>
<p class="more"><%# Eval("Description") %></p>
<div style="display: none;" id='<%#"inputreedit"+Eval("CommentsID")+"div" %>'>
<asp:TextBox ID="txt_editCommnt" runat="server" class="redesignForn_inputClassreedit" placeholder="Type your comment" TextMode="MultiLine"
Text='<%# Eval("Description").ToString() %>'></asp:TextBox>
<div style="width: 100%; float: left;">
<a href="javascript:void(0)" id='<%#"inputreedit"+Eval("CommentsID") +"di" %>' class="replysubmitBoxBtn02closeatag">Cancel</a>
<asp:Button ID="Btn_UpdateComment" runat="server" CssClass="replysubmitBoxBtn02close002" Text="Update" OnClick="Btn_UpdateComment_Click" />
</div>
</div>
</div>
<div class="reaplyComtainer_inpost">
<ul>
<li><a href="javascript:void(0)" id='<%#"inputreedit"+Eval("CommentsID") %>' class="recommentbtn04" style='<%# "display:" + (Convert.ToString(Eval("EmailID")) == Convert.ToString(Session["User"])?"block": "none") %>'>Edit</a></li>
<li>
<asp:LinkButton ID="Btn_DeleteCmnt" runat="server" Text="Delete" class="recommentbtn04" OnClick="Btn_DeleteCmnt_Click" OnClientClick="return confirm('Are you sure you want to delete this comment.')" Style='<%# "display:" + (Convert.ToString(Eval("EmailID")) == Convert.ToString(Session["User"])?"block": "none") %>' /></li>
<li><a href="javascript:void(0)" id='<%#"recommentbtn"+Eval("CommentsID") %>' class="recommentbtn">Reply</a></li>
<li><a href="javascript:void(0)" id='<%#"sendmailuserbtn"+Eval("CommentsID") %>' class="recommentbtn02" Style='<%# "display:" + (Convert.ToString(Eval("EmailID")) == Convert.ToString(Session["User"])?"none": "block") %>'>Send Mail</a></li>
</ul>
</div>
</div>
<!-------reply submit container------>
<!------- Inner Listing ------>
<asp:Repeater ID="rpt_InnerComment" runat="server" DataSourceID="SqlDataSource_CommentReply">
<ItemTemplate>
<div class="replysepratorCommnmain">
<div class="replysepratorCommnmain01">
<div class="newcommmetboxImg">
<%--<img src="images/userclientimg.jpg" alt="" />--%>
<img src='<%# string.IsNullOrEmpty(Eval("ProfileImagePath").ToString()) ? Page.ResolveUrl("~/images/userclientimg.jpg") : Page.ResolveUrl(Eval("ProfileImagePath").ToString()) %>' alt="" />
</div>
<div class="newcommmetboxContant">
<asp:HiddenField ID="hdn_ChildcmntID" runat="server" Value='<%#Eval("CommentReplyId") %>' />
<asp:HiddenField ID="hdn_Childusername" runat="server" Value='<%# Eval("FirstName") %>' />
<asp:HiddenField ID="hdn_Childuseremail" runat="server" Value='<%# Eval("ReplyBy") %>' />
<div class="newcommentuser_name"><%#Eval("FirstName") %></div>
<span style="font-size: 12px;">@TeachYou</span>
<%--<div class="newcommentuser_email">
<img src="images/useremail.png" alt="" />
<%#Eval("ReplyBy") %>
</div>--%>
<div class="newcommentuser_date"><%#Eval("PostedDate") %></div>
<p class="more"><%#Eval("CommentReply") %></p>
<div style="display: none;" id='<%#"inputEditComntReply"+Eval("CommentReplyId")+"div" %>' class="div_editcommentReply">
<asp:TextBox ID="txt_editCommntReply" runat="server" class="redesignForn_inputClassreedit" placeholder="Type your comment" TextMode="MultiLine"
Text='<%# Eval("CommentReply").ToString() %>'></asp:TextBox>
<div style="width: 100%; float: left;">
<a href="javascript:void(0)" id='<%#"inputEditComntReply"+Eval("CommentReplyId") %>' class="replysubmitBoxBtn022closeatag">Cancel</a>
<asp:Button ID="Btn_UpdateCommentReply" runat="server" CssClass="replysubmitBoxBtn02close002" Text="Update" OnClick="Btn_UpdateCommentReply_Click" />
</div>
</div>
</div>
<div class="reaplyComtainer_inpost">
<ul>
<li><a href="javascript:void(0)" id='<%#"inputEditComntReply" + Eval("CommentReplyId") %>' class="recommentbtn05"
style='<%# "display:" + (Convert.ToString(Eval("ReplyBy")) == Convert.ToString(Session["User"])?"block": "none") %>'>Edit</a></li>
<li>
<asp:LinkButton ID="Btn_DeleteCmntReply" runat="server" Text="Delete" class="recommentbtn04" OnClick="Btn_DeleteCmntReply_Click" OnClientClick="return confirm('Are you sure you want to delete this comment.')" Style='<%# "display:" + (Convert.ToString(Eval("ReplyBy")) == Convert.ToString(Session["User"])?"block": "none") %>' /></li>
<%--<li><a href="javascript:void(0)" id='<%#"childcommentbtn_"+Eval("CommentsID") %>' class="recommentbtn">Reply</a></li>--%>
<li><a href="javascript:void(0)" class="recommentbtn02" id='<%#"childsendmailbtn_"+Eval("CommentReplyId") %>' style='<%# "display:" + (Convert.ToString(Eval("ReplyBy")) == Convert.ToString(Session["User"])?"none": "block") %>'>Send Mail</a></li>
</ul>
</div>
</div>
<%-- <div class="hiddencommentBoxchild" id='<%#"childcommentbtn_"+Eval("CommentsID")+"div" %>'>
<div class="replysepratorCommnet02">
<asp:TextBox ID="txt_childreply" runat="server" class="replypostcommentFeil" placeholder="Type Your Comments" TextMode="MultiLine"></asp:TextBox>
<a href="javascript:void(0)" class="replysubmitBoxBtn02close" id="childcommentboxclose" rel='<%#"childcommentbtn_"+Eval("CommentsID") %>'>Close</a>
<asp:Button ID="btn_childReply" class="replysubmitBoxBtn02" runat="server" Text="Submit" OnClick="btn_childReply_Click" />
</div>
</div>--%>
<!-----send mail comment user----->
<div class="sendmailusercomment" id='<%#"childsendmailbtn_"+Eval("CommentReplyId")+"div" %>'>
<div class="sendmailInner">
<%--<input type="text" class="replypostcommentFeil02" placeholder="Email Address" />--%>
<asp:TextBox ID="txt_childEmail" runat="server" CssClass="replypostcommentFeil02" placeholder="Message"></asp:TextBox>
<%-- <button type="submit" value="" class="replysubmitBoxBtn03">Submit</button>--%>
<asp:Button ID="btn_SendChildEMail" class="replysubmitBoxBtn03" runat="server" Text="Send Mail" OnClick="btn_SendChildEMail_Click"
OnClientClick="return showpopup()" />
</div>
</div>
<!-----send mail comment user----->
</div>
</ItemTemplate>
</asp:Repeater>
<asp:SqlDataSource ID="SqlDataSource_CommentReply" runat="server" ConnectionString="<%$ ConnectionStrings:connectionstring %>"
SelectCommand="SP_GetAllCommentReplyByCommentIdAndType" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:ControlParameter ControlID="hdn_cmntID" Name="CommentId" DefaultValue="-1" ConvertEmptyStringToNull="true" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
<!------- Inner Listing ------>
<!-------reply submit container------>
<!-----send mail comment user----->
<div class="sendmailusercomment" id='<%#"sendmailuserbtn"+Eval("CommentsID")+"div" %>'>
<div class="sendmailInner">
<asp:TextBox ID="txt_email" runat="server" class="replypostcommentFeil02" placeholder="Message"></asp:TextBox>
<%-- <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="Required" ControlToValidate="txt_email" ForeColor="Red"
Display="Dynamic" ValidationGroup="sendemail"></asp:RequiredFieldValidator>--%>
<asp:Button ID="btn_sendmail" runat="server" Text="Post" ValidationGroup="sendemail" class="replysubmitBoxBtn03" OnClick="btnSendMail_Click" OnClientClick="return showpopup()" />
</div>
</div>
<!-----send mail comment user----->
<div class="hiddencommentBox" id='<%#"recommentbtn"+Eval("CommentsID")+"div" %>'>
<asp:TextBox ID="txt_reply" runat="server" Placeholder="Type your comment" TextMode="MultiLine" CssClass="redesignForn_inputClass"></asp:TextBox>
<a href="javascript:void(0)" class="replysubmitBoxBtn02close" id="closebtncomment" rel='<%#"recommentbtn"+Eval("CommentsID") %>'>Close</a>
<asp:Button ID="btn_replysubmit" CssClass="replysubmitBoxBtn02" Text="Post" OnClick="btn_replySubmit_Click" runat="server" OnClientClick="return showpopup()" />
</div>
</div>
</ItemTemplate>
</asp:Repeater>
How to select alternate rows from a table in SQL Server
Odd alternate
select * from (select ROW_NUMBER() over(order by blog_category_id)as row, * from tbl_blog_category)A where row % 2=1
Even alternate
select * from (select ROW_NUMBER() over(order by blog_category_id)as row, * from tbl_blog_category)A where row % 2=0
---------------------------------------------------------------------------------------------------------------------
Find the 3rd MAX salary in the emp table.
select distinct blog_category_id from tbl_blog_category b1 where 3= (select COUNT (distinct blog_category_id) from
tbl_blog_category b2 where b2.blog_category_id <= b1.blog_category_id)
Find the nth MAX salary in the emp table.
select distinct blog_category_id from tbl_blog_category b1 where 3= (select COUNT (distinct blog_category_id) from
tbl_blog_category b2 where b2.blog_category_id <= b1.blog_category_id)
---------------------------------------------------------------------------------------------------------------------
Select FIRST n records from a table.
select Top(3)* from tbl_blog_category
Select LAST n records from a table
select Top(3)* from tbl_blog_category order by blog_category_id desc
------------------------------------------------------------------------------------------------------------------
Control CSS
Read More
<a href='<%=Page.ResolveUrl("~/home") %>' style="color: #000000; text-decoration: none; font-weight: bold; line-height: 15px; font-size: 12px">Read More</a>
* (Red Strik)
<span style="color: Red;">*</span>
<body onload="javascript:window.print();">
<asp:TemplateField ShowHeader="True" HeaderText="Total Outstanding Amount" HeaderStyle-ForeColor="White">
--------------------------------------------------------------------------------------------------------------------
<ItemTemplate>
<%#cal(Eval("debitAmount").ToString(), Eval("creditamount").ToString())%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ShowHeader="True" HeaderText="Update" HeaderStyle-ForeColor="White">
<ItemTemplate>
<a href='<%# GetUrl(Convert.ToString(Eval("ClientId"))) %>'>
<img src="images/update.png" alt="Update" height="25px" width="65" /></a>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ShowHeader="True" HeaderText="View" HeaderStyle-ForeColor="White">
<ItemTemplate>
<a href='<%# GetUrlView(Convert.ToString(Eval("ClientId"))) %>'>
<img src="images/view.gif" alt="View" height="25px" width="65" /></a>
</ItemTemplate>
</asp:TemplateField>
C# Code
Code to Close Window
protected void btn_cncl_Click(object sender, EventArgs e)
{
ClientScript.RegisterStartupScript(GetType(), "CloseScript", "window.opener.location.reload(); window.close();", true);
}
Finding div of masterpage at content page to hide
System.Web.UI.HtmlControls.HtmlGenericControl contentdiv = (System.Web.UI.HtmlControls.HtmlGenericControl)Master.FindControl("div_id");
contentdiv.Style.Add("display", "none");
if (Convert.ToDouble(debitamount) > Convert.ToDouble(creditamount))
{
double calamount = Convert.ToDouble(debitamount) - Convert.ToDouble(creditamount);
amount = "<span style='color:red;'> - " + calamount.ToString("0.00") + "</span>";
}
else
{
double calamount = Convert.ToDouble(creditamount) - Convert.ToDouble(debitamount);
amount = "<span style='color:green;'> " + calamount.ToString("0.00") + "</span>";
}
Code to Get Confirmation message to delete item
protected void grid_Image_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType != DataControlRowType.DataRow) return;
int lastCellIndex = e.Row.Cells.Count - 1;
ImageButton db = (ImageButton)e.Row.Cells[lastCellIndex].Controls[0];
db.OnClientClick = "if (!window.confirm('Are you sure you want to delete this record?')) return false;";
}
Code to get sum of amount from gridview columns
protected void grid_Statement_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
totalCreditAmount += Convert.ToDouble(DataBinder.Eval(e.Row.DataItem, "creditamount"));
totalDebitAmount += Convert.ToDouble(DataBinder.Eval(e.Row.DataItem, "debitamount"));
}
}
-------------------------------------------------------------------------------------------------------------------------
<td colspan="2" height="10px" align="left">
<asp:GridView ID="grid_Client" runat="server" Width="100%" AutoGenerateColumns="False"
CellPadding="3" ForeColor="#333333" GridLines="None" AllowPaging="true" PageSize="30"
Font-Size="12px" OnPageIndexChanging="grid_Client_PageIndexChanging" OnRowDataBound="grid_Client_RowDataBound"
OnRowDeleting="grid_Client_RowDeleting">
<RowStyle BackColor="#EFF3FB" HorizontalAlign="Center" Font-Size="12px" />
<AlternatingRowStyle BackColor="#EFF3FB" HorizontalAlign="Center" />
<Columns>
<asp:TemplateField>
<HeaderTemplate>
Sr. No.
</HeaderTemplate>
<ItemTemplate>
<%# Container.DataItemIndex + 1 %>
<asp:HiddenField ID="hdn_id" runat="server" Value='<%# Eval("ClientId") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" HeaderStyle-ForeColor="White" />
<asp:BoundField DataField="Email" HeaderText="Email ID" SortExpression="Email" HeaderStyle-ForeColor="White" />
<asp:BoundField DataField="ContactNo" HeaderText="Contact No" HeaderStyle-ForeColor="White" />
<asp:BoundField DataField="ContactPerson" HeaderText="Contact Person" SortExpression="ContactPerson"
HeaderStyle-ForeColor="White" />
<asp:BoundField DataField="Address" HeaderText="Address" HeaderStyle-ForeColor="White" />
<asp:TemplateField ShowHeader="True" HeaderText="Debit" HeaderStyle-ForeColor="White">
<ItemTemplate>
<%#Eval("debitAmount").ToString()%>
</ItemTemplate>
</asp:TemplateField> <asp:TemplateField ShowHeader="True" HeaderText="Credit" HeaderStyle-ForeColor="White">
<ItemTemplate>
<%#Eval("creditamount").ToString()%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ShowHeader="True" HeaderText="Total Outstanding Amount" HeaderStyle-ForeColor="White">
<ItemTemplate>
<%#cal(Eval("debitAmount").ToString(), Eval("creditamount").ToString())%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ShowHeader="True" HeaderText="Update" HeaderStyle-ForeColor="White">
<ItemTemplate>
<a href='<%# GetUrl(Convert.ToString(Eval("ClientId"))) %>'>
<img src="images/update.png" alt="Update" height="25px" width="65" /></a>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ShowHeader="True" HeaderText="Update" HeaderStyle-ForeColor="White">
<ItemTemplate>
<a href='<%# GetUrlView(Convert.ToString(Eval("ClientId"))) %>'>
<img src="images/view.gif" alt="View" height="25px" width="65" /></a>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ButtonType="Image" HeaderText="Delete" ControlStyle-Width="20px"
ControlStyle-Height="20px" DeleteImageUrl="~/images/delete.png" ShowDeleteButton="True"
DeleteText="delete">
<ItemStyle Width="50px" />
</asp:CommandField>
</Columns>
<EmptyDataTemplate>
Sorry, no data found as your search criteria.</EmptyDataTemplate>
<EmptyDataRowStyle CssClass="header-mainnew2" HorizontalAlign="Left" ForeColor="Red"
VerticalAlign="Middle" />
<FooterStyle BackColor="#31302B" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#31302B" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#31302B" Font-Bold="True" ForeColor="white" HorizontalAlign="Center" />
<EditRowStyle BackColor="#2461BF" />
</asp:GridView>
</td>
-------------------------------------------------------------------------------------------------------------------
public string cal(string debitamount, string creditamount)
{
string amount = "0";
if (debitamount == "" || debitamount == null)
debitamount = "0";
if (creditamount == "" || creditamount == null)
creditamount = "0";
if (Convert.ToDouble(debitamount) > Convert.ToDouble(creditamount))
{
double calamount = Convert.ToDouble(debitamount) - Convert.ToDouble(creditamount);
amount = "<span style='color:red;'> - " + calamount.ToString("0.00") + "</span>";
}
else
{
double calamount = Convert.ToDouble(creditamount) - Convert.ToDouble(debitamount);
amount = "<span style='color:green;'> " + calamount.ToString("0.00") + "</span>";
}
return amount;
}
Working with gridview itemtemplate to delete, update, edit, cancel edit
<td colspan="2" height="10px" align="left">
<asp:GridView ID="grid_Image" runat="server" Width="80%" AutoGenerateColumns="false"
DataKeyNames="Id" CellPadding="3" ForeColor="#333333" GridLines="none" AllowPaging="true"
PageSize="30" Style="margin-top: 0px" OnRowUpdating="grid_Image_RowUpdating"
OnRowEditing="grid_Image_RowEditing"
OnRowDeleting="grid_Image_RowDeleting"
OnRowCancelingEdit="grid_Image_RowCancelingEdit"
>
<RowStyle BackColor="#ffffff" HorizontalAlign="center" />
<AlternatingRowStyle BackColor="#ffffff" HorizontalAlign="center" />
<Columns>
<asp:TemplateField>
<HeaderTemplate>
Sr. no.
</HeaderTemplate>
<ItemTemplate>
<%# Container.DataItemIndex + 1 %><asp:HiddenField ID="hdn_commentid" runat="server"
Value='<%# Eval("Id") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="LeadDate" HtmlEncode="false" DataFormatString="{0:dd-MM-yyyy}"
ReadOnly="true" HeaderText="Lead Date" SortExpression="LeadDate" HeaderStyle-ForeColor="White" />
<asp:BoundField DataField="Name" HeaderText="Name" ReadOnly="true" SortExpression="Name" />
<asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" ReadOnly="true"
HeaderStyle-ForeColor="white" />
<asp:BoundField DataField="Phone" HeaderText="Phone" SortExpression="Phone" ReadOnly="true"
HeaderStyle-ForeColor="white" />
<asp:TemplateField HeaderText="Lead Status">
<EditItemTemplate>
<asp:HiddenField ID="hdn_usertype" runat="server" Value='<%# Eval("LeadStatus") %>' />
<asp:DropDownList ID="ddl_status" Width="100px" runat="server">
<asp:ListItem>Pending</asp:ListItem>
<asp:ListItem>Open</asp:ListItem>
<asp:ListItem>Closed</asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lbl_usetype" runat="server" Text='<%# Bind("LeadStatus") %>'></asp:Label>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Center" />
<ItemStyle HorizontalAlign="Center" Width="90px" />
</asp:TemplateField>
<asp:TemplateField ShowHeader="true" HeaderText="View">
<ItemTemplate>
<a href="javascript:void(0);" onclick="PopupCenter('<%# "lead_detail.aspx?Id=" + Eval("Id") %>', '',800,400);">
<img src="../images/view_icon4.png" alt="view" /></a>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ButtonType="image" ShowEditButton="true" HeaderText="update" EditImageUrl="../images/edit.png"
UpdateImageUrl="../images/update.png" CancelImageUrl="../images/cancel.png">
<ItemStyle Width="70px" />
</asp:CommandField>
<asp:TemplateField ShowHeader="true" HeaderText="Delete">
<ItemTemplate>
<asp:ImageButton ID="imgDelete" runat="server" ImageUrl="~/images/delete.png" CommandName="Delete" OnClientClick= "if (!window.confirm('Are you sure you want to delete this record?')) return false;"/>
</ItemTemplate>
</asp:TemplateField>
<%-- <asp:CommandField ButtonType="Image" HeaderText="Delete" ControlStyle-Width="16px"
ControlStyle-Height="16px" DeleteImageUrl="~/images/delete.png" ShowDeleteButton="True" />--%>
</Columns>
<EmptyDataTemplate>
sorry, no data found as your search criteria.
</EmptyDataTemplate>
<EmptyDataRowStyle CssClass="header-mainnew2" HorizontalAlign="left" ForeColor="red"
VerticalAlign="middle" />
<FooterStyle BackColor="#0190b9" Font-Bold="true" ForeColor="white" />
<PagerStyle BackColor="#0190b9" ForeColor="white" HorizontalAlign="center" />
<SelectedRowStyle Font-Bold="true" ForeColor="#333333" />
<HeaderStyle BackColor="#0190b9" Font-Bold="true" ForeColor="white" HorizontalAlign="center" />
<EditRowStyle BackColor="#ffffff" />
</asp:GridView>
</td>
---------------------------------------------------------------------------------------------------------------------
protected void grid_Image_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
try
{
img_right.Visible = false;
lbl_msg.Text = "";
grid_Image.EditIndex = -1;
BindGrid();
}
catch (Exception ex)
{
lbl_msg.Text = "Error : " + ex.Message;
}
}
protected void grid_Image_RowEditing(object sender, GridViewEditEventArgs e)
{
try
{
lbl_msg.Text = "";
img_error.Visible = false;
img_right.Visible = false;
grid_Image.EditIndex = e.NewEditIndex;
BindGrid();
}
catch (Exception ex)
{
lbl_msg.Text = "Error : " + ex.Message;
}
}
protected void grid_Image_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
try
{
lbl_msg.Text = "";
int update_index = e.RowIndex;
GridViewRow gr = grid_Image.Rows[update_index];
int ID = Convert.ToInt32(grid_Image.DataKeys[update_index].Values["Id"]);
String LeadStatus = ((DropDownList)gr.FindControl("ddl_status")).Text;
// bool status = ((CheckBox)gr.FindControl("chk_editstatus")).Checked;
user.leadID = ID;
user.leadStatus = LeadStatus;
user.Updateuser();
if (user.OperationStatus != false)
{
div_message.Visible = true;
lbl_msg.Text = "User Detail Updated Successfully.";
lbl_msg.ForeColor = System.Drawing.Color.Green;
img_right.Visible = true;
img_error.Visible = false;
}
else
{
lbl_msg.Text = user.ErrorMessage;
}
grid_Image.EditIndex = -1;
BindGrid();
}
catch (Exception ex)
{
lbl_msg.Text = "Error : " + ex.Message;
}
}
protected void grid_Image_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
grid_Image.PageIndex = e.NewPageIndex;
BindGrid();
}
protected void grid_Image_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
try
{
int Delete_index = e.RowIndex;
GridViewRow gr = grid_Image.Rows[Delete_index];
string hdn = ((HiddenField)gr.FindControl("hdn_commentid")).Value;
int Blogid = Convert.ToInt32(hdn);
user.leadID = Blogid;
//while (File.Exists(Server.MapPath(hdn_image.Value)))
//{
// File.Delete(Server.MapPath(hdn_image.Value));
//}
user.DeleteLeadByID();
if (user.OperationStatus)
{
lbl_msg.Text = "Lead Deleted Successfully.";
lbl_msg.ForeColor = System.Drawing.Color.Green;
Div_Image.Visible = true;
div_message.Visible = true;
img_right.Visible = true;
BindGrid();
}
else
{
div_message.Visible = true;
lbl_msg.Text = user.ErrorMessage;
lbl_msg.ForeColor = System.Drawing.Color.Red;
img_error.Visible = true;
img_right.Visible = false;
}
}
catch (Exception ex)
{
div_message.Visible = true;
lbl_msg.Text = "Error : " + ex.Message;
lbl_msg.ForeColor = System.Drawing.Color.Red;
img_error.Visible = true;
img_right.Visible = false;
}
}
<script type="text/javascript">
function Validate(sender, args) {
var gridView = document.getElementById("<%=grid_Expresscertificate.ClientID %>");
var checkBoxes = gridView.getElementsByTagName("input");
for (var i = 0; i < checkBoxes.length; i++) {
if (checkBoxes[i].type == "checkbox" && checkBoxes[i].checked) {
args.IsValid = true;
return;
}
}
args.IsValid = false;
}
</script>
=======================================================================
<asp:CustomValidator ID="CustomValidator1" runat="server" ValidationGroup="print" ErrorMessage="Please select at least one record." ClientValidationFunction="Validate" ForeColor="Red"></asp:CustomValidator>
=======================================================================
<asp:Button ID="btnA4" runat="server" Text="Print A4" OnClick="btnA4_Click" ValidationGroup="print" />
DatalistorListView
<table cellpadding="0" cellspacing="0" border="0" width="100%">
<tr>
<td align="center" valign="top">
<table cellpadding="0" cellspacing="0" border="0" width="1024px">
<tr>
<td height="21" width="100%" align="center" valign="top">
<font size="2" face="Verdana" color="#333333"><strong>Select Country :</strong></font>
<asp:DropDownList ID="drp_Country" runat="server" DataSourceID="SqlDataSource1" DataTextField="Country"
DataValueField="Country" AutoPostBack="True" OnSelectedIndexChanged="drp_Country_SelectedIndexChanged">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ConnectionStrings:connectionstring %>"
SelectCommand="SP_GetAllCountriesFromtblCertificate" SelectCommandType="StoredProcedure">
</asp:SqlDataSource>
</td>
</tr>
<tr style="height:50px;">
<td>
</td>
</tr>
<tr>
<td align="left">
<asp:DataList ID="ListView_Certificates" runat="server" RepeatColumns="6" RepeatDirection="Horizontal">
<ItemTemplate>
<td width="150px" align="center">
<a style="text-decoration: none;" href='<%# Page.ResolveUrl(Eval("Pdf").ToString()!=""?Eval("Pdf").ToString():Eval("Pdf").ToString()) %>'
target="_blank">
<img src='<%=Page.ResolveUrl("~/images/pdf_icon.png") %>' alt="Download of <%# Eval("Title") %>"
align="center" border="0" />
</a>
<br /><br />
<a style="text-decoration: none; color:#000;" href='<%# Page.ResolveUrl(Eval("Pdf").ToString()!=""?Eval("Pdf").ToString():Eval("Pdf").ToString()) %>'
target="_blank">
<%# Eval("Title") %></a><br /><br />
</td>
</ItemTemplate>
<SeparatorTemplate>
<td width="30px">
</td>
</SeparatorTemplate>
</asp:DataList>
</td>
</tr>
</table>
</td>
</tr>
</table>
DateTime
txt_DateOfReportSubmission.Text = Convert.ToDateTime(objCase.CaseTable.Rows[0]["DateOfReportSubmission"]).ToString("dd-MMM-yyyy");
=======================================================================
<asp:BoundField DataField="BillDate" HeaderText="BillDate" SortExpression="BillDate" HeaderStyle-ForeColor="White" DataFormatString="{0:dd/MM/yyyy}" />
=======================================================================
objBill.BillDate = DateTime.ParseExact(txtBillDate.Text, "dd/MM/yyyy", null);
=======================================================================
rev.PostedDate = DateTime.Now.ToString("MMM dd,yyyy");
=======================================================================
<asp:TemplateField>
<HeaderTemplate>
Lead Date
</HeaderTemplate>
<ItemTemplate>
<%# Convert.ToDateTime(Eval("LeadDate")).ToString("dd/MM/yyyy")%>
</ItemTemplate>
</asp:TemplateField>
Disable particular commandfield in a gridview on some condition
protected void grid_Lead_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string Client_Lead_Status = DataBinder.Eval(e.Row.DataItem, "ClientLeadStatus").ToString();
if (Client_Lead_Status == "Accepted" || Client_Lead_Status == "Rejected")
{
e.Row.Cells[7].Enabled = false;
}
}
}
Find Item in dropdownlist in side gridview and set selected true.
-----------------------------------------------------------------------------------------------------------
protected void grid_Lead_RowDataBound(object sender, GridViewRowEventArgs e)
{
foreach (GridViewRow gvRow in grid_Lead.Rows)
{
DropDownList ddlStatus = gvRow.FindControl("ddl_clientleadstatus") as DropDownList;
HiddenField hdn_Status = gvRow.FindControl("hdn_clientleadstatus") as HiddenField;
if (ddlStatus != null && hdn_Status != null)
{
ddlStatus.SelectedValue = hdn_Status.Value;
}
}
if (e.Row.RowType == DataControlRowType.DataRow)
{
string Client_Lead_Status = DataBinder.Eval(e.Row.DataItem, "ClientLeadStatus").ToString();
if (Client_Lead_Status == "Accepted" || Client_Lead_Status == "Rejected")
{
e.Row.Cells[7].Enabled = false;
}
}
}
DynamicMenu
<div id='cssmenu'>
<ul>
<li><a href='<%= Page.ResolveUrl("~/home") %>'>Home</a></li>
<li class='has-sub'><a href='<%= Page.ResolveUrl("~/all-products") %>'>Products</a>
<ul>
<asp:Repeater ID="listview_category" runat="server" DataSourceID="sql_category">
<ItemTemplate>
<asp:HiddenField ID="hdn_categoryid" runat="server" Value='<%# Eval("category_id") %>' />
<li class="has-sub"><a href='<%# Page.ResolveUrl(WriteUrl2("product_category",Eval("category_name").ToString(),Eval("category_id").ToString())) %>'>
<%# Eval("category_name")%></a>
<ul>
<asp:Repeater ID="repeater_subcategory" runat="server" DataSourceID="sds_subcategory">
<ItemTemplate>
<li><a href='<%# Page.ResolveUrl(WriteUrl3(Eval("category_name").ToString(),Eval("subcategory_name").ToString(),Eval("category_id").ToString(),Eval("subcategory_id").ToString())) %>'>
<%# Eval("subcategory_name")%></a></li>
</ItemTemplate>
</asp:Repeater>
<asp:SqlDataSource ID="sds_subcategory" runat="server" ConnectionString="<%$ ConnectionStrings:connectionstring %>"
SelectCommand="GetallSubcategoryBycategory_id" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:ControlParameter ControlID="hdn_categoryid" DefaultValue="-1" Name="category_id"
PropertyName="Value" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
</ul>
</li>
</ItemTemplate>
</asp:Repeater>
<asp:SqlDataSource ID="sql_category" runat="server" ConnectionString="<%$ ConnectionStrings:connectionstring %>"
SelectCommand="SP_GetCategoryType" SelectCommandType="StoredProcedure"></asp:SqlDataSource>
</ul>
</li>
<li><a href='<%=Page.ResolveUrl("~/company") %>'>Company</a></li>
<li><a href='<%=Page.ResolveUrl("~/support") %>'>Support</a> </li>
<li class="active"><a href='<%=Page.ResolveUrl("~/contact") %>'>Contact Us</a></li>
</ul>
</div>
Download
<div class="heading_container ">
<div class="heading_text1">
Downloads of
<%=ProjectName %>
</div>
<div class="line">
</div>
<div class="floor_contianer">
<div class="des-details">
<div class="floor_contianer">
<div class="zerogrid">
<asp:Repeater ID="Rpt_download" runat="server">
<ItemTemplate>
<div class="col05">
<a style="text-decoration: none;" href='<%# Page.ResolveUrl(Eval("ProjectDownloadPath").ToString()!=""?Eval("ProjectDownloadPath").ToString().Remove(0,2):Eval("ProjectDownloadPath").ToString()) %>'
target="_blank">
<div class="project-content down">
<img src="images/pdf_icon.png" width="150" height="55" border="0" alt="Download of <%=ProjectName %> <%#Eval("ProjectDownloadTitle")%>" /></div>
<div class="t1-title2">
<%#Eval("ProjectDownloadTitle")%>
</div>
</a>
<div class="line">
</div>
</div>
</ItemTemplate>
</asp:Repeater>
</div>
</div>
</div>
</div>
<div class="clearfix">
</div>
</div>
===============================================================
Project.GetProjectDownloadID();
if (Project.OperationStatus)
{
Rpt_download.DataSource = Project.ProjectTable;
Rpt_download.DataBind();
}
===========================
public void GetProjectDownloadID()
{
try
{
SqlDataAdapter ad = new SqlDataAdapter();
DataTable Sqldatatable = new DataTable();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "SP_GetDownloadByID";
cmd.Parameters.AddWithValue("@ProjectID", ProjectID);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = Connection;
ad.SelectCommand = cmd;
OpenConnection();
ad.Fill(Sqldatatable);
ProjectTable = Sqldatatable;
OperationStatus = true;
CloseConnection();
Sqldatatable.Dispose();
cmd.Dispose();
ad.Dispose();
}
catch (Exception ex)
{
ErrorMessage = "Error : " + ex.Message;
OperationStatus = false;
}
finally
{
CloseConnection();
}
}
===============================
CREATE PROCEDURE [dbo].[SP_GetDownloadByID]
(
@ProjectID numeric(18,0)
)
as
begin
select * from tbl_ProjectDownload where ProjectID=@ProjectID order by ProjectDownloadID desc
end