Tuesday 23 April 2013

string array using asp.net

string array using asp.net:


   string[] arrID = new string[20];
    int Count;
    Count = dsSearch.Tables[0].Rows.Count;
       for (int i = 0; i < 3; i++)
        {
             arrID[i] = dsSearch.Tables[0].Rows[i]["UserId"].ToString() + ",";
              aa += arrID[i];
         }
              
       bb= aa.Trim(',');              //last , are Deleted



xl sheet File Upload and Insert in asp.net c#


xl sheet Upload and Insert in asp.net c#

aspx:


     XL Question Upload:
<div>
       <asp:Label ID="lblXLUpload" runat="server" Text="XL Upload
       Question:"></asp:Label>
       <i style="color:Red">(Should be xls format)
       </i>      
       <asp:FileUpload ID="QueUploadXL" runat="server"/>

        <asp:RequiredFieldValidator ID="ReqXL" runat="server" 
        ValidationGroup="XL" ControlToValidate="QueUploadXL"      
        ErrorMessage="Select XL File"></asp:RequiredFieldValidator>
    
        <asp:Button ID="btnXLUpload" runat="server" Text="XL Data Upload"
          ValidationGroup="XL"  onclick="btnXLUpload_Click"/>
   
</div>

         -------------------------------------------------------------
aspx:cs

NameSpace:

using System.Data.OleDb;

protected void btnXLUpload_Click(object sender, EventArgs e)
   {
     try
       {
         if (Page.IsValid)
          {
           if (QueUploadXL.HasFile)
            {
               string FName, Path, OlXL;
               FName = QueUploadXL.FileName;
               Path = Server.MapPath(".");
               string XLPath = Path + "/Image/" + FName;
               QueUploadXL.SaveAs(Path + "/Image/" + FName);
               string XLConnString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
                "Data Source=" + XLPath + ";" + "Extended Properties=Excel 
                 8.0;";
                OleDbConnection OleConn = new  
                OleDbConnection(XLConnString);
                OleDbCommand OleCmd = new OleDbCommand();
              OlXL = "Select * From [Sheet1$]";
              OleCmd = new OleDbCommand(OlXL, OleConn);
              OleConn.Open();
              dt.Load(OleCmd.ExecuteReader());
              OleConn.Close();
              FileInfo fileinfo = new FileInfo(XLPath);
                 fileinfo.Delete();
              Count = Convert.ToInt16(dt.Rows.Count.ToString());
              for (int i = 0; i < Count; i++)
               {
                 try
                  {
                   Conn.Open();
                   Que = dt.Rows[i]["Question"].ToString();
                   Cate = dt.Rows[i]["Category"].ToString();
                   OptA = dt.Rows[i]["OptionA"].ToString();
                   OptB = dt.Rows[i]["OptionB"].ToString();
                   OptC = dt.Rows[i]["OptionC"].ToString();
                   OptD = dt.Rows[i]["OptionD"].ToString();
                   Answer = dt.Rows[i]["Answer"].ToString();
Already Record Check:
C              Select = "Select QuestionID From    
                     KnowledgeBowl_Question Where Question='" + Que + "'";
                   da = new SqlDataAdapter(Select, Conn);
                   da.Fill(ds);
                    if (ds.Tables[0].Rows.Count != 0)
                   {
                    QuesID = ds.Tables[0].Rows[0]["QuestionID"].ToString();
Already Record Check in Delete:
                    Delete = "Delete From Question Where      
                    QuestionID='" + QuesID + "'";
                    Cmd = new SqlCommand(Delete, Conn);
                    Cmd.ExecuteNonQuery();
                    ds.Clear();
                   Insert();
                     }
                    else
                     {
                       Insert();
                     }

                }
                   catch (Exception Ex)
                     {
                            Response.Write(Ex);
                    }
                    finally
                     {
                            Conn.Close();
                     }
                  }

                    Response.Write("<script>alert('Added Sucessfully!!') 

                      </script>");
                }
            }
        }
        catch (Exception Ex)
        { 
        
        }
    }


 public void Insert()
    {
        SqlCommand Cmd = new SqlCommand("SP_Question", Conn);
        Cmd.Parameters.Add("@Question", SqlDbType.VarChar).Value =    
        Que.Trim();
        Cmd.Parameters.Add("@Category", SqlDbType.VarChar).Value =  
         Cate.Trim();
        Cmd.Parameters.Add("@OptionA", SqlDbType.VarChar).Value =  
        OptA.Trim();
        Cmd.Parameters.Add("@OptionB", SqlDbType.VarChar).Value =
        OptB.Trim();
        Cmd.Parameters.Add("@OptionC", SqlDbType.VarChar).Value = 
        OptC.Trim();
        Cmd.Parameters.Add("@OptionD", SqlDbType.VarChar).Value =  
         OptD.Trim();
        Cmd.Parameters.Add("@Answer", SqlDbType.VarChar).Value =  
        Answer.Trim();
        Cmd.CommandType = CommandType.StoredProcedure;
        Cmd.ExecuteNonQuery();
    }

Saturday 20 April 2013

Repeater Control Using asp.net Design and C#

Repeater Control Using asp.net Design and C# 

Repeater Control  Using asp.net Design and C# :

CSS Style:
<style type="text/css">
      .divrpt
        {
          margin: 20px;
          font-family: Verdana;
          color: Maroon; 
          font-size: 20px;
       }
     .rpt
        {
            border: 1px solid #84945a;
            -moz-border-radius: 8px;
            -webkit-border-radius: 8px;
            -khtml-border-radius: 8px;
            color: #071019;
            padding: 0px;
       }
      .rpttr
        {
            border: 2px solid white;
            -moz-border-radius: 8px;
            -webkit-border-radius: 8px;
            -khtml-border-radius: 8px;
            background-color: #319471;
            padding: 0px;
        }
      .rptSpan
        {
            color: White;
            font-family: Verdana;
        }
      .rptmar
         {
            margin: 10px;
            color: Maroon;
            font-family: Verdana;
         }
     .rpta
        {
            color: Maroon;
            width: 200px;
            height: auto;
            text-decoration: underline;
        }
     .rpta:hover
        {
            color: #b70b6e;
            text-decoration: underline;
        }
     .rpttdWidth
        {
            width:100px;
         }
      .rptTr
          {
             border-bottom: dashed 1px maroon; 
             background-color: #F5FAEA;
            }
  </style>
     ------------------------------------------------------------

aspx: 



<div style="margin: 20px;" align="center">

  <div class="divrpt">
            <asp:Label ID="lblName" runat="server"></asp:Label>
  </div>

  <div class="rpt">
      <asp:Panel ID="pnl" runat="server">
           <asp:Repeater ID="rptList" runat="server">
               <HeaderTemplate>
                 <table>
                     <tr class="rpttr">
                       <td align="center">
                           <span class="rptSpan">Category</span>
                        </td>
                        <td>
                             </td>
                        <td align="center">
                           <span class="rptSpan">Product Name</span>
                        </td>
                        <td align="center" class="rpttdWidth">
                           <span class="rptSpan">Priority</span>
                       </td>
                        <td align="center" class="rpttdWidth"
                            <span class="rptSpan">Price </span>
                        </td>
                              <td align="center" class="rpttdWidth">
                            <span class="rptSpan">Quantity</span>
                         </td>
                         <td align="center" class="rpttdWidth">
                         </td>
                   </tr>
          </HeaderTemplate>
          <ItemTemplate>
                 <tr class="rpttr">
                    <td align="center">
                        <asp:Label CssClass="rptmar" ID="Label5" 
                             Width="130px" runat="server"
                             Text='<%#Eval("CategoryName") %>'>
                                 </asp:Label>
                   </td>
                   <td align="center">
                       <img class="rptmar" style="border: solid 1px silver"  
                             alt="Image"   src='<%#Eval("ImagePath") %>'
                              width="100px" height="100px" />
                  </td>
                  <td align="center">
                    <a class="rpta" href="Default.aspx?ID=<%#Eval("Id") %>">
                         <asp:Label Style="text-decoration: underline"   
                         ID="lblProName" Width="200px" runat="server"
                         Text='<%#Eval("ProductName") %>'>
                     </asp:Label>
                   </a>
                   <br />
                  <div style="text-align: left">
                     <span style="vertical-align: top; font-family: Verdana;
                         font-size:10px">color:</span>
                    <asp:Label ID="lblColor" BorderColor="Silver"     
                         BorderWidth="2px" BorderStyle="Solid"
                         Width="30px" Height="25px" runat="server">
                  </asp:Label>
                 </div>
              </td>
                 <td align="center">
                 <asp:Label CssClass="rptmar" ID="Label1" runat="server"    
                   Text='<%#Eval("Priority") %>'></asp:Label>
            </td>
            <td align="center" style="font-family: Verdana; color: Red">
              <asp:Label Style="margin-left: 10px" ID="Label3" runat="server" 
                 Text="$"></asp:Label>
               <asp:Label ID="Label2" runat="server" 
                Text='<%#Eval("Price")%>'></asp:Label>
            </td>
            <td style="margin: 10px" align="center">
               <asp:Label CssClass="rptmar" ID="Label4" runat="server"  
                  Text='<%#Eval("QuantityRequired") %>'></asp:Label>
             </td>
             <td style="width: 100px" align="center">
                  <a class="rptmar" style="background-color: #976ea4;
                      width:  150px; height: 50px; color: White;
                      text-decoration: none; border: dashed 1px white"      
                     href="Buy.aspx?BID=<%#Eval("BID") %>">
                  Buy it!</a>
              </td>
       </tr>
          <tr>
            <td colspan="7">
                 <div style="border: dashed  0.1em maroon">
                  </div>
            </td>
           </tr>
       </div>
    </ItemTemplate>
    <FooterTemplate>
         <tr class="rpttr">
           <td colspan="7" align="center">
               <asp:Label Height="30px" Style="color: White; 
                  font-family:  Verdana; font-size: 20px"
                  ID="lblFotterName" runat="server"></asp:Label>
             </td>
          </tr>
      </table>
  </FooterTemplate>
</asp:Repeater>
</asp:Panel>
   </div>
    </div>

       --------------------------------------------------------------------

aspx:CS

 protected void Page_Load(object sender, EventArgs e)
   {
        View();
        ViewName();
 }
 public void View()
    {
          UserID = Session["UserId"].ToString();
        Select = "Select * From Product Where UserID='" + UserID + "'";
        da = new SqlDataAdapter(Select, Conn);
        da.Fill(ds);
        rptList.DataSource = ds;
        rptList.DataBind();
        foreach (RepeaterItem rpt in rptList.Items)
        {
            Label lbl = (Label)rpt.FindControl("lblColor");
            lbl.Attributes.Add("style", "background-color:" +  
            ds.Tables[0].Rows[rpt.ItemIndex]["Color"] + ";");
        }
    }
 Find Controls:
    public void ViewName()
    {
        SelectName = "Select
        GroomName,BrideName,CONVERT(Varchar(20),WeddingDate,107)
        WeddingDate From Registration Where UserId='" + UserID + "'";
        da = new SqlDataAdapter(SelectName, Conn);
        da.Fill(ds, "Name");
        GroomName = ds.Tables["Name"].Rows[0]["GroomName"].ToString();
        BrideName = ds.Tables["Name"].Rows[0]["BrideName"].ToString();
        WedDate = ds.Tables["Name"].Rows[0]["WeddingDate"].ToString();
        lblGroomName.Text = GroomName + " & " + BrideName + "'s wedding
          on " + WedDate;
 Find Controls:
        Label lblFotter rptList.Controls[rptList.Controls.
        Count -  1].FindControl("lblFotterName") as Label;
        lblFotter.Text = GroomName+" & "+BrideName+" 's";
     
}

          -------------------------------------------------

Screen:

               


Footer Design:

Tuesday 16 April 2013

DataList Using asp.net c# and Design css style



 DataList Using asp.net c# and Design css style:


CSS Style:

      .CssOuting
         {
            border: 2px solid #84945a;
            -moz-border-radius: 8px;
            background-image: url(../Images/Home/bg_pattern.jpg);
            -webkit-border-radius: 8px;
            -khtml-border-radius: 8px;
            color: #071019;
            box-shadow: inset 0 0 45px #84945a;
            padding: 0px;
            margin-left: 10px;
            margin-top: 20px;
            width: 830px;
       }

     .Head
        {
            font-size: 25px;
            font-family: Georgia, Times New Roman, serif;
            color:#84945a;
            height: 50px;
            line-height:2;
            border-bottom:dotted 1px #84945a;
       }
   .HeadType
        {
             color: #826279; 
          margin-left: 20px;
          font-family:Verdana;
          font-size:18px;
          font-weight:bold;
        }

   .tbltd
        {
            margin: 10px;
          width: 170px;
        }

   .divtd
        {
            webkit-border-radius: 5px;
          -moz-border-radius: 5px;
          border-radius: 5px;
          background-color: White; /*border: solid 2px #755095;*/
          border: solid 2px silver;
          margin: 10px;
          height: 200px;
        }
   .divtda
        {
            font-weight: bold;
            font-family: Georgia, Times New Roman, serif;
            color: Maroon;
            margin: 10px;
        }


.divtdImg
        {
             width: 125px;
            height: 140px;
            margin: 10px;
        }

.divSpanHd
        {
            webkit-border-radius: 5px;
            -moz-border-radius: 5px;
            border-radius: 5px; /*border: solid 2px #755095;*/
            border: solid 2px silver;
            background-color: #4da28f;
            font-family: Verdana;
            height: 35px;
            font-weight: bold;
            color: White;
            font-size: 20px;
            text-align: center;
        }
        -----------------------------------------------------------------

aspx :



 <div class="CssOuting">
        <div align="center" class="Head">
                Actor
        </div>

       <div class="HeadType">
                Actor Type
       </div>
   <div>

       <asp:DataList Width="750px" ID="dlActor" RepeatColumns="3" 
                                RepeatLayout="Table" runat="server">
        
         <ItemTemplate>
           <table>
                  <tr>
                  <td class="tbltd">
                   <div class="divtd">
                       <a href="Actor.aspx?Name=<%#Eval("ActorName")%>"  
                           class="divtda" 
                         <img src='<%#Eval("ActImgPath")%>' 
                          Class="divtdImg"  />
                         <br />
                      </a>
                  <div class="divSpanHd">
                     <asp:Label ID="lblName" runat="server"
                       Text='<%# Eval("subcategoryname")%>'>
                     </asp:Label>
                   </div>
                        </div>
                </td>
            </tr>
         </table>
        </ItemTemplate>
      </asp:DataList>
</div>
          -----------------------------------------------------------------
aspx:cs C#
  SqlConnection Conn = new   SqlConnection(ConfigurationManager.AppSettings["Connections"]);
  SqlDataAdapter da = new SqlDataAdapter();
  DataSet ds = new DataSet();
  string Select ;
 
     protected void Page_Load(object sender, EventArgs e)
     {
        View();
     }

   public void View()
    {
        Select = "Select * From Actor";
        da = new SqlDataAdapter(Select, Conn);
        da.Fill(ds);
           if (ds.Tables[0].Rows.Count != 0)
             {
                dlActor.DataSource = dsPho;
                dlActor.DataBind();
             }
          else
            {
                 Response.write("No Data");
             }
     }

            -----------------------------------------------------------------
Screen:

         

Saturday 6 April 2013

Master Page Using Login Current URL Run

Master Page Using Login Current Page URL Run


 LogIn Table :
 
Master Page:
URL:

   


aspx:cs:

  protected void LogIn_click(object sender, EventArgs e)
    {
        .....
        ....
        string Url = HttpContext.Current.Request.Url.AbsoluteUri;
        Response.Redirect(Url, false);
     }


URL:


LogIn Current URL Only Run in asp.Net









Friday 5 April 2013

Css Menu Using Database UL LI in asp.net


Css Menu Using Database UL LI in asp.net Repeater:

CSS Style:
<style type="text/css">
    #Menu
         {
              background-color: #84945a;
            font-family: Arial, Helvetica, sans-serif;
            font-size: 14px;
            margin: 0;
            padding: 0;
            border-radius: 5px;
            webkit-border-radius: 5px;
            -moz-border-radius: 5px;
            font-family: Verdana;
            width: 150px;
            list-style: none; /*#707070#A9A9A9*/
         }
    #Menu li
        {
            padding: 10px;
            font-family: Verdana;
            border-bottom: dotted 1px white;
        }
     #Menu li a
        {
           color: White;
           text-decoration: none;
        }
      #Menu li:hover li
        {
           cursor:pointer;
           color: #84945a;
           background-repeat:no-repeat;
           border:dotted 1px #84945a;
        }
      #Menu li a:hover
        {
           color:Maroon;
         }
      #Menu li a:active
        {
             background-color: White;
             color: #84945a;
         }
      #Menu li ul
        {
            display: none;
        }
      . lbl
        {
               color:#b70b6e;
             font-family:Verdana;
             font-size:20px;
         }
  
 </style>

aspx:

   <div>
        <asp:Label Text=":Actor Type:"  CssClass="lbl"  runat="server"> 
         </asp:label>                 
 </div>

 <div style="float:left">
     <ul id="Menu">  
          <asp:Repeater ID="rptMenu" runat="server">
              <ItemTemplate>
                  <li>
                      <a href="Home.aspx?ID=<%#Eval("ActorName") %>">
                        <asp:Label ID="txtText" runat="server" 
                             Text='<%#Eval("ActorName") %>'>      
                         </asp:Label></a>
                 </li>
                </ItemTemplate>
            </asp:Repeater>
      </ul>
  </div>

aspx:cs C#:

  SqlConnection Conn= new SqlConnection(strConnString);
   DataSet ds = new DataSet();

  Load:
   protected void Page_Load(object sender, EventArgs e)
     {
             if (!IsPostBack)
              {
                      Bind();
               }
     }

     
       public void Bind()
        {
           String Select;
           Select = "Select * From Actor";
           da = new SqlDataAdapter(Select, Conn);
           da.Fill(ds);
           rptMenu.DataSource = ds;
           rptMenu.DataBind();
       }



    Screen:



Monday 1 April 2013

Dynamic Table Create C# in asp.net

Dynamic Table Create C# with CSS and aspx Page:


aspx: CS 

using System.Web;

using System.Web.UI;
using System.Web.UI.WebControls;


String Select;int Count;
Page Load :
 protected void Page_Load(object sender, EventArgs e)
 {
      Select = "Select * From Registration";
      da = new SqlDataAdapter(Select, Conn);
      da.Fill(ds);
     Count = ds.Tables[0].Rows.Count;

Table Create:
      Table tbldynamic = new Table();
        tbldynamic.CssClass = "tbl";  - - - >CSS
       
       for (int i = 0; i < Count; i++)
        {
            TableCell tc = new TableCell();
            TableRow tr = new TableRow();
            TableCell tc1 = new TableCell();
            tr.Height = 20;
            Label lblID = new Label();
           TextBox txtName = new TextBox();
            lblID.Height = 20;
            lblID.ID = ds.Tables[0].Rows[i]["ID"].ToString();
            tc.Controls.Add(lblID);
            Label lblName = new Label();
            lblName.ID = "lblName" + i;
            lblName.Text = ds.Tables[0].Rows[i]["Question"].ToString();
            lblName.CssClass = "lbl";      - - - >Label CSS
            tc.Controls.Add(lblName);
            txtName.ID = "txtName" + i;
            txtName.Height = 25;
            txtName.CssClass = "txt";     - - - >Text Box CSS
            txtName.Width = 300;
            tc1.Controls.Add(txtName);
            tr.Cells.Add(tc);
            tr.Cells.Add(tc1);
            tbldynamic.Rows.Add(tr);
            tc = new TableCell();
            tc1 = new TableCell();
            tr = new TableRow();
            tbldynamic.Rows.Add(tr);
            pnl.Controls.Add(tbldynamic);
        }
        pnl.Controls.Add(tbldynamic);
    }

aspx:

     <div align="center" style="margin-top: 40px">
         <div class="head">
               Dynamic Table Creater:
        </div>
        <br />

             <asp:Panel ID="pnl" runat="server">
              </asp:Panel>
        <br />
       <asp:ImageButton ID="btnSave" runat="server" ImageUrl="save.png"/>
     </div>

  CSS Style:
   <style type="text/css">


        .lbl
          {
             font-family: Verdana;
             font-size: 15px;
          }
       .txt
         {
            width: 250px;
            color: Black;
            height: 20px;
            border: solid 1px #d1c7ac;
            padding: 4px 8px;
            margin-bottom: 0px;
         }
      .tbl
         {
            background-color: #E8E8E8;
         }
      .head
        {
            font-family: Verdana;
            font-size: x-large;
            font-weight: bold;
            color: #976ea4;
        }
    </style>

Screen Shot: