Thursday, 6 December 2012

image uploading with image datafild

//codepage

<%
@ Page Language="C#" AutoEventWireup="true" CodeFile="image.aspx.cs" Inherits="image" %>
<!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"><div><asp:FileUpload ID="FileUpload1" runat="server" /><asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" /></div><div><asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false"><Columns><asp:TemplateField HeaderText="Photo"><ItemTemplate><asp:Image ID="Image1" runat="server" Width="50" Height="50" ImageUrl='<%# "Handler.ashx?id=" + Eval("Img_Id") %>' /></ItemTemplate></asp:TemplateField><asp:TemplateField HeaderText="imageno"><ItemTemplate><asp:Label ID="lab1" runat="server" Text='<%# Bind("Img_Id") %>' /></ItemTemplate></asp:TemplateField><asp:TemplateField HeaderText="ImageType"><ItemTemplate><asp:Label ID="lab1" runat="server" Text='<%# Bind("Image_Type") %>' /></ItemTemplate></asp:TemplateField><asp:TemplateField HeaderText="ImageSize"><ItemTemplate><asp:Label ID="lab1" runat="server" Text='<%# Bind("Image_Size") %>' /></ItemTemplate></asp:TemplateField></Columns></asp:GridView></div></form></
body></
html>

//code page
using System;using System.Collections;using System.Configuration;using System.Data;using System.Linq;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;using System.Xml.Linq;using System.IO;using System.Data.SqlClient;using DatabaseUtility;public partial class image : System.Web.UI.Page{
GlobalConnection GST = new GlobalConnection();
SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["testConnectionString"].ConnectionString);
protected void Page_Load(object sender, EventArgs e){
GridView1.DataSource = FetchAllImagesInfo();
GridView1.DataBind();
}

protected void Button1_Click(object sender, EventArgs e){

if (FileUpload1.PostedFile != null && FileUpload1.PostedFile.FileName != ""){

byte[] myimage = new byte[FileUpload1.PostedFile.ContentLength];
HttpPostedFile Image = FileUpload1.PostedFile;Image.InputStream.Read(myimage, 0, (
int)FileUpload1.PostedFile.ContentLength);
SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["testConnectionString"].ConnectionString);
SqlCommand storeimage = new SqlCommand("insert into ImageGallery "+ "(Image_Content, Image_Type, Image_Size) "+ " values (@image, @imagetype, @imagesize)", myConnection);storeimage.Parameters.Add(
"@image", SqlDbType.Image, myimage.Length).Value = myimage;storeimage.Parameters.Add(
"@imagetype", SqlDbType.VarChar, 100).Value= FileUpload1.PostedFile.ContentType;
storeimage.Parameters.Add(
"@imagesize", SqlDbType.BigInt, 99999).Value= FileUpload1.PostedFile.ContentLength;
myConnection.Open();
storeimage.ExecuteNonQuery();
myConnection.Close();
}
}

public DataTable FetchAllImagesInfo(){

string sql = "Select * from ImageGallery";
SqlDataAdapter da = new SqlDataAdapter(sql, myConnection);
DataTable dt = new DataTable();da.Fill(dt);

return dt;}
}

url:http://www.aspdotnetcodes.com/Insert_Images_Database.aspx

Friday, 20 July 2012

create dynamic control using edmx to insert data


 //Create Dynamic Control
 //.aspx page

 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="add_meeting.aspx.cs" Inherits="add_meeting" %>

<%@ Register Src="UI/header.ascx" TagName="header" TagPrefix="uc2" %>
<%@ Register Src="~/UI/sidebar.ascx" TagName="Sidebar" TagPrefix="uc3" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" 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>Meeting Deatil</title>
    <link rel="stylesheet" type="text/css" href="CSS/style.css" />
    <%--<script type="text/javascript">
        function change(obj) {
            document.getElementById("TextBox1").value = obj.value;
        }
    </script>--%>
    <script src="js/addmeeting.js" type="text/javascript"></script>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager id="ScriptManager1" runat="server"></asp:ScriptManager>
  
 
    <div id="wrapper">
  
        <uc2:header ID="header" runat="server" />
        <div id="splash">
            <div>
                <asp:updatepanel id="updtpnl" runat="server">
                    <contenttemplate>
                        <table>
                            <tr>
                                <td valign="top" width="170px" style="background-color: #C0C0C0;">
                                  <uc3:Sidebar ID="head" runat="server" />
                                </td>
                                <td>
                                    <asp:Panel ID="pan" runat="server">
                                        <table width="100%">
                                            <tr>
                                                <td>
                                                    <asp:Label ID="lbl_type" runat="server" Text="Meeting Type"></asp:Label>
                                                </td>
                                                <td>
                                                    <asp:DropDownList ID="Drp_Type" runat="server" CssClass="drp">
                                                        <asp:ListItem>--Select--</asp:ListItem>
                                                        <asp:ListItem>Executive Committee</asp:ListItem>
                                                        <asp:ListItem>GBB</asp:ListItem>
                                                    </asp:DropDownList>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    <asp:Label ID="lbl_subject" runat="server" Text="Subject"></asp:Label>
                                                </td>
                                                <td>
                                                    <asp:TextBox ID="tb_subject" runat="server" CssClass="txtclass"
                                                        TextMode="MultiLine"></asp:TextBox>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    <asp:Label ID="lbl_date" runat="server" Text="Meeting Date"></asp:Label>
                                                </td>
                                                <td>
                                                    <asp:TextBox ID="tb_date" runat="server" CssClass="txtclass"></asp:TextBox>
                                                    <asp:CalendarExtender ID="tb_date_CalendarExtender" runat="server" Enabled="True"
                                                        TargetControlID="tb_date" Format="dd/MM/yyyy">
                                                    </asp:CalendarExtender>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    MeetingPlace
                                                </td>
                                                <td>
                                                    <asp:TextBox ID="tb_place" runat="server" CssClass="txtclass"></asp:TextBox>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    <asp:Label ID="lbl_agenda" runat="server" Text="Add No. of Agenda"></asp:Label>
                                                </td>
                                                <td>
                                                    <asp:TextBox ID="tb_agenda" runat="server" OnTextChanged="tb_agenda_TextChanged"
                                                        AutoPostBack="True" CssClass="txtclass"></asp:TextBox>
                                                    <asp:FilteredTextBoxExtender ID="tb_agenda_FilteredTextBoxExtender" runat="server"
                                                        Enabled="True" TargetControlID="tb_agenda" FilterType="Numbers">
                                                    </asp:FilteredTextBoxExtender>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td colspan="2">
                                                    <table border="0" cellpadding="0" cellspacing="0">
                                                        <tr>
                                                            <td>
                                                                <asp:Panel ID="panel_agenda" runat="server">
                                                                    <asp:PlaceHolder ID="ph_Account" runat="server"></asp:PlaceHolder>
                                                                </asp:Panel>
                                                            </td>
                                                        </tr>
                                                    </table>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    <asp:Label ID="lbl_doc" runat="server" Text="Add Document"></asp:Label>
                                                </td>
                                                <td>
                                                    <asp:FileUpload ID="FileUpload1" runat="server" ViewStateMode="Enabled" onchange="change(this)" />
                                                    <%--<asp:TextBox ID="TextBox1" runat="server" Visible="true" Enabled="false"></asp:TextBox>--%>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                </td>
                                                <td>
                                                    <asp:Button ID="btn_add" runat="server" Text="Add" OnClick="btn_add_Click" CssClass="stamp"
                                                        Height="23px" Width="85px" OnClientClick="return Check_Valid1();" />
                                                </td>
                                            </tr>
                                        </table>
                                    </asp:Panel>
                                </td>
                            </tr>
                        </table>
                    </contenttemplate>
                    <triggers>
                        <asp:PostBackTrigger ControlID="btn_add" />
                    </triggers>
                </asp:updatepanel>
            </div>
        </div>
        <div id="page-bottom">
            <div id="page-bottom-content">
            </div>
            <br class="clearfix" />
        </div>
        <div id="footer">
        </div>
    </div>
    </form>
</body>
</html>


//aspx.cs page


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using meeting_newModel;
using System.IO;

