Thursday, 30 June 2011

bind state dropdown and by selecting state valid cities display related to that state


use database master
create table Statee(id int, namee varchar(50))
insert into Statee values(1,'Maharashtra')
insert into Statee values(2,'UttarPradesh')
insert into Statee values(3,'AndhraPradesh')
insert into Statee values(4,'Bihar')
drop table statee


create table City(id int , namee varchar(50))
insert into City values (1,'Mumbai')
insert into City values(1,'Pune')
insert into City values(1,'Nashik')
insert into City Values(2,'Luckhnow')
insert into City Values(2,'Kanpur')
insert into City Values(3,'Hyderabad')
insert into City Values(4,'Patna')
insert into City Values(2,'Rajgir')
insert into City Values(2,'Nalanda')

create procedure PMP_GetState
AS
BEGIN
Select * from statee
END


create procedure PMP_GetCity
@stateid int
as
Begin
select * from City
where id=@stateid
end

take two dropdownlist
name as ddlstate and ddlcity
ddlstate autopostback =true
ddlcity collapse edit item add item text= Select and value =0
aspx.cs
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Bind();
}
}
protected void Bind()
{
cls_PMPtables obj = new cls_PMPtables();

DataSet ds = obj.GetState();

if (ds != null)
{
if (ds.Tables[0].Rows.Count > 0)
{
ddlstate.DataSource = ds.Tables[0];
ddlstate.DataValueField = "id";
ddlstate.DataTextField = "namee";
ddlstate.DataBind();

}
}

System.Web.UI.WebControls.ListItem cmbItem;
cmbItem = new System.Web.UI.WebControls.ListItem("-Select-", "0");
ddlstate.Items.Insert(0, cmbItem);
ddlstate.SelectedIndex = 0;


}
protected void ddlstate_SelectedIndexChanged(object sender, EventArgs e)
{
if (ddlstate.SelectedIndex < 0)
return;
bindcity(Convert.ToInt32(ddlstate.SelectedItem.Value.Trim()));
}
private void bindcity(int stateid)
{
cls_PMPtables obj = new cls_PMPtables();
try
{
DataSet ds = obj.Getcity(stateid);
if (ds != null)
{
if (ds.Tables[0].Rows.Count > 0)
{
ddlcity.DataSource = ds.Tables[0];
ddlcity.DataTextField = "namee";
ddlcity.DataValueField = "id";
ddlcity.DataBind();
}
}
}
catch (Exception ex)
{
}
finally
{
obj = null;
}

}
}






Add new class file name as cls_PMPtables

public class cls_PMPtables
{
public SqlConnection sqlconn = new SqlConnection(ConfigurationManager.AppSettings["statecity"]);
SqlCommand cmd = new SqlCommand();
public cls_PMPtables()
{
//
// TODO: Add constructor logic here
//
}

public DataSet GetState()
{
DataSet ds = new DataSet();
try
{
if (sqlconn.State != ConnectionState.Open)
{
sqlconn.Open();
}

SqlCommand cmd = new SqlCommand();
cmd.CommandText = "PMP_GetState";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = sqlconn;
SqlDataAdapter sqlda = new SqlDataAdapter();
sqlda.SelectCommand = cmd;
sqlda.Fill(ds);
}
catch (Exception ex)
{
//Response.write(ex.Message);
}
finally
{
sqlconn.Close();
}
return ds;
}

public DataSet Getcity(int stateid)
{
//CREATE procedure PMP_GetGrantDonation_Type_byGD_Type_Id
//@GD_Type_Id int

DataSet ds = new DataSet();
try
{
if (sqlconn.State == ConnectionState.Closed)
{
sqlconn.Open();
}

SqlCommand cmd = new SqlCommand();
cmd.CommandText = "PMP_GetCity";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = sqlconn;
cmd.Parameters.Add("@stateid", stateid);

SqlDataAdapter sqlda = new SqlDataAdapter();
sqlda.SelectCommand = cmd;
sqlda.Fill(ds);
}
catch (Exception ex)
{
}
finally
{
sqlconn.Close();
}
return ds;
}


}

Tuesday, 28 June 2011

Particular record on colum which we didnt want to display



ALTER procedure [dbo].[PMP_GetGrantDonation_Type_byGD_Type_Id]
@GD_Type_Id int
as

if (@GD_Type_Id = 1)

Begin
select * from PMP_GrantDonation_Type
where gd_type_id=@GD_Type_Id and SubType_Name NOt In ( 'In Kind Donation')
order by GD_SubType_id asc
end

else

Begin
select * from PMP_GrantDonation_Type
where gd_type_id=@GD_Type_Id and SubType_Name NOt In ( 'In-kind Mission','In-kind Friends & Need','In-kind')
order by GD_SubType_id asc
end

Wednesday, 22 June 2011

