Thursday 19 December 2013

xml using xslt in asp.net

xml using xslt in asp.net :

XML :

ProductList.xml

<?xml version="1.0" encoding="utf-8" ?>

 <ProductDetails>
   <products>
        <productID>1</productID>
      <proname>Shoe</proname>
      <price>1000</price>
     <description>Shoe Description</description>
     <image>
       <img src="image/2194484image3.jpg"></img>
     </image>
   </products>
  <products>
      <productID>2</productID>
     <proname>Shoe 2</proname>
     <price>1000</price>
     <description>Shoe Description</description>
     <image>
       <img src="image/2353864Koala.jpg"></img>
     </image>
  </products>
  <products>
     <productID>3</productID>
    <proname>Shoe 3</proname>
    <price>1000</price>
    <description>Shoe Description</description>
    <image>
      <img src="image/2353864Koala.jpg"></img>
    </image>
  </products>
</ProductDetails>

XSLT :

ProductListXSLT.xslt :

 <?xml version="1.0" encoding="utf-8"?>
 <xsl:stylesheet version="1.0"      
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-  prefixes="msxsl">
    <xsl:output method="xml" indent="yes"/>
    <xsl:template match="@* | node()">
        <xsl:copy>
            <xsl:apply-templates select="@* | node()"/>
        </xsl:copy>
    </xsl:template>
--Start 
   <xsl:template match="/">
     <h1>
       <u>
        <font>ProductList</font>
      </u>
       </h1>
      
      <div>
       <table>
        <tr>
--for each Split Nodes
            <xsl:for-each select="//ProductDetails//products">
              
                <td style="width:150px;border:1px solid 
                                 silver;padding:10px;background:aliceblue;">
            <table>
               <tr>
                 <td style="font-family:verdana;font-weight:bold">
--xsl:value-of select Child Name
                  <xsl:value-of select="proname"/>
                </td>
               </tr>
               <tr>
                <td>
                  <xsl:value-of select="price"/>
                </td>
              </tr>
              <tr>
                <td>
                  <xsl:value-of select="description"/>
                </td>
              </tr>
              <tr>
                <td>
--Image Using
                  <img>
                    <input type="image" name="imagem" width="150px">
--Attributes
                      <xsl:attribute name="src">
                        <xsl:value-of select="image/img/@src" />
                      </xsl:attribute>
                    </input>
                  </img>
                </td>
              </tr>
            </table>
              </td>

            </xsl:for-each>

          </tr>

      </table>
    </div>
  </xsl:template>
</xsl:stylesheet>

aspx :

      <asp:Literal ID="litProductList" runat="server">
       </asp:Literal>
aspx.cs :

 using System.Xml;
 using System.Xml.Xsl;

   protected void Page_Load(object sender, EventArgs e)
    {

        GetProductList();
     }
    public void GetProductList()
    {
        string xmlPath = Server.MapPath("ProductList.xml");
        string xsltPath = Server.MapPath("ProductListXSLT.xslt");
       // string htmlPath = Server.MapPath("ProductList.htm");

        XmlReader objXMlReader = XmlReader.Create(xmlPath);
        XslCompiledTransform objXSLCompTransform
                                  new XslCompiledTransform();
        objXSLCompTransform.Load(xsltPath);

        StringBuilder objStrBuil = new StringBuilder();
        TextWriter objTextWri = new StringWriter(objStrBuil);

        objXSLCompTransform.Transform(objXMlReader, null, objTextWri);

        litProductList.Text = objStrBuil.ToString();
        objXMlReader.Close();

      
    }


Tuesday 17 December 2013

message box with OK in C# using asp.net

message box with OK in C# using asp.net :

