Wednesday, August 3, 2011

Populating dropdownlist

On .aspx page dropdown code
<asp:DropDownList ID="ddlsearchempgrid" AutoPostBack="true"
runat="server"><asp:ListItem Selected="True" Value="-Select-">-Select-</asp:ListItem>
</asp:DropDownList>

On .Cs page dropdown code


protected void binddropdownprj()
{
SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["Enigma"].ToString().Trim());
SqlDataAdapter da = new SqlDataAdapter("select * from cProject", con);
DataSet ds = new DataSet();
da.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
ddlproject.DataSource = ds.Tables[0];
ddlproject.DataTextField = "createproject";
ddlproject.DataValueField = "ProjectId";
ddlproject.DataBind();
ddlproject.Items.Insert(0, new ListItem("-Select-"));

}
}

And On Page dropdown code


protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{

binddropdownprj();
}
}


2.

Populating Dropdown Inside Gridview



On buttun code use onselectedindexchanged="" and then create this method on serverside.

if (e.Row.RowType == DataControlRowType.Header)
{
SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["Enigma"].ToString().Trim());
SqlDataAdapter da = new SqlDataAdapter("Select * From Empdetail", con);
DataSet ds = new DataSet();
da.Fill(ds);
da.SelectCommand.CommandText = "select * from cProject ";
da.Fill(ds, "cproject");

if (ds.Tables[0].Rows.Count > 0)
{

DropDownList ddlgridfilter = new DropDownList();
ddlgridfilter = (DropDownList)e.Row.FindControl("ddlsearchempgrid");
ddlgridfilter.DataSource = ds.Tables[0];
ddlgridfilter.DataTextField = "EmpCode";
ddlgridfilter.DataValueField = "EmpCode";
ddlgridfilter.DataBind();
Dropdown list populating project currently not in correct format.


}
if (ds.Tables[1].Rows.Count > 0)
{
DropDownList ddlgrprj = new DropDownList();
ddlgrprj = (DropDownList)e.Row.FindControl("ddlproject");
ddlgrprj.DataSource = ds.Tables[1];
ddlgrprj.DataTextField = "createproject";
ddlgrprj.DataValueField = "ProjectId";
ddlgrprj.DataBind();
}

}



To Catch event when text changed of dropdown





protected void ddlprogress_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList dd=(DropDownList)viewtsk.HeaderRow.FindControl("ddlprogress");
dd1=dd.SelectedItem.Text;
string Eprg = ddlprogress.SelectedValue.ToString().Trim();
string Eprg = ((DropDownList)viewtsk.HeaderRow.FindControl("ddlprogress")).SelectedValue.ToString().Trim();
SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["Enigma"].ToString().Trim());
SqlDataAdapter dagrid = new SqlDataAdapter("select e.status,e.taskId,e.project,e.task,e.description,f.EmpCode from taskdetails e inner join Empdetail f on f.EmpCode = e.EmpCode where e.status='" + Eprg + "'", con);
DataSet dt = new DataSet();
dagrid.Fill(dt);
if (dt.Tables[0].Rows.Count > 0)
{

viewtsk.DataSource = dt;
viewtsk.DataBind();

}
}

Monday, August 1, 2011

Gidview Css

1.Open Notepad and paste the style given below.


.GridViewStyle
{
font-family: Arial, Sans-Serif;
font-size:small;
table-layout: auto;
border-collapse: collapse;
border: #1d1d1d 5px solid;
}
/*Header and Pager styles*/
.HeaderStyle, .PagerStyle /*Common Styles*/
{
background-image: url(Images/HeaderGlassBlack.jpg);
background-position:center;
background-repeat:repeat-x;
background-color:#1d1d1d;
}
.HeaderStyle th
{
padding: 5px;
color: #ffffff;
}
.HeaderStyle a
{
text-decoration:none;
color:#ffffff;
display:block;
text-align:left;
font-weight:normal;
}
.PagerStyle table
{
text-align:center;
margin:auto;
}
.PagerStyle table td
{
border:0px;
padding:5px;
}
.PagerStyle td
{
border-top: #1d1d1d 3px solid;
}
.PagerStyle a
{
color:#ffffff;
text-decoration:none;
padding:2px 10px 2px 10px;
border-top:solid 1px #777777;
border-right:solid 1px #333333;
border-bottom:solid 1px #333333;
border-left:solid 1px #777777;
}
.PagerStyle span
{
font-weight:bold;
color:#FFFFFF;
text-decoration:none;
padding:2px 10px 2px 10px;
}
/*RowStyles*/
.RowStyle td, .AltRowStyle td, .SelectedRowStyle td, .EditRowStyle td /*Common Styles*/
{
padding: 5px;
border-right: solid 1px #1d1d1d;
}
.RowStyle td
{
background-color: #c9c9c9;
}
.AltRowStyle td
{
background-color: #f0f0f0;
}
.SelectedRowStyle td
{
background-color: #ffff66;
}

