Monday, 21 November 2016

Use of Repeater in Asp.net

Use Of Repeater in Asp.net





The Repeater Web server control is a data-bound container control that produces a list of individual items. You define the layout of individual items on a Web page by using templates. When the page runs, the control repeats the layout for each item in the data source.



Difference Between Repeater and Data List


Now to Use this:-

Designing Code:-

<asp:Repeater ID="rpt1" runat="server" >
                            <ItemTemplate>
 <div class="panel-body">
                            <div class="row">
                                <div class="col-lg-4 text-center">
                                             <asp:Image ImageUrl='<%# Eval("photo_path") %>' Width="90%" ID="imag1" runat="server" /> 
</div>
<div class="col-lg-4">
<table width="100%">
<tr>
<td><label>Registartion Number:</label></td>
<td><asp:Label ID="reg" runat="server" Text='<%# Eval("regi_no") %>'></asp:Label></td>
</tr>
<tr>
<td><label>Transaction Id:</label></td>
<td><asp:Label ID="Label1" runat="server" Text=""></asp:Label></td>
</tr>
<tr>
<td><label>Name:</label></td>
<td><asp:Label ID="Label2" runat="server" Text='<%# Eval("full_name") %>'></asp:Label></td>
</tr>
<tr>
<td><label>Sex:</label></td>
<td><asp:Label ID="Label3" runat="server" Text='<%# Eval("sex") %>'></asp:Label></td>
</tr>
<tr>
<td><label>Date Of Birth:</label></td>
<td><asp:Label ID="Label4" runat="server" Text='<%# Eval("dob") %>'></asp:Label></td>
</tr>
<tr>
<td><label>Mobile Number:</label></td>
<td><asp:Label ID="Label5" runat="server" Text='<%# Eval("phone") %>'></asp:Label></td>
</tr>
<tr>
<td><label>Email Id:</label></td>
<td><asp:Label ID="Label6" runat="server"  Text='<%# Eval("email_id") %>'></asp:Label></td>
</tr>
<tr>
<td> <label>Father Name:</label></td>
<td><asp:Label ID="Label8" runat="server" Text='<%# Eval("father_name") %>'></asp:Label></td>
</tr>
<tr>
<td> <label>Mother Name:</label></td>
<td><asp:Label ID="Label9" runat="server" Text='<%# Eval("mother_name") %>'></asp:Label></td>
</tr>
<tr>
<td><label>Father Occupation:</label></td>
<td><asp:Label ID="Label10" runat="server" Text='<%# Eval("father_occupation") %>'></asp:Label></td>
</tr>
<tr>
<td><label>Mother Occupation:</label></td>
<td><asp:Label ID="Label11" runat="server" Text='<%# Eval("mother_occupation") %>'></asp:Label></td>
</tr>
                                            <tr>
<td><label>Adhar Number:</label></td>
<td><asp:Label ID="Label12" runat="server" Text='<%# Eval("adhar_no") %>'></asp:Label></td>
</tr>
</table>
                                        </div>
<div class="col-lg-4">
<table width="100%">
<tr>
<td><label>Blood Group:</label></td>
<td><asp:Label ID="Label13" runat="server" Text='<%# Eval("blood_group") %>'></asp:Label></td>
</tr>
<tr>
<td> <label>City:</label></td>
<td><asp:Label ID="Label14" runat="server" Text='<%# Eval("city") %>'></asp:Label></td>
</tr>
<tr>
<td> <label>State:</label></td>
<td><asp:Label ID="Label15" runat="server" Text='<%# Eval("states") %>'></asp:Label></td>
</tr>
<tr>
<td><label>Address:</label></td>
<td><asp:Label ID="Label16" runat="server" Text='<%# Eval("addres") %>'></asp:Label></td>
</tr>
<tr>
<td><label>Country:</label></td>
<td><asp:Label ID="Label17" runat="server" Text='<%# Eval("country") %>'></asp:Label></td>
</tr>
<tr>
<td><label>Zip Code:</label></td>
<td><asp:Label ID="Label18" runat="server" Text='<%# Eval("zipcode") %>'></asp:Label></td>
</tr>
<tr>
<td><label>Current Class:</label></td>
<td><asp:Label ID="Label19" runat="server" Text='<%# Eval("current_class") %>'></asp:Label></td>
</tr>
<tr>
<td> <label>School Name:</label></td>
<td><asp:Label ID="Label20" runat="server" Text='<%# Eval("school_name") %>'></asp:Label></td>
</tr>
<tr>
<td> <label>Principal Name:</label></td>
<td><asp:Label ID="Label21" runat="server" Text='<%# Eval("principal_name") %>'></asp:Label></td>
</tr>
<tr>
<td><label>Board:</label></td>
<td><asp:Label ID="Label22" runat="server" Text='<%# Eval("education_board") %>'></asp:Label></td>
</tr>
<tr>
<td><label>Medium:</label></td>
<td><asp:Label ID="Label23" runat="server" Text='<%# Eval("medium") %>'></asp:Label></td>
</tr>
<tr>
<td><label>Address:</label></td>
<td><asp:Label ID="Label24" runat="server" Text='<%# Eval("school_address") %>'></asp:Label></td>
</tr>
                                            <tr>
                                                