public partial class add_meeting : System.Web.UI.Page
{
    int incnt = 0;
    meeting_newEntities2 ent = new meeting_newEntities2();
    string path = "";

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            CreatePlhWithData();
            CreateTempDatatable(0);
        }
        //FileUpload1.Attributes.Add("value", FileUpload1.FileName);
        CreatePlhWithData();
    }

    private void CreatePlhWithData()
    {
        try
        {
            ph_Account.Controls.Clear();
            DataTable dt = (DataTable)Session["dtPlh"];
            incnt = GetRowCount(dt);

            Label Doc1 = new Label();
            Doc1.Text = "Number";
            Doc1.Font.Bold = true;

            Label Doc2 = new Label();
            Doc2.Text = "Agenda Detail";
            Doc2.Font.Bold = true;

            Label Doc3 = new Label();
            Doc3.Text = "Action Taken";
            Doc3.Font.Bold = true;

            Label Doc4 = new Label();
            Doc4.Text = "Sacntioned Amount";
            Doc4.Font.Bold = true;

            if (!IsPostBack)
            {
                Doc1.Visible = false;
                Doc2.Visible = false;
                Doc3.Visible = false;
                Doc4.Visible = false;
            }
            else
            {
                Doc1.Visible = true;
                Doc2.Visible = true;
                Doc3.Visible = true;
                Doc4.Visible = true;
            }

            ph_Account.Controls.Add(new LiteralControl("<table width='100px' cellpadding='0' cellspacing='1' border='0'>"));

            ph_Account.Controls.Add(new LiteralControl("<tr>"));

            ph_Account.Controls.Add(new LiteralControl("<td valign='left' style ='font-size :9pt;font-family :Tahoma ;width='200px';'>"));
            ph_Account.Controls.Add(Doc1);
            ph_Account.Controls.Add(new LiteralControl("&nbsp;"));
            ph_Account.Controls.Add(new LiteralControl("</td>"));

            ph_Account.Controls.Add(new LiteralControl("<td valign='left'  style ='font-size :9pt;font-family :Tahoma ;'>"));
            ph_Account.Controls.Add(Doc2);
            ph_Account.Controls.Add(new LiteralControl("&nbsp;"));
            ph_Account.Controls.Add(new LiteralControl("</td>"));

            ph_Account.Controls.Add(new LiteralControl("<td valign='left' style ='font-size :9pt;font-family :Tahoma ;'>"));
            ph_Account.Controls.Add(Doc3);
            ph_Account.Controls.Add(new LiteralControl("&nbsp;"));
            ph_Account.Controls.Add(new LiteralControl("</td>"));

            ph_Account.Controls.Add(new LiteralControl("<td valign='left' style ='font-size :9pt;font-family :Tahoma ;'>"));
            ph_Account.Controls.Add(Doc4);
            ph_Account.Controls.Add(new LiteralControl("&nbsp;"));
            ph_Account.Controls.Add(new LiteralControl("</td>"));

            ph_Account.Controls.Add(new LiteralControl("</tr>"));

            for (int i = 0; i < incnt; i++)
            {
                ph_Account.Controls.Add(new LiteralControl("<tr>"));

                Label lbl_srno = new Label();
                TextBox txt_agenda = new TextBox();
                TextBox txt_action = new TextBox();
                TextBox txt_sanc_amount = new TextBox();


                txt_agenda.TextMode = TextBoxMode.MultiLine;
                txt_sanc_amount.TextMode = TextBoxMode.MultiLine;
                txt_action.TextMode = TextBoxMode.MultiLine;

                lbl_srno.Text = "[" + (i + 1) + "]";
                lbl_srno.ID = "lbl_srno" + i;

                txt_agenda.ID = "txt_agenda" + i;
                txt_agenda.CssClass = "txtclass";

                txt_action.ID = "txt_action" + i;
                txt_action.CssClass = "txtclass";

                txt_sanc_amount.ID = "txt_sanc_amount" + i;
                txt_sanc_amount.CssClass = "txtclass";

                ph_Account.Controls.Add(new LiteralControl("<td valign='left'>"));
                ph_Account.Controls.Add(lbl_srno);
                ph_Account.Controls.Add(new LiteralControl("</td>"));

                ph_Account.Controls.Add(new LiteralControl("<td valign='left'>"));
                ph_Account.Controls.Add(txt_agenda);
                ph_Account.Controls.Add(new LiteralControl("</td>"));

                ph_Account.Controls.Add(new LiteralControl("<td valign='left'>"));
                ph_Account.Controls.Add(txt_action);
                ph_Account.Controls.Add(new LiteralControl("</td>"));

                ph_Account.Controls.Add(new LiteralControl("<td valign='left'>"));
                ph_Account.Controls.Add(txt_sanc_amount);
                ph_Account.Controls.Add(new LiteralControl("</td>"));

                ph_Account.Controls.Add(new LiteralControl("</tr>"));
            }

            ph_Account.Controls.Add(new LiteralControl("</table>"));
        }
        catch (Exception ex)
        {
            ex.Message.ToString();
        }
    }

    private void CreateTempDatatable(int id)
    {
        try
        {
            DataTable dtPlh = new DataTable();
            DataColumn dc1 = new DataColumn("Number");
            DataColumn dc2 = new DataColumn("Agenda Detail");
            DataColumn dc3 = new DataColumn("Action Taken");
            DataColumn dc4 = new DataColumn("Sacntioned Amount");
            dtPlh.Columns.Add(dc1);
            dtPlh.Columns.Add(dc2);
            dtPlh.Columns.Add(dc3);
            dtPlh.Columns.Add(dc4);
            DataRow drRow;
            for (int intCont = 1; intCont <= id; intCont++)
            {
                drRow = dtPlh.NewRow();
                drRow[0] = "Number" + intCont;
                drRow[1] = "Agenda Detail" + intCont;
                drRow[2] = "Action Taken" + intCont;
                drRow[3] = "Sacntioned Amount" + intCont;
                dtPlh.Rows.Add(drRow);
            }
            Session["dtPlh"] = dtPlh;
        }
        catch (Exception ex)
        {
            ex.Message.ToString();
        }
    }

    private int GetRowCount(DataTable dt)
    {
        int intRowCount = 0;
        try
        {
            for (int i = 0; i <= dt.Rows.Count - 1; i++)
            {
                if (dt.Rows[i].RowState != DataRowState.Deleted)
                {
                    intRowCount = intRowCount + 1;
                }
            }
        }
        catch (Exception ex)
        {
            ex.Message.ToString();
        }
        return intRowCount;
    }

    protected void tb_agenda_TextChanged(object sender, EventArgs e)
    {
        //string sss = string.Empty;
        //sss = TextBox1.Text;
        //path = "Upload" + "/" + sss;
        //FileUpload1.SaveAs(Server.MapPath(path));
        //Session["FileName"] = path;

        FileUpload fu = (FileUpload)this.FindControl("FileUpload1");
        string s = fu.FileName;
        try
        {
            if (tb_agenda.Text.ToString() != "")
            {
                ph_Account.Visible = true;
                CreateTempDatatable(Convert.ToInt32(tb_agenda.Text.ToString()));
                CreatePlhWithData();
            }
            else
            {
                ph_Account.Visible = false;
                CreateTempDatatable(0);
                CreatePlhWithData();
            }
        }
        catch (Exception ex)
        {
            ex.Message.ToString();
        }
        CreatePlhWithData();
    }

    protected void btn_add_Click(object sender, EventArgs e)
    {
        try
        {
            meeting_master mm = new meeting_master();

            //string path = Server.MapPath("~/Offline_uploaded_excel_file");
            //path = path + "\\" + filename;
            //FileUpload1.SaveAs(path);

            //string sss = string.Empty;
            //sss = TextBox1.Text;
            path = "Upload/" + FileUpload1.FileName;
            FileUpload1.SaveAs(Server.MapPath(path));

            mm.meeting_type = Drp_Type.SelectedItem.Text;
            mm.meeting_subject = tb_subject.Text;
            mm.meeting_date = tb_date.Text;
            mm.doc_path = path;
            mm.meeting_place = tb_place.Text;
            ent.AddTomeeting_master(mm);
            ent.SaveChanges();

            int met_id = ent.meeting_master.Where(m => m.meeting_id == ent.meeting_master.Max(w => w.meeting_id)).Select(m => m.meeting_id).Single<int>();
            Add_Attendees(met_id);
            clear();
            Response.Write("<script>alert('insert successfully')</script>");
        }
        catch (Exception ex)
        {
            ex.Message.ToString();
       
        }
    }

    private void clear()
    {
        Drp_Type.ClearSelection();
        tb_subject.Text = "";
        tb_date.Text = "";
        //TextBox1.Text = "";
        tb_place.Text = "";
        tb_agenda.Text = "";
        ph_Account.Controls.Clear();
    }

    private void Add_Attendees(int id)
    {
        DataTable dt = (DataTable)Session["dtPlh"];
        incnt = GetRowCount(dt);

        try
        {
            for (int i = 0; i < incnt; i++)
            {
                meeting_agenda ma = new meeting_agenda();

                TextBox txt_agenda = new TextBox();
                txt_agenda = (TextBox)ph_Account.FindControl("txt_agenda" + i);
                string agenda = txt_agenda.Text;

                TextBox txt_action = new TextBox();
                txt_action = (TextBox)ph_Account.FindControl("txt_action" + i);
                string action = txt_action.Text;

                TextBox txt_sanc_amount = new TextBox();
                txt_sanc_amount = (TextBox)ph_Account.FindControl("txt_sanc_amount" + i);
                string amount = txt_sanc_amount.Text;

                ma.meeting_id = id;
                ma.meeting_agnda = agenda;
                ma.action_taken = action;
                ma.sanction_amount = amount;
                ent.AddTomeeting_agenda(ma);
                ent.SaveChanges();
                //ent.Detach(ma);  //if we define table's object globally
            }

            var t = ent.meeting_agenda.Where(r => r.meeting_id == id).ToList();
            int f = 0;
            int total = 0;

            for (int i = 0; i < t.Count; i++)
            {
                f = Convert.ToInt32(t[i].sanction_amount);
                total = total + f;
            }
            var abc = ent.meeting_master.Where(r => r.meeting_id == id).Single<meeting_master>();
            abc.sanction_amount = total.ToString();
            ent.SaveChanges();
        }
        catch (Exception ex)
        {
            ex.Message.ToString();
        }
    }
}

