3 Jun 2014

Minimum and Maximum character length Validation (Minimum 10 and Maximum 15 characters required) in asp.net and js

Minimum and Maximum character length Validation (Minimum 10 and Maximum 15 characters required)
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator Display = "Dynamic" ControlToValidate = "TextBox3" ID="RegularExpressionValidator3" ValidationExpression = "^[\s\S]{10,15}$" runat="server" ErrorMessage="Minimum 5 and Maximum 8 characters required."></asp:RegularExpressionValidator>
======================================================
<table cellpadding="0" cellspacing="0" align="center" width="600">
            <tr>
                <td height="30" colspan="2">
                    <asp:Label ID="Label1" runat="server" Text=""></asp:Label>
                </td>
            </tr>
            <tr>
                <td height="30" colspan="2">
                    <b>Resume Upload Retrieve Example</b>
                </td>
            </tr>
            <tr>
                <td height="30">
                    Select Your Resume
                </td>
                <td>
                    <asp:FileUpload ID="FileUpload1" runat="server" />
                </td>
            </tr>
            <tr>
                <td height="30" colspan="2" align="center">
                    <asp:Button ID="Button1" runat="server" Text="Upload" onclick="Button1_Click" />
                </td>
            </tr>
            <tr>
                <td height="30" colspan="2" align="center">
                    <asp:GridView ID="GridView1" runat="server" DataKeyNames="ID" AutoGenerateColumns="false">
                        <Columns>
                            <asp:TemplateField HeaderText="ID">
                                <ItemTemplate>
                                    <%#Eval("ID")%>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Resume File Name">
                                <ItemTemplate>
                                    <asp:HyperLink Target="_blank" ID="HyperLink1" runat="server" NavigateUrl=' <%# "~/Default2.aspx?ID=" + Eval("ID", "{0:d}")%> '><%#Eval("RNAME")%></asp:HyperLink>                                   
                                </ItemTemplate>
                            </asp:TemplateField>
                        </Columns>
                    </asp:GridView>
                </td>
            </tr>

        </table>

======================================================
public partial class Default2 : System.Web.UI.Page
{
  
    SqlCommand sqlcmd = new SqlCommand();
    SqlDataAdapter da = new SqlDataAdapter();
    DataTable dt = new DataTable();
    string qstr;
    byte[] b = null;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            qstr = Request.QueryString["ID"];
            //Read Resume file from DATABASE table rcontent field
            SqlCommand sqlcmd = new SqlCommand("Select RCONTENT from Rupload where ID='" + qstr + "'", sqlcon); //use condition to retrieve particulatr REsume
            sqlcon.Open();
            da = new SqlDataAdapter(sqlcmd);
            da.Fill(dt);
            if (dt.Rows.Count > 0)
            {
                b = ((byte[])dt.Rows[0][0]);
                //Collect Bytes from database and write in Webpage
                Response.ContentType = "application/msword";
                Response.BinaryWrite(b);
            }
        }
    }
    protected void btnProcess_Click(object sender, EventArgs e)
    {
        string str = string.Empty;
        string strname = string.Empty;
        foreach (GridViewRow gvrow in gvDetails.Rows)
        {
            CheckBox chk = (CheckBox)gvrow.FindControl("chkSelect");
            if (chk != null & chk.Checked)
            {
                str += gvDetails.DataKeys[gvrow.RowIndex].Value.ToString() + ',';
                strname += gvrow.Cells[2].Text + ',';
            }
        }
        str = str.Trim(",".ToCharArray());
        strname = strname.Trim(",".ToCharArray());
        lblmsg.Text = "Selected UserIds: <b>" + str + "</b><br/>" + "Selected UserNames: <b>" + strname + "</b>";
    }
    protected void GetSelectedRecords(object sender, EventArgs e)
    {
        DataTable dt = new DataTable();
        dt.Columns.AddRange(new DataColumn[2] { new DataColumn("Name"), new DataColumn("Country") });
        foreach (GridViewRow row in GridView1.Rows)
        {
            if (row.RowType == DataControlRowType.DataRow)
            {
                CheckBox chkRow = (row.Cells[0].FindControl("chkRow") as CheckBox);
                if (chkRow.Checked)
                {
                    string name = row.Cells[1].Text;
                    string country = (row.Cells[2].FindControl("lblCountry") as Label).Text;
                    dt.Rows.Add(name, country);
                }
            }
        }
        gvSelected.DataSource = dt;
        gvSelected.DataBind();
    }
    foreach(GridViewRow  gvrow in gvDetails.Rows)
{
CheckBox chk = (CheckBox)gvrow.FindControl("chkSelect");
if (chk != null & chk.Checked)
{
str += gvDetails.DataKeys[gvrow.RowIndex].Value.ToString() + ',';
strname += gvrow.Cells[2].Text+',';

}
=========================================================

 SqlConnection sqlcon = new SqlConnection();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            LoadGrid();
        }
        Label1.Text = "";
    }
    void LoadGrid()
    {
        sqlcon.Open();
        SqlCommand sqlcmd;
        SqlDataAdapter da;
        DataTable dt = new DataTable();
        
        sqlcmd = new SqlCommand("select * from RUPLOAD", sqlcon);
        da = new SqlDataAdapter(sqlcmd);
        da.Fill(dt);
        if (dt.Rows.Count > 0)
        {
            GridView1.DataSource = dt;
            GridView1.DataBind();
        }
        sqlcon.Close();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (FileUpload1.HasFile)
        {
            Stream fs = default(Stream);
            fs = FileUpload1.PostedFile.InputStream;
            BinaryReader br1 = new BinaryReader(fs);
            byte[] rbytes = br1.ReadBytes(FileUpload1.PostedFile.ContentLength);
            sqlcon.Open();
            SqlCommand sqlcmd = new SqlCommand("insert into RUPLOAD(RNAME,RCONTENT) values (@rname,@rcon)", sqlcon);
            sqlcmd.Parameters.Add("@rname", FileUpload1.FileName);
            sqlcmd.Parameters.Add("@rcon", rbytes);
            sqlcmd.ExecuteNonQuery();
            sqlcon.Close();
            Label1.Text = "Successfully resume upload to SQL Server database.";
            LoadGrid();
        }      

    }
====================================================================



No comments:

Post a Comment