Sunday 20 October 2013

Transfer values from asp to aspx

<div dir="ltr" style="text-align: left;" trbidi="on">
&lt;% dim get_ip get_ip=Request.ServerVariables("server_name") get_ip="http://"&amp;get_ip&amp;"/TEST/CheckFormIdentity.aspx" %&gt; <html><script type="text/javascript">
    function PageSubmit() {
        document.frm.method = "post";
        document.frm.target = "_blank";
        document.frm.submit();
        window.history.back();
    }
</script>&lt;%
    Response.Write("<form action="&quot;&amp;get_ip&amp;&quot;" id="frm" method="post" name="frm">
")   
    Response.Write(" <input name="UserId" type="hidden" u_id="" value=" &amp; Session(" />")   
    Response.Write(" <input name="FRM_Code" type="hidden" val="" value=" &amp; Request.QueryString(" />")   
    Response.Write("</form>
")
    Response.Write("<script>PageSubmit();</script>")
%&gt;
</html></div>

Friday 26 July 2013

Recursive in C#

A Method can call another methods but it can also call itself. When a mathod calls itself is called Recursive . 

using
System.Collections.Generic;using System.Linq;using System.Text;using System;namespace InterfaceApplication{

class Program{static void Main(){

Program a = new Program();
Console.WriteLine(a.Fib(10));
Console.Read();
}

public long Fib(int n){

if (n == 0 || n == 1)return n;
return n * Fib(n - 1);}
 
 
}
}

Tuesday 23 July 2013

To Check Javascript is enabled or disabled


<
noscript>
<meta http-equiv="refresh" content="0; url=HTMLPage.htm" /></
noscript>

Wednesday 10 July 2013

Common Class for C#

using System;
using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI.WebControls;using System.Data;using System.Data.SqlClient;using System.Configuration;namespace shajil.CommonClass{

public class Common{
public SqlConnection con = new SqlConnection(Convert.ToString(System.Configuration.ConfigurationSettings.AppSettings["connectionString"]));
//Escape Sequence for XML public string ConvertToXMLFormat(string xml){

if (xml != null && xml != string.Empty && xml != ""){
xml = xml.Replace(
"&", "&amp;");xml = xml.Replace(
"\"", "&quot;");xml = xml.Replace(
"'", "&apos;");xml = xml.Replace(
"<", "&lt;");xml = xml.Replace(
">", "&gt;");
return xml;}

elsereturn xml;}

//Fill Dropdown List public void FillDropdownlist(DropDownList ddl, string strTextField, string strValueField, DataTable dt){
ddl.DataSource = dt;
ddl.DataTextField = strTextField;
ddl.DataValueField = strValueField;
ddl.DataBind();
ddl.Items.Insert(0,
new ListItem("Select", string.Empty));
//if (dt.Rows.Count == 1)// ddl.SelectedValue = dt.Rows[0][0].ToString();//else// ddl.SelectedValue = string.Empty;}
//Get Data With Parameter Using Stored Procedure and Dataset.public DataSet GetData1(string procedure, string[,] Parameters){

using (SqlDataAdapter da = new SqlDataAdapter(procedure, con)){
da.SelectCommand.CommandType =
CommandType.StoredProcedure;
for (int i = 0; i < Parameters.GetLength(0); i++){
da.SelectCommand.Parameters.Add(
new SqlParameter(Parameters[i, 0], Parameters[i, 1]));}

DataSet ds = new DataSet();da.Fill(ds);

return ds;}
}

//Get Data With Parameter Using Stored Procedure nd Datatable.public DataTable GetData(string procedure, string[,] Parameters){

using (SqlDataAdapter da = new SqlDataAdapter(procedure, con)){
da.SelectCommand.CommandType =
CommandType.StoredProcedure;
for (int i = 0; i < Parameters.GetLength(0); i++){
da.SelectCommand.Parameters.Add(
new SqlParameter(Parameters[i, 0], Parameters[i, 1]));}

DataTable dt = new DataTable();da.Fill(dt);

return dt;}
}

//Get Data With Out Parameter Using Stored Procedure.public DataTable GetData(string procedure){

using (SqlDataAdapter da = new SqlDataAdapter(procedure, con)){
da.SelectCommand.CommandType =
CommandType.StoredProcedure;
DataTable dt = new DataTable();da.Fill(dt);

return dt;}
}
 

//Insert/Update/Delete Data With Parameter Using Stored Procedure.public string Insert_Update_Data(string procedure, string[,] Parameters){

//Checking the connection stateif (con.State != ConnectionState.Open)con.Open();

//Creating a command objectusing (SqlCommand ObjCom = new SqlCommand(procedure, con)){

//Command type is for stored procedure ObjCom.CommandType = CommandType.StoredProcedure;
//Passing parfor (int i = 0; i < Parameters.GetLength(0); i++){
ObjCom.Parameters.Add(
new SqlParameter(Parameters[i, 0].ToString(), Parameters[i, 1].ToString()));}

string Message = string.Empty;
if (Parameters[1, 1] == "UPDATE" || Parameters[1, 1] == "INSERT" || Parameters[1, 1] == "DELETE"){

DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(ObjCom);da.Fill(dt);

if (dt.Rows.Count > 0)Message = dt.Rows[0][0].ToString();
}

elseObjCom.ExecuteNonQuery();
if (con.State != ConnectionState.Closed)con.Close();

return Message;}
}
}
}