webservice for farenhit to celcius and vice versa.

//Webservice2

using System;
using System.Collections;

using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;

/// <summary>
/// Summary description for WebService2
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class WebService2 : System.Web.Services.WebService {

    public WebService2 () {

        //Uncomment the following line if using designed components
        //InitializeComponent();
    }

    [WebMethod]
    public string FahrenheitToCelsius(string Fahrenheit)
    {
        object fahr = null;
        fahr = Fahrenheit.Replace(",", ".").Trim(' ');
        if (fahr == "")
        {
            return "Error";
        }
        int returnVal = ((((Convert.ToInt32(fahr)) - 32) / 9) * 5);
        return returnVal.ToString();
    }

    [WebMethod]
    public string CelsiusToFahrenheit(string Celsius)
    {
        object cel = null;
        cel = Celsius.Replace(",", ".").Trim(' ');
        if (cel == "")
        {
            return "Error";
        }
        int returnVal = ((((Convert.ToInt32(cel)) * 9) / 5) + 32);
        return returnVal.ToString();
    }
   
}
//aspx.cs page--connect to webservice


using System;
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;
using System.Web.Services;


public partial class _Default : System.Web.UI.Page
{
   
    WebService w = new WebService();
    WebService2 ws = new WebService2();
    protected void Page_Load(object sender, EventArgs e)
    {
     

     
    }