aspx:cs :


  protected void btn_tomail_Click(object sender, EventArgs e)
        {

     ClientScript.RegisterStartupScript(Page.GetType(), "alert", 
                             "alert('Password Sent Your EmailID !!');
                              window.location='Login1.aspx';", true);

      }




Wednesday 11 December 2013

gridview nested gridview in asp net

gridview nested gridview in asp net :


-- CSS 
<style type="text/css">

      .Grid td
        {
            background-color: #eee;
            color: black;
            font-size: 10pt;
            line-height:200%
        }
        .Grid th
        {
            background-color: #6f6e6e;
            color: White;
            font-size: 10pt;
            line-height:200%
        }
        .ChildGrid td
        {
            background-color: white  !important;
            color: black;
            font-size: 10pt;
            line-height:200%
        }
        .ChildGrid th
        {
            background-color: #890000 !important;
            color: White;
            font-size: 10pt;
            line-height:200%
        }
    </style>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
    $("[src*=plus]").live("click", function () {
        $(this).closest("tr").after("<tr><td></td><td colspan = '999'>" + $(this).next().html() + "</td></tr>")
        $(this).attr("src", "../image/minus.png");
    });
    $("[src*=minus]").live("click", function () {
        $(this).attr("src", "../image/plus.png");
        $(this).closest("tr").next().remove();
    });
</script>

aspx:

<div align="center" style="border: 1px solid silver">
   <asp:GridView ID="grdPro" runat="server" AutoGenerateColumns="false"                 CssClass="Grid" DataKeyNames="product_id"              
              OnRowDataBound="grdPro_RowDataBound" 
              AllowPaging="True" 
              OnPageIndexChanging="grdPro_PageIndexChanging">
     <Columns>
       <asp:TemplateField>
         <ItemTemplate>
            <img alt = "" style="cursor: pointer" src="../image/plus.png" />
--Panel Style Display None

               <asp:Panel ID="pnlOrders" runat="server" Style="display: none">

--Nested Grid

       <asp:GridView ID="grdSubPro" runat="server"             
                   AutoGenerateColumns="false" CssClass = "ChildGrid">
         <Columns>
               <asp:BoundField ItemStyle-Width="150px" 
                           DataField="color" HeaderText="color" />
               <asp:TemplateField ItemStyle-Width="150px"                  
                                     HeaderText="ColorCode">
               <ItemTemplate>
                 <asp:Label ID="lblColorCode" Width="120px"       
                     Text='<%#Eval("color") %>' ForeColor="White"              
                     BackColor='<%#System.Drawing.ColorTranslator.
                     FromHtml(Eval("color").ToString()) %>' runat="server">
              </asp:Label>
           </ItemTemplate>
           </asp:TemplateField>
                <asp:BoundField ItemStyle-Width="150px" 
                           DataField="size"  HeaderText="size" />
           </Columns>
          </asp:GridView>
           </asp:Panel>
          </ItemTemplate>
          </asp:TemplateField>

     <asp:BoundField ItemStyle-Width="150px" 
                  DataField="Productname" HeaderText="Pro-Name" />
     <asp:TemplateField HeaderText="Pro-Image">
           <ItemTemplate>
               <asp:Image ID="imgProImage" runat="server" Width="150px"                        Height="100px" 
                 ImageUrl='<%#string.Format("~/{0}",Eval("Image")) %>' />
                </ItemTemplate>
            </asp:TemplateField>
     <asp:BoundField ItemStyle-Width="150px" 
                   DataField="Productdes" HeaderText="Pro-Description" />
     <asp:BoundField ItemStyle-Width="150px"
                   DataField="Price" HeaderText="Price" />
     <asp:BoundField ItemStyle-Width="150px"
                    DataField="Brandname" HeaderText="Brandname"/>
   </Columns>
    </asp:GridView>
        </div>

aspx:cs :

   protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                grdProductView();
            }
        }
        public void grdProductView()
        {
            Select = "Select * From Product_Master";
            da = new SqlDataAdapter(Select, Conn);
            da.Fill(ds);
            grdPro.DataSource = ds;
            grdPro.DataBind();
            
        }

        protected void grdPro_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                string ProID = grdPro.DataKeys[e.Row.RowIndex].Value.ToString();
                GridView gvSub = e.Row.FindControl("grdSubPro") as GridView;
                Label lblColorcode = e.Row.FindControl("lblColorCode") as Label;

                string select1;
                DataSet ds1 = new DataSet();
                select1 = "Select * From test1 where product_id="+ProID+"";
                da = new SqlDataAdapter(select1, Conn);
                da.Fill(ds1);
                gvSub.DataSource = ds1;
                gvSub.DataBind();
            }
        }

        protected void grdPro_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            grdPro.PageIndex = e.NewPageIndex;
            grdProductView();
        }








C# using id creation dynamically in asp.net

C# using id creation dynamically in asp.net :