Nested GridView in asp.net

<%
@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Default16" %><%
@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"Namespace="System.Web.UI" TagPrefix="asp" %><!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></
head><
body><form id="form1" runat="server"><asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager><asp:UpdatePanel ID="UpdatePanel1" runat="server"><ContentTemplate><asp:GridView ID="Gridview1" runat="server" BorderStyle="Double" BorderColor="Gold" BackColor="AliceBlue" ShowFooter="true" AutoGenerateColumns="false"> <HeaderStyle BackColor="Green" Font-Bold="true" ForeColor="White" /><Columns><asp:BoundField DataField="RowNumber" HeaderText="Row Number" /><asp:TemplateField HeaderText="Main"><ItemTemplate><table><tr><td><asp:TextBox ID="txt1" runat="server"></asp:TextBox></td><td><asp:TextBox ID="txt2" runat="server"></asp:TextBox></td><td><asp:TextBox ID="txt3" runat="server"></asp:TextBox></td></tr></table><hr /><table><tr><td><asp:GridView ID="gvChildGrid" runat="server" ShowFooter="true" AutoGenerateColumns="false"BorderStyle="Double" BorderColor="#df5015" GridLines="None" Width="250px"><HeaderStyle BackColor="#df5015" Font-Bold="true" ForeColor="White" /><RowStyle BackColor="#E1E1E1" /><AlternatingRowStyle BackColor="White" /><HeaderStyle BackColor="#df5015" Font-Bold="true" ForeColor="White" /><Columns><asp:BoundField DataField="RowNumber" HeaderText="Row Number" /><asp:TemplateField HeaderText="sub"><ItemTemplate><table><tr><td><asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></td><td><asp:TextBox ID="TextBox2" runat="server"></asp:TextBox></td><td><asp:TextBox ID="TextBox3" runat="server"></asp:TextBox></td><td></td></tr></table></ItemTemplate><FooterTemplate><asp:Button ID="ButtonAdd" OnClick="innergridclick" CommandName="<%# Container.DataItemIndex %>"runat="server" Text="Add inner Row" /></FooterTemplate></asp:TemplateField></Columns></asp:GridView></td></tr></table></ItemTemplate><FooterTemplate><asp:Button ID="ButtonAdd" runat="server" Text="Add New Row" OnClick="ButtonAdd_Click" /></FooterTemplate></asp:TemplateField></Columns></asp:GridView></ContentTemplate></asp:UpdatePanel></form></
body></
html>using System;using System.Collections;using System.Configuration;using System.Data;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.HtmlControls;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;public partial class Default16 : System.Web.UI.Page{
protected void Page_Load(object sender, EventArgs e){

if (!Page.IsPostBack){
SetInitialRow();
}
}

private void SetInitialRow(){

DataTable dt = new DataTable();
DataRow dr = null;dt.Columns.Add(
new DataColumn("RowNumber", 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[
"RowNumber"] = 1;dr[
"Column1"] = string.Empty;dr[
"Column2"] = string.Empty;dr[
"Column3"] = string.Empty;dt.Rows.Add(dr);
ViewState[
"CurrentTable"] = dt;Gridview1.DataSource = dt;
Gridview1.DataBind();
SetInitialRow2();
}

private void AddNewRowToGrid(){

int rowIndex = 0;setgridviewvalues();

if (ViewState["CurrentTable"] != null){

DataTable dtCurrentTable = (DataTable)ViewState["CurrentTable"];
DataRow drCurrentRow = null;
if (dtCurrentTable.Rows.Count > 0){

for (int i = 1; i <= dtCurrentTable.Rows.Count; i++){

TextBox box1 = (TextBox)Gridview1.Rows[rowIndex].Cells[1].FindControl("txt1");
TextBox box2 = (TextBox)Gridview1.Rows[rowIndex].Cells[1].FindControl("txt2");
TextBox box3 = (TextBox)Gridview1.Rows[rowIndex].Cells[1].FindControl("txt3");drCurrentRow = dtCurrentTable.NewRow();
drCurrentRow[
"RowNumber"] = i + 1;dtCurrentTable.Rows[i - 1][
"Column1"] = box1.Text;dtCurrentTable.Rows[i - 1][
"Column2"] = box2.Text;dtCurrentTable.Rows[i - 1][
"Column3"] = box3.Text;rowIndex++;
}
dtCurrentTable.Rows.Add(drCurrentRow);
ViewState[
"CurrentTable"] = dtCurrentTable;Gridview1.DataSource = dtCurrentTable;
Gridview1.DataBind();
}
}

else{
Response.Write(
"ViewState is null");}
SetPreviousData();
SetInitialRow2();
}

public void setgridviewvalues(){

if (ViewState["CurrentTable2"] != null){

DataSet dtset = (DataSet)ViewState["CurrentTable2"];
int Dtcount = dtset.Tables.Count;
for (int rowIndex = 0; rowIndex < Gridview1.Rows.Count; rowIndex++){

int rowcount = 0;
DataTable dtCurrentTable = dtset.Tables[rowIndex];
DataRow drCurrentRow = null;
GridView Grdview = (GridView)Gridview1.Rows[rowIndex].Cells[1].FindControl("gvChildGrid");
if (dtCurrentTable.Rows.Count > 0){

for (int i = 1; i <= dtCurrentTable.Rows.Count; i++){

TextBox box1 = (TextBox)Grdview.Rows[rowcount].Cells[1].FindControl("TextBox1");
TextBox box2 = (TextBox)Grdview.Rows[rowcount].Cells[1].FindControl("TextBox2");
TextBox box3 = (TextBox)Grdview.Rows[rowcount].Cells[1].FindControl("TextBox3");drCurrentRow = dtCurrentTable.NewRow();
drCurrentRow[
"RowNumber"] = i + 1;dtCurrentTable.Rows[i - 1][
"Column1"] = box1.Text;dtCurrentTable.Rows[i - 1][
"Column2"] = box2.Text;dtCurrentTable.Rows[i - 1][
"Column3"] = box3.Text;rowcount++;
}
ViewState[
"CurrentTable2"] = dtset;}
}
}
}

private void SetPreviousData(){

int rowIndex = 0;
if (ViewState["CurrentTable"] != null){

DataTable dt = (DataTable)ViewState["CurrentTable"];
if (dt.Rows.Count > 0){

for (int i = 0; i < dt.Rows.Count; i++){

TextBox box1 = (TextBox)Gridview1.Rows[rowIndex].Cells[1].FindControl("txt1");
TextBox box2 = (TextBox)Gridview1.Rows[rowIndex].Cells[1].FindControl("txt2");
TextBox box3 = (TextBox)Gridview1.Rows[rowIndex].Cells[1].FindControl("txt3");box1.Text = dt.Rows[i][
"Column1"].ToString();box2.Text = dt.Rows[i][
"Column2"].ToString();box3.Text = dt.Rows[i][
"Column3"].ToString();rowIndex++;
}
}
}
}

protected void ButtonAdd_Click(object sender, EventArgs e){
AddNewRowToGrid();
}

protected void innergridclick(object sender, EventArgs e){

Button b1 = (Button)sender;
GridViewRow gRow = (GridViewRow)b1.Parent.Parent.Parent.Parent.Parent.Parent;
int Rindex = gRow.RowIndex;AddNewRowToGrid2(Rindex);
}

private void SetInitialRow2(){

DataSet dtset;
if (ViewState["CurrentTable2"] != null){
dtset = (
DataSet)ViewState["CurrentTable2"];
int Dtcount = dtset.Tables.Count;}

else{
dtset =
new DataSet();}

DataTable dt = new DataTable();
DataRow dr = null;dt.Columns.Add(
new DataColumn("RowNumber", 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[
"RowNumber"] = 1;dr[
"Column1"] = string.Empty;dr[
"Column2"] = string.Empty;dr[
"Column3"] = string.Empty;dt.Rows.Add(dr);
dtset.Tables.Add(dt);
ViewState[
"CurrentTable2"] = dtset;
int rowIndex = 0;
for (rowIndex = 0; rowIndex < Gridview1.Rows.Count; rowIndex++){

DataTable dtCurrentTable = dtset.Tables[rowIndex];
GridView Grdview = (GridView)Gridview1.Rows[rowIndex].Cells[1].FindControl("gvChildGrid");Grdview.DataSource = dtCurrentTable;
Grdview.DataBind();
SetPreviousData2(rowIndex);
}
}

private void AddNewRowToGrid2(int rowIndex){

int rowcount = 0;
if (ViewState["CurrentTable2"] != null){

DataSet dtset = (DataSet)ViewState["CurrentTable2"];
int Dtcount = dtset.Tables.Count;
DataTable dtCurrentTable = dtset.Tables[rowIndex];
DataRow drCurrentRow = null;
GridView Grdview = (GridView)Gridview1.Rows[rowIndex].Cells[1].FindControl("gvChildGrid");
if (dtCurrentTable.Rows.Count > 0){

for (int i = 1; i <= dtCurrentTable.Rows.Count; i++){

TextBox box1 = (TextBox)Grdview.Rows[rowcount].Cells[1].FindControl("TextBox1");
TextBox box2 = (TextBox)Grdview.Rows[rowcount].Cells[1].FindControl("TextBox2");
TextBox box3 = (TextBox)Grdview.Rows[rowcount].Cells[1].FindControl("TextBox3");drCurrentRow = dtCurrentTable.NewRow();
drCurrentRow[
"RowNumber"] = i + 1;dtCurrentTable.Rows[i - 1][
"Column1"] = box1.Text;dtCurrentTable.Rows[i - 1][
"Column2"] = box2.Text;dtCurrentTable.Rows[i - 1][
"Column3"] = box3.Text;rowcount++;
}
dtCurrentTable.Rows.Add(drCurrentRow);
ViewState[
"CurrentTable2"] = dtset;Grdview.DataSource = dtCurrentTable;
Grdview.DataBind();
}
}

else{
Response.Write(
"ViewState is null");}
SetPreviousData2(rowIndex);
}

private void SetPreviousData2(int dTindex){

int rowIndex = 0;
if (ViewState["CurrentTable2"] != null){

DataSet dset = (DataSet)ViewState["CurrentTable2"];
DataTable dt = dset.Tables[dTindex];
if (dt.Rows.Count > 0){

GridView Grdview = (GridView)Gridview1.Rows[dTindex].Cells[1].FindControl("gvChildGrid");
for (int i = 0; i < dt.Rows.Count; i++){

TextBox box1 = (TextBox)Grdview.Rows[rowIndex].Cells[1].FindControl("TextBox1");
TextBox box2 = (TextBox)Grdview.Rows[rowIndex].Cells[1].FindControl("TextBox2");
TextBox box3 = (TextBox)Grdview.Rows[rowIndex].Cells[1].FindControl("TextBox3");box1.Text = dt.Rows[i][
"Column1"].ToString();box2.Text = dt.Rows[i][
"Column2"].ToString();box3.Text = dt.Rows[i][
"Column3"].ToString();rowIndex++;
}
}
}
}
}