Monday, 20 June 2011

how to show empty grid view Request.aspx.cs and login with database table



-----------------------how to show empty grid view Request.aspx.cs-----------------------------------

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">

function CalcMarks()
{
debugger;
hdnCount = document.getElementById('hdnCount');
var hcount = parseInt(hdnCount.value);
for (i = 1; i <= hcount; i++)
{
i++;
var num1 = parseInt(document.getElementById('MyMarksgrd_ctl0' + i + '_txtMarks1').value);
var num2 = parseInt(document.getElementById('MyMarksgrd_ctl0' + i + '_txtMarks2').value);
if (num1.value == "" && num2.value == "") {

document.getElementById('MyMarksgrd_ctl0' + i + '_txtTotal').style.backgroundColor = 'red';
return "";
}
if (num1.value == "") {
num1.value = 0;
}
if (num2 + "".length != 0) {
num2.Value = 0;
}
var num3 = parseInt(num1 + num2);
document.getElementById('MyMarksgrd_ctl0' + i + '_txtTotal').value = num3;
i--;
}
}
</script>

</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="MyMarksgrd" runat="server" Width="100%" AutoGenerateColumns="False"
AllowPaging="True" AllowSorting="True" BorderColor="#CC9966" BorderStyle="None"
BorderWidth="1px" CellPadding="4">
<Columns>
<asp:BoundField HeaderText="Sr.NO" />
<asp:TemplateField HeaderText="Marks1" SortExpression="Marks1">
<ItemStyle Wrap="true" />
<ItemTemplate>
<asp:TextBox ID="txtMarks1" MaxLength="3" runat="server" ></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Marks2" SortExpression="Marks2">
<ItemStyle Wrap="true" />
<ItemTemplate>
<asp:TextBox ID="txtMarks2" MaxLength="3" runat="Server" onblur="return CalcMarks();"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Total" SortExpression="Result">
<ItemStyle Wrap="true" />
<ItemTemplate>
<asp:TextBox ID="txtTotal" MaxLength="4" runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
<table style="width: 28%;">
<tr>
<td class="style1">
&nbsp;
</td>
<td>
&nbsp;
</td>
</tr>
<tr>
<td class="style1">
<asp:Button ID="Button1" runat="server" Text="Button" />
</td>
<td>
<asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Button" />
</td>
</tr>
<tr>
<td class="style1">
&nbsp;
</td>
<td>
&nbsp;
</td>
</tr>
</table>
<asp:HiddenField ID="hdnCount" runat="server" />
</form>
</body>
</html>
------------------------------------------Request.aspx.cs ----------------------------------------------------
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
setInitialize();
}
Button1.Text = "Save";
Button2.Text = "Add New Box";
hdnCount.Value = "1";
}

private void setInitialize()
{
DataTable dt = new DataTable();
DataRow dr = null;
dt.Columns.Add(new DataColumn("RowNum",typeof(string)));
dt.Columns.Add(new DataColumn("Column1", typeof(string)));
dt.Columns.Add(new DataColumn("Column2", typeof(string)));
dt.Columns.Add(new DataColumn("Column3", typeof(string)));
dr = dt.NewRow();
dr["RowNum"] = 1;
dr["Column1"] = string.Empty;
dr["Column2"] = string.Empty;
dr["Column3"] = string.Empty;
dt.Rows.Add(dr);

ViewState["Current Table"] = dt;
MyMarksgrd.DataSource = dt;
MyMarksgrd.DataBind();
}

protected void Button2_Click(object sender, EventArgs e)
{
AddNewText();
}

private void AddNewText()
{
int rowIndex = 0;
if (ViewState["Current Table"] != null)
{
DataTable dtCurrentTable = (DataTable)ViewState["Current Table"];
DataRow drCurrentRow = null;
if (dtCurrentTable.Rows.Count > 0)
{
for (int i = 1; i <= dtCurrentTable.Rows.Count; i++)
{
//extract the TextBox values
TextBox box1 = (TextBox)MyMarksgrd.Rows[rowIndex].Cells[1].FindControl("txtMarks1");
TextBox box2 = (TextBox)MyMarksgrd.Rows[rowIndex].Cells[2].FindControl("txtMarks2");
TextBox box3 = (TextBox)MyMarksgrd.Rows[rowIndex].Cells[3].FindControl("txtTotal");

drCurrentRow = dtCurrentTable.NewRow();
drCurrentRow["RowNum"] = i + 1;
drCurrentRow["Column1"] = box1.Text;
drCurrentRow["Column2"] = box2.Text;
drCurrentRow["Column3"] = box3.Text;
rowIndex++;
}

//add new row to DataTable

dtCurrentTable.Rows.Add(drCurrentRow);
//Store the current data to ViewState
ViewState["Current Table"] = dtCurrentTable;

//Rebind the Grid with the current data
MyMarksgrd.DataSource = dtCurrentTable;
MyMarksgrd.DataBind();
string hndCount1 = Convert.ToString(dtCurrentTable.Rows.Count);
hdnCount.Value = hndCount1;
}
}
else
{
Response.Write("ViewState is null");
}
//Set Previous Data on Postbacks
SetPreviousData();
}