aspx:cs :

  string SelectID;
  int ID;
   --Database Table Count
          SelectID = "Select COUNT(*) AS Count From Sample";
          SqlDataAdapter da2 = new SqlDataAdapter(SelectInvoiceID, cn);
          DataSet dsInvoiceID = new DataSet();
          da2.Fill(dsInvoiceID);
                if (dsInvoiceID.Tables[0].Rows.Count != 0)
                {

             int a =
            Convert.ToInt16(dsInvoiceID.Tables[0].Rows[0]["Count"].ToString());
                    int C = a + 1;
                    //ID  creates dynamically if ID count <10
                    if (C > 0 && C <= 9)
                    {
                        ID = "abc0000" + C;
                    }

                    //ID  creates dynamically if ID count 10 to 99
                    else if (C > 9 && C <= 99)
                    {
                        ID = "abc000" + C;
                    }

                    //ID  creates dynamically if ID count 100 to 999
                    else if (C > 99 && C <= 999) ID = "abc00" + C;

                    //ID  creates dynamically if ID count 1000 to 9999
                    else if (C > 999 && C <= 9999) ID = "abc0" + C;

                    //ID  creates dynamically if ID count 10000 to 99999
                    else if (C > 9999 && C <= 99999) ID = "abc" + C;
             

Tuesday 10 December 2013

dynamic table createtion and insert using database in asp.net

dynamic table createtion and insert using database in asp.net :


DataBase :

             Select * From size


        Select * From Attributelist

aspx :


  <div>
        
       <asp:Panel ID="pnl" runat="server">
       </asp:Panel>
          <asp:Button ID="Button1" runat="server" 
          OnClick="Button1_Click"  Text="Button" />

 </div>

aspx.cs :


  SqlConnection Conn = new           
                 SqlConnection(ConfigurationManager.AppSettings["Connection"]);
        SqlDataAdapter da = new SqlDataAdapter();
        DataSet ds = new DataSet();
        DataSet dsTest = new DataSet();
        DataSet dsSize = new DataSet();
        DataSet dsAttr = new DataSet();
        int Count;
        int CountSize, CountAttr;
        string SelectAttr, SelectSize;

    protected void Page_Load(object sender, EventArgs e)
        {
          --Load Table Dynamic Creation
            tblCreation();
        }
  --Dynamic Creation Table
public void tblCreation()
        {
 --Select Attributelist 
          SelectAttr = "Select * From Attributelist";
           da = new SqlDataAdapter(SelectAttr, Conn);
           da.Fill(dsAttr);
           CountAttr = dsAttr.Tables[0].Rows.Count;
 --Select Size 
           SelectSize = "Select * From size";
           da = new SqlDataAdapter(SelectSize, Conn);
           da.Fill(dsSize);
           CountSize = dsSize.Tables[0].Rows.Count;

 --Create Table  <table>
            Table tbldynamicTest = new Table();
 --Create TableRow <tr>  
            TableRow trTest = new TableRow();
 --Create TableCell tableData <td>  
            TableCell tcTest = new TableCell();
--Create Label  
            Label lblHead = new Label();
            trTest.Height = 20;
            Label lblID1 = new Label();
            tcTest.Width = 100;
            lblID1.Height = 20;
            lblID1.ID = "lb1";
            lblID1.Text = "Name";
            lblID1.Width = 100;
--TableCell Add Label
            tcTest.Controls.Add(lblID1);
--TableRow Add TableCell
            trTest.Cells.Add(tcTest);
--Table Add TableRow
            tbldynamicTest.Rows.Add(trTest);

--ColumnCreation            
            for (int i = 0; i < CountSize; i++) 
            {
               
                trTest.Height = 20;
                Label lblName = new Label();
                lblName.ID = 
                          "lblName" + dsSize.Tables[0].Rows[i]["size"].ToString()+i;
                lblName.Text = 
                          dsSize.Tables[0].Rows[i]["size"].ToString();
                lblName.CssClass = "lbl";
                lblName.Width = 100;
--Table Cell Add Label
                tcTest.Controls.Add(lblName);
--Table Row Add TableCell
                trTest.Cells.Add(tcTest);
              }
--Table Add TableRow
            tbldynamicTest.Rows.Add(trTest);
--Panel Add Table
            pnl.Controls.Add(tbldynamicTest);
            for (int i = 0; i < CountAttr; i++)
            {
                TableRow tr = new TableRow();
                TableCell tc = new TableCell();
                tr.Height = 20;
                Label lblName = new Label();
                lblName.ID = "lblName" + i;
                lblName.Text = dsAttr.Tables[0].Rows[i]["name"].ToString();
                lblName.CssClass = "lbl";
                lblName.Width = 100;
                tc.Controls.Add(lblName);
                tr.Cells.Add(tc);
                for (int j = 0; j < CountSize; j++)
                {
--Checkbox Creation
                    CheckBox chk = new CheckBox();
                    chk.ID = 
                           "chk" +dsAttr.Tables[0].Rows[i]["name"].ToString()+ j;
                    chk.Height = 25;
                    chk.CssClass = "txt";
                    chk.Width = 100;
                    tc.Controls.Add(chk);
                    tr.Cells.Add(tc);
                }
--Table Add TR
                tbldynamicTest.Rows.Add(tr);
                pnl.Controls.Add(tbldynamicTest);
            }
--Panel Add Table
            pnl.Controls.Add(tbldynamicTest);
        }



--Save

protected void Button1_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < CountAttr; i++)
            {
                string opid1
                     "lblName" + dsAttr.Tables[0].Rows[i]["name"].ToString() + i;
                Label lblName = (Label)pnl.FindControl(opid1);
                string Attr;
                     Attr = dsAttr.Tables[0].Rows[i]["name"].ToString();
               
                for (int m = 0; m < CountSize; m++)
                {
                    string aa
                          "chk" + dsAttr.Tables[0].Rows[i]["name"].ToString() + m;
                    CheckBox chk = (CheckBox)pnl.FindControl(aa);
                    string opid = "lblName1" + m;
--(pnl)Panel Get label ID
                    Label lblName1 = (Label)pnl.FindControl(opid);
                    string Size = dsSize.Tables[0].Rows[m]["size"].ToString();
--Checkbox  Checked
                    if (chk.Checked == true)
                    {

                     Conn.Open();
--Insert Checked Values
                     SqlCommand cmd = new 
                     SqlCommand("insert into test values
                            ('" + Size.ToString() + "','" + Attr.ToString() + "')", Conn);
                        cmd.ExecuteNonQuery();
                        Conn.Close();
}
                    
                }
            }

        }