2.Save it .js Type.
3.Use this like this in header edit the src location.
4.And Gridview design

<asp:GridView ID="viewtsk" runat="server" AutoGenerateColumns="false" OnRowCommand="viewtsk_RowCommand"
OnRowDataBound="viewtsk_RowDataBound" AllowPaging="True" OnPageIndexChanging="viewtsk_PageIndexChanging">
<RowStyle CssClass="RowStyle" />

<PagerStyle CssClass="PagerStyle" />
<SelectedRowStyle CssClass="SelectedRowStyle" />
<HeaderStyle CssClass="HeaderStyle" />
<EditRowStyle CssClass="EditRowStyle" />
<AlternatingRowStyle CssClass="AltRowStyle" />

Wednesday, July 27, 2011

Emailer

MailTo with multiline message in Body



NOTE: Use "%0A" for a new line, use "%0A%0A" for a new line preceded by a blank line.

" " (beginning and ending double quotes) are necessary if any spaces are used
Mailto parameter should be preceded by "?" for the first or only parameter and "&" for second and subsequent parameter.

Thursday, July 21, 2011

Maintain session

Never Use Master page on login page

Example of login page
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Admin_Default2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
<style type="text/css">
.style2
{
height: 23px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div><center>
<table>
<tr><td>
<th style="border-bottom:1px solid #000000;" colspan="2">Welcome to admin login page!</th></td></tr>
<tr>
<td>
Name
</td>
<td>
:
</td>
<td>
<asp:TextBox ID="txtname" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
Password
</td>
<td>
:
</td>
<td>
<asp:TextBox ID="txtpass" runat="server" TextMode="Password"></asp:TextBox>
</td>
</tr>
<tr>
<td >
</td>
<td >
</td>
<td><asp:Button ID="btnsubmit" runat="server" Text="Sign In" align="left"
onclick="btnsubmit_Click" />
</td>
</tr>
</table></center>
</div>
</form>
</body>
</html>

On code behind page



/// create session while login if not redirect to login page

protected void btnsubmit_Click(object sender, EventArgs e)
{
if (txtname.Text.ToString().Trim() == "admin" && txtpass.Text.ToString().Trim() == "enigma")
{
Session["Username"] = txtname.Text.ToString().Trim();
Session["User"] = txtpass.Text.ToString().Trim();
Response.Redirect("Registration.aspx");
}
else
{
Response.Write("Invalid Username and password");
}
}

On master page which is used in internal page


protected void Page_Load(object sender, EventArgs e)
{
Page.Response.AppendHeader("Cache-Control", "no-store, no-cache, must-revalidate, post-check=0, pre-check=0");

This will clear the cache and brower history.


if (Session["User"] == "" || Session["Username"] == "" || Session["User"] == null ||Session["Username"] == null)
{
Session.Abandon();
Session.Clear();
Response.Redirect("Default.aspx");
}
}

default is my login page this is done because if session not available than automatically redirected to login page.

In the Global file Use this it will always prevent from unauthorized user



void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup

}

void Application_End(object sender, EventArgs e)
{
// Code that runs on application shutdown

}

void Application_Error(object sender, EventArgs e)
{
Exception ex = Server.GetLastError().GetBaseException();
// Code that runs when an unhandled error occurs

}

void Session_Start(object sender, EventArgs e)
{
Session["Username"] = "";
Session["User"] = "";
Session["emailid"] = "";
// Code that runs when a new session is started

}

void Session_End(object sender, EventArgs e)
{
// Code that runs when a session ends.
// Note: The Session_End event is raised only when the sessionstate mode
// is set to InProc in the Web.config file. If session mode is set to StateServer
// or SQLServer, the event is not raised.

}

Saturday, July 2, 2011

Link for beginner

Below is a selection of excellent links from Microsoft that will give you an introduction into ASP.NET 2.0 and their free ASP.NET editor Visual Web Developer.

http://msdn.microsoft.com/vstudio/express/vwd/easytolearn/ Includes Video tutorials for Visual Web developer aimed at the beginner.

http://msdn2.microsoft.com/en-us/library/ms186106(VS.80).aspx A series of ‘How do I’ in Visual Web Developer tutorials.

http://www.asp.net/QuickStart/aspnet/Default.aspx - Welcome to the ASP.NET 2.0 QuickStart Tutorials from Microsoft.

http://msdn.microsoft.com/vstudio/express/vwd/learning/
Learn the basics of ASP.NET 2.0 and Visual Web Developer 2005 Express Edition with over 6 hours of video. The series of 11 videos features data access, master pages, site navigation, themes and skins, caching, localization and more.
http://forums.asp.net
Microsoft's excellent ASP.NET forum
.

http://www.asp.net/default.aspx?tabindex=5&tabid=41
ASP.NET 2.0 Starter Kits for Visual Web Developer 2005 Express Edition. Easily set up.