<td colspan="2"><a href="pst_admin_edit.aspx" class="btn btn-info">Edit</a></td>
</tr>
</table>
                                       </div>
                                        </div>
                                      
                              
                                <!-- /.col-lg-6 (nested) -->
                            </div>
                                 </ItemTemplate>
                        </asp:Repeater>

It Will appear Like This:-

now C# Code to add database connection and calling values

public partial class pages_Default : System.Web.UI.Page
{
    SqlCommand cmd;
    SqlDataAdapter da;
    DataSet ds;
    SqlConnection con = new SqlConnection("Data Source=enter your data source;Initial Catalog=database name;User ID=user_id;Password=password");
protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            RepeterData();

        }
    }
    public void RepeterData()
    {
        con.Open();
        cmd = new SqlCommand("Select * from regi", con);
        DataSet ds = new DataSet();
        da = new SqlDataAdapter(cmd);
        da.Fill(ds);
        rpt1.DataSource = ds;
        rpt1.DataBind();
    }
}

Thursday, 5 May 2016

How to Create Login Page in Asp.net

Create Login With Database Using ASP.NET

Login Page Design For More attractive Degin use Bootstap 

Code For Designing

 <div class="row ">
             
                  <div class="col-md-4 col-md-offset-4 col-sm-6 col-sm-offset-3 col-xs-10 col-xs-offset-1">
                        <div class="panel panel-default">
                            <div class="panel-heading">
                        <strong>   Enter Details To Login </strong>
                            </div>
                            <div class="panel-body">
                       
                                       <br />
                                     <div class="form-group input-group">
                                            <span class="input-group-addon"><i class="glyphicon glyphicon-phone"  ></i></span>
                                        <asp:TextBox ID="txtid" runat="server" class="form-control" placeholder="Mobile Number " ></asp:TextBox>
                                        </div>
                                                                              <div class="form-group input-group">
                                            <span class="input-group-addon"><i class="glyphicon glyphicon-lock"  ></i></span>
                                        <asp:TextBox ID="txtpassword" runat="server" TextMode="Password" class="form-control"  placeholder="Your Password"></asp:TextBox>
                                        </div>
                                 <div class="form-group input-group">
                                            <span class="input-group-addon"><i class="glyphicon glyphicon-lock"  ></i></span>
                                     <asp:DropDownList ID="ddl" runat="server" CssClass="form-control">
                                         <asp:ListItem>Select Admin Role</asp:ListItem>
                                         <asp:ListItem>Super Admin</asp:ListItem>
                                         <asp:ListItem>Admin</asp:ListItem>
                                            </asp:DropDownList></div>
                                <asp:RequiredFieldValidator ID="req1" runat="server" ControlToValidate="ddl"  EnableClientScript="false" ErrorMessage="Admin role is not selected" ForeColor="Red" InitialValue="Select Admin Role" ></asp:RequiredFieldValidator>
                                   <div class="links"><a href="forgotpassword.aspx" >FORGOT YOUR ID? / FORGOT YOUR PASSWORD?</a></div>
                                   
                                   <div>  <asp:Button ID="btnlogin" runat="server" CssClass="btn btn-success bg-color-blue" Text="Login Now" OnClick="btnlogin_Click" />
                                     </div>
                                       <div><asp:Label ID="la1" runat="server" ForeColor="Red" ></asp:Label>
                                       </div>
                                 
                                 
                                 
                            </div>
                         
                        </div>
                    </div>

C# Code:-

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 System.Data.SqlClient;
using System.Configuration;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void btnlogin_Click(object sender, EventArgs e)
    {
     
         
                if (txtid.Text == null && txtpassword.Text == null && ddl.SelectedValue== "Select Admin Role")
                {
                    la1.Text = "Invalid id and password";
                }
                else
                {
                    SqlConnection con = new SqlConnection("Data Source=rahul-pc;Initial Catalog=login;User ID=sa;Password=123;");
                    con.Open();
                    SqlCommand cmd = new SqlCommand("select * from users where mobile=@id and password=@password and usertype=@uty ", con);
                    cmd.Parameters.AddWithValue("@id", txtid.Text);
                    cmd.Parameters.AddWithValue("@password", txtpassword.Text);
                    cmd.Parameters.AddWithValue("@uty", ddl.SelectedItem.Value);
                    SqlDataAdapter da = new SqlDataAdapter(cmd);
                    DataTable dt = new DataTable();
                    da.Fill(dt);
                    if (dt.Rows.Count > 0)
                    {
                     
                        if(ddl.SelectedItem.Value=="Super Admin")
                        {
                            Session["UserId"] = txtid.Text;
                        Response.Redirect("index.aspx");
                    }
                        else
                         
                        {
                            Session["UserId"] = txtid.Text;
                            Response.Redirect("~/admin/index.aspx");
                    }
                    }
                    else
                    {
                        la1.Text = "Invalid id and password";
                    }

                }
            }
     
}

Monday, 25 April 2016

How to create a button to download the data from database in excel format

1. step create a button.

2. create connection with database to fetch the data.

3. add reference or install close xmal

when close xmal will be installed it will appear on your solution explorer.
now click on it
excel file is download