private void SetPreviousData()
{
int rowIndex = 0;
if (ViewState["Current Table"] != null)
{
DataTable dt = (DataTable)ViewState["Current Table"];
if (dt.Rows.Count > 0)
{
for (int i = 1; i < dt.Rows.Count; i++)
{
TextBox box1 = (TextBox)MyMarksgrd.Rows[rowIndex].Cells[1].FindControl("txtMarks1");
TextBox box2 = (TextBox)MyMarksgrd.Rows[rowIndex].Cells[2].FindControl("txtMarks2");
TextBox box3 = (TextBox)MyMarksgrd.Rows[rowIndex].Cells[3].FindControl("txtTotal");

box1.Text = dt.Rows[i]["Column1"].ToString();
box2.Text = dt.Rows[i]["Column2"].ToString();
box3.Text = dt.Rows[i]["Column3"].ToString();
rowIndex++;
}
}
}
}
*************************************************************
-----------------------------------------------------------------------------------------------------------------
Login by using sql database table
------------Default.aspx page--------------------------
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
&nbsp;</div>
<table style="z-index: 100; left: 285px; width: 305px; position: absolute; top: 120px;
height: 128px">
<tr>
<td style="width: 100px">
<asp:Label ID="Label1" runat="server" Text="UserName"></asp:Label></td>
<td style="width: 100px">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td style="width: 100px; height: 9px">
<asp:Label ID="Label2" runat="server" Text="Password"></asp:Label></td>
<td style="width: 100px; height: 9px">
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td colspan="2">
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Style="z-index: 100;
left: 107px; position: absolute; top: 96px" Text="Button" />
</td>
</tr>
</table>
<asp:Label ID="Label3" runat="server" ForeColor="Red" Style="z-index: 101; left: 323px;
position: absolute; top: 82px" Text="* Envalid UserName And Password"></asp:Label>
</form>
</body>
</html>
------------Default.aspx.cs page--------------------------
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
string uname,password;
string ConnectionString = "Data Source=TECH-SWAPNILM\\SQLEXPRESS;Initial Catalog=swap;Integrated Security=True";
protected void Page_Load(object sender, EventArgs e)
{
uname = TextBox1.Text;
password = TextBox2.Text;
if(!IsPostBack)
{
Label3.Visible = false;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(ConnectionString);
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "select * from e where username = @uname and password=@password";
cmd.Parameters.AddWithValue("@uname", uname);
cmd.Parameters.AddWithValue("@password",password);
SqlDataReader dr = cmd.ExecuteReader();
if(dr.Read())
{
if ((uname.Equals(@uname)) && (password.Equals(@password)))
{
Response.Redirect("Default2.aspx");
}
}
Label3.Visible = true;
}
}
-------sql table-----------------------
create table e (username varchar(50),password varchar(50))
insert into e values('swapnil','pass')
**********************************************************************


Wednesday, 8 June 2011

flash swf file use on asp.net

<object width="720" height="540"><param name="movie" value="Gallery 1.swf" /><param name="quality" value="high" /><param name="wmode" value="transparent" /><param name="allowScriptAccess" value="always" /><param name="allowFullScreen" value="true" />
</
<embed src="Gallery 1/Gallery 1.swf" quality="high" name="sf" allowScriptAccess="always" allowFullScreen="true" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="720" height="540"></embed>object>

All type of Javascript validation


{



{
dateCompareValidator.style.visibility=
}
}


function




t.value =

}
}
}



function

{
confirmFrm(){if(confirm("All the data entered will be lost, Are you sure you want to go back?"))// window.location.href("AdminUser.aspx");window.location=
}
}
"AdminUser.aspx";OnClientClick="javascript:confirmFrm();return false;"



function
{




}
isNumberKey(evt)var charCode = (evt.which) ? evt.which : event.keyCodeif (charCode > 31 && (charCode < 48 || charCode > 57))return false;return true;
isAlphaNumeric(t) {var iChars = "_!@#$%^&*()+=-[]\\\';,.{}|\":<>`~?";var txt = t.value;for (var i = 0; i < txt.length; i++) {if (iChars.indexOf(txt.charAt(i)) != -1) {"";return false;
function validatefromdate_OnBlur()var txtFromEventDate = document.getElementById("ctl00_ContentPlaceHolder1_txtFromEventDate")var dateCompareValidator = document.getElementById("ctl00_ContentPlaceHolder1_dateCompareValidator")if(txtFromEventDate.value == "" )"hidden";