    protected void btn1_Click(object sender, EventArgs e)
    {
        Label2.Visible = true;
       
       Label2.Text= "Your Celcius is:"+ws.FahrenheitToCelsius(Fahrenheit.Text);

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
     
        Label3.Visible = true;
        Label3.Text = "Your Farenhit is:" + ws.CelsiusToFahrenheit(Celsius.Text);
    }
}
//aspx page

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!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 runat="server">
<table border="solid" bgcolor="Silver">


<tr>
<td>Fahrenheit to Celsius:</td>
<td><asp:TextBox ID="Fahrenheit" runat="server"
size="30"/></td>
</tr>
<tr>
<td><asp:Label ID="Label2" runat="server" Visible="False"></asp:Label></td>
<td align="center"> <asp:Button id="btn1" Text="Submit" class="button" 
        runat="server" onclick="btn1_Click" BorderColor="#669999" 
        BorderStyle="Dotted" align="center" /></td>
</tr>
</table>


<table border="solid" bgcolor="Silver">
<tr>
<td>Celsius to Fahrenheit:</td>
<td><asp:TextBox class="frmInput" 
size="30" id="Celsius" runat="server"/></td>
</tr>
<tr>
<td><asp:Label ID="Label3" runat="server" Visible="False"></asp:Label></td>
<td align="center"> <asp:Button id="Button1" Text="Submit" class="button" 
        runat="server" onclick="Button1_Click" BorderColor="#669999" 
        BorderStyle="Dotted" align="center"  /></td>
</tr>
</table>
</form>
</body>
</html>




Friday, 8 June 2012

javascript for enter numeric or character value

Enter only Numeric Value
function validate(evt) {
  var theEvent = evt || window.event;
  var key = theEvent.keyCode || theEvent.which;
  key = String.fromCharCode( key );
  var regex = /[0-9]|\./;
  if( !regex.test(key) ) {
    theEvent.returnValue = false;
    if(theEvent.preventDefault) theEvent.preventDefault();
  }
}




enter only char value
function checkchar()
{

if ((event.keyCode > 64 && event.keyCode < 91) || (event.keyCode > 96 && event.keyCode < 123) || event.keyCode == 8)
   return true;
else
   {
       alert("Please enter only char");
       return false;
   }

}

<script type="text/javascript">

function f(){

var el=document.getElementById('bang');
var re=/^[A-z]+$/;
if(!re.test(el.value) ) { alert("please enter char only");  }

}

</script>
</head>
<body>
<input type="text" id="bang" onkeyup="f()">

Saturday, 19 May 2012

Report Server in c#


//aspx page

<%@ Page Language="C#" MasterPageFile="~/HOME.master" AutoEventWireup="true" CodeFile="DistrictwiseRainfallReport.aspx.cs" Inherits="DistrictwiseRainfallReport" Title="Untitled Page" %>

<%@ Register Assembly="CrystalDecisions.Web, Version=10.2.3600.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"
    Namespace="CrystalDecisions.Web" TagPrefix="CR" %>
<%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
    Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<table></table>
<br />
    <asp:Panel ID="Panel1" runat="server" ScrollBars="auto" >
<asp:DropDownList ID="Drpyear" runat="server">
<asp:ListItem>SelectYear</asp:ListItem>
    <asp:ListItem>1980</asp:ListItem>
    <asp:ListItem>1981</asp:ListItem>
    <asp:ListItem>1982</asp:ListItem>
    <asp:ListItem>1983</asp:ListItem>
    <asp:ListItem>1984</asp:ListItem>
    <asp:ListItem>1985</asp:ListItem>
    <asp:ListItem>1986</asp:ListItem>
    <asp:ListItem>1987</asp:ListItem>
    <asp:ListItem>1988</asp:ListItem>
    <asp:ListItem>1989</asp:ListItem>
    <asp:ListItem>1990</asp:ListItem>
    <asp:ListItem>1991</asp:ListItem>
    <asp:ListItem>1992</asp:ListItem>
    <asp:ListItem>1993</asp:ListItem>
    <asp:ListItem>1994</asp:ListItem>
    <asp:ListItem>1995</asp:ListItem>
    <asp:ListItem>1996</asp:ListItem>
    <asp:ListItem>1997</asp:ListItem>
    <asp:ListItem>1998</asp:ListItem>
    <asp:ListItem>1999</asp:ListItem>
    <asp:ListItem>2000</asp:ListItem>
    <asp:ListItem>2001</asp:ListItem>
    <asp:ListItem>2002</asp:ListItem>
    <asp:ListItem>2003</asp:ListItem>
    <asp:ListItem>2004</asp:ListItem>
    <asp:ListItem>2005</asp:ListItem>
    <asp:ListItem>2006</asp:ListItem>
    <asp:ListItem>2007</asp:ListItem>
    <asp:ListItem>2008</asp:ListItem>
    <asp:ListItem>2009</asp:ListItem>
    <asp:ListItem>2010</asp:ListItem>
    <asp:ListItem>2011</asp:ListItem>
</asp:DropDownList>
    <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Clickhere" />

        <rsweb:ReportViewer ID="ReportViewer1" runat="server" ProcessingMode="Remote" Width="100%">
        </rsweb:ReportViewer>
         </asp:Panel>
</asp:Content>





//code page
using System;
using System.Data;
using System.Configuration;
using System.Collections;
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 Microsoft.Reporting.WebForms;

public partial class DistrictwiseRainfallReport : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
     
    }
   
    protected void Button1_Click(object sender, EventArgs e)
    {
        ReportViewer1.ShowParameterPrompts = false;
        ReportViewer1.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Remote;
        ReportViewer1.ServerReport.ReportServerUrl = new Uri(System.Configuration.ConfigurationManager.AppSettings["SQL_REPORT_SERVER"]);

        ServerReport objServerReport;
        objServerReport = ReportViewer1.ServerReport;
        objServerReport.ReportPath = System.Configuration.ConfigurationManager.AppSettings["REPORT_FOLDER"] + "DistrictWiseRainfallReport";
//list of parameter define ex:yearwise
        string str2 = Drpyear.SelectedItem.Text;

        ReportParameter objRepoParam_3 = new ReportParameter("YEAR_ID", str2);


        ReportViewer1.ServerReport.SetParameters(new ReportParameter[] { objRepoParam_3 });
        ReportViewer1.ServerReport.Refresh();

    }
}