Friday 6 December 2013

dynamic table creation in asp.net using c#

dynamic table creation in asp.net using c# :




aspx:

           <asp:Panel ID="pnl" runat="server">
           </asp:Panel>

aspx:cs :

  string Select;
        SqlConnection Conn = new           
                  SqlConnection(ConfigurationManager.AppSettings["Connection"]);
        SqlDataAdapter da = new SqlDataAdapter();
        DataSet ds = new DataSet();
        int Count;
  protected void Page_Load(object sender, EventArgs e)
        {
            tblCreation();
        }

//Method Call
public void tblCreation()
        {
            Select = "Select * From Attributelist";
            da = new SqlDataAdapter(Select, Conn);
            DataSet dsTest = new DataSet();
            da.Fill(dsTest);
            int CountTest;
            CountTest = dsTest.Tables[0].Rows.Count;
--Table Creation
            Table tbldynamicTest = new Table();
--Table Row <tr>
            TableRow trTest = new TableRow();
--Table Data<td>
            TableCell tcTest = new TableCell();
--Label
            Label lblHead = new Label();
            trTest.Height = 20;
            Label lblID1 = new Label();
            tcTest.Width = 100;
            lblID1.Height = 20;
            lblID1.ID = "lb1";
            lblID1.Text = "Name";
            lblID1.Width = 100;
--TC Add Label
            tcTest.Controls.Add(lblID1);
--TR Add tc
            trTest.Cells.Add(tcTest);
--TableAdd tr
            tbldynamicTest.Rows.Add(trTest);

           
            for (int i = 0; i < CountTest; i++) 
            {
               
                trTest.Height = 20;
                Label lblName = new Label();
                lblName.ID = "lblName" + i;
                lblName.Text = dsTest.Tables[0].Rows[i]["name"].ToString();
                lblName.CssClass = "lbl";
                lblName.Width = 100;
--TC Add Label
                tcTest.Controls.Add(lblName);
--TR Add tc
                trTest.Cells.Add(tcTest);
            }
--Table Rows Add 
            tbldynamicTest.Rows.Add(trTest);
--Panel Add
            pnl.Controls.Add(tbldynamicTest);
            for (int i = 0; i < CountTest; i++)
            {
                TableRow tr = new TableRow();
                TableCell tc = new TableCell();
                tr.Height = 20;
                Label lblName = new Label();
                lblName.ID = "lblName" + i;
                lblName.Text = dsTest.Tables[0].Rows[i]["name"].ToString();
                lblName.CssClass = "lbl";
                lblName.Width = 100;

                tc.Controls.Add(lblName);
                tr.Cells.Add(tc);
                for (int j = 0; j < Count; j++)
                {
--Checkbox Create
                    CheckBox chk = new CheckBox();
                    chk.ID = "chk" + j;
                    chk.Height = 25;
                    chk.CssClass = "txt";
                    chk.Width = 100;
--TC Add Checkbox
                    tc.Controls.Add(chk);
--TR Add TC 
                    tr.Cells.Add(tc);
                }
--Table Add TR
                tbldynamicTest.Rows.Add(tr);
--Panel add Table
                pnl.Controls.Add(tbldynamicTest);
            }
--Panel add Table
            pnl.Controls.Add(tbldynamicTest);
        }




grid view image using folder in asp.net

grid view image using folder in asp.net :


aspx :

 <asp:TemplateField HeaderText="Pro-Image">
     <ItemTemplate>

          <asp:Image ID="Image1"
                                --- Folder Name Set
//<%# string.Format("~/{0}",Eval("Image"))%>
                  ImageUrl='<%# string.Format("~/{0}",Eval("Image"))%>'                              Width="150px" Height="100px"   runat="server" />

     </ItemTemplate>
</asp:TemplateField>