Sunday 21 February 2016

How to use Gridview Inside Another Controls using Asp.Net C#

 Gridview Inside Another Controls


Gridview inside access another controls like  Calender,Imagebutton,Gridview,Linkbutton Using in Asp.Net C#.

                                  DEMO

          
                             Download

                       HTML CODING

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>How to use Gridview Inside Another Control</title>
</head>
<body>
    <form id="form1" runat="server">
    <div align="center">
        <h4>Girdview Inside Button,Gridview,Linkbutton,
            ImageButton,Calender
        </h4>
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" OnRowDataBound="GridView1_RowDataBound">
            <AlternatingRowStyle ForeColor="#999966" />
            <Columns>
                <asp:TemplateField HeaderText="Employee Name">
                    <ItemTemplate>
                        <table><tr><td>
                            <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
                            </td><td>
                                <asp:Label ID="Label1" runat="server" Text='<%# Eval("Empname"%>'></asp:Label>
                            </td></tr>
                            <tr><td>
                                <asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click">LinkButton</asp:LinkButton>
                                </td><td>
                                    <asp:ImageButton ID="ImageButton1" runat="server" Height="50px" ImageUrl="~/Penguins.jpg" OnClick="ImageButton1_Click" Width="50px" />
                                </td></tr>
                            <tr><td>
                                <h4>Child Gridview</h4>
                                <asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False">
                                    <Columns>
                                        <asp:TemplateField HeaderText="Empname">
                                            <ItemTemplate>
                                                <asp:Label ID="Label2" runat="server" Text='<%# Eval("Empname"%>'></asp:Label>
                                                <br />
                                                <br />
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                    </Columns>
                                </asp:GridView>
                                </td><td>
                                    <asp:Calendar ID="Calendar1" runat="server" OnSelectionChanged="Calendar1_SelectionChanged"></asp:Calendar>
                                </td></tr>
                            <tr><td></td><td></td></tr>
                        </table>
                        &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="Id" HeaderText="Employee Id">
                <ControlStyle Font-Size="Larger" />
                <ItemStyle HorizontalAlign="Center" />
                </asp:BoundField>
            </Columns>
            <HeaderStyle ForeColor="#3399FF" />
            <RowStyle ForeColor="Gray" />
        </asp:GridView>
    </div>
    </form>
</body>
</html>

 C# CODING

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;
public partial class GridviewEvents : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        SqlConnection con=new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["dbcon"].ToString() );
        con.Open();
        SqlDataAdapter adp=new SqlDataAdapter ("select * from Employee",con);
        DataSet ds = new DataSet();
        adp.Fill(ds);
        GridView1.DataSource = ds;
        GridView1.DataBind();
        con.Close();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        // Button inside of Griview
        Button btn = (Button)sender;
        GridViewRow gr = (GridViewRow)btn.NamingContainer;
        Label lbl = (Label)gr.FindControl("Label1");
        ScriptManager.RegisterStartupScript(this,this.GetType(),"Script","alert('"+lbl.Text+"')",true);
    }
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        // LinkButton inside of Griview
        LinkButton lbt = (LinkButton)sender;
        GridViewRow gr = (GridViewRow)lbt.NamingContainer;
        Label lbl = (Label)gr.FindControl("Label1");
        ScriptManager.RegisterStartupScript(thisthis.GetType(), "Script1""alert('" + lbl.Text + "')"true);
       
    }  
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        // GridView Inside of Another Gridview
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            GridView grChild = e.Row.FindControl("GridView2"as GridView;
            SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["dbcon"].ToString());
            con.Open();
            SqlDataAdapter adp = new SqlDataAdapter("select * from Employee", con);
            DataSet ds = new DataSet();
            adp.Fill(ds);
            grChild.DataSource = ds;
            grChild.DataBind();       
       
        }
    }

    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        ImageButton lbt = (ImageButton)sender;
        GridViewRow gr = (GridViewRow)lbt.NamingContainer;
        Label lbl = (Label)gr.FindControl("Label1");
        ScriptManager.RegisterStartupScript(thisthis.GetType(), "Script12""alert('" + lbl.Text + "')"true);
       
    }
    protected void Calendar1_SelectionChanged(object sender, EventArgs e)
    {
        Calendar cal = (Calendar)sender;
        GridViewRow gr = (GridViewRow)cal.NamingContainer;
        Calendar cal1 = (Calendar)gr.FindControl("Calendar1");
        ScriptManager.RegisterStartupScript(thisthis.GetType(), "Script12""alert('" +"Selected Date is = " + cal1.SelectedDate.ToString("dd/MM/yyyy") + "')"true);
    }

}
                    















       

Panel hide and show particular interval time using Javascript in Asp.Net C#

No comments    
categories: , , ,
Panel hide and show particular interval 

time using Javascript

Using Javascript particular interval Panel Control hide and show in Asp.net c#.

                    DEMO

       
                              

                        HTML CODING

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Panel hide and show particular interval time using Javascript in Asp.Net C#</title>
    <script type="text/javascript">

        function ShowPanel()
        {
            document.getElementById('<%=Panel1.ClientID%>').style.display = "none";
        }
        setTimeout("ShowPanel();", 2000);

    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div align="center">
        <asp:Panel ID="Panel1" Visible="false" runat="server" >
            <asp:Label ID="Label5" runat="server" Text="Register Successfully" Font-Size="XX-Large" ForeColor="#FF3300"></asp:Label>
        </asp:Panel>
            <table class="table">

           <tr><td align="center">
             <asp:Label ID="Label4" runat="server" Font-Overline="False" Font-Size="Medium" Text="Name"></asp:Label>
             </td><td>
                 <asp:TextBox ID="txtName" placeholder="Full Name" runat="server" Font-Overline="False" Font-Size="Medium"></asp:TextBox>
             </td></tr>
         <tr><td align="center">
             <asp:Label ID="Label3"  Font-Size="Medium"  runat="server" Text="Email Id"></asp:Label>
             </td><td><asp:TextBox ID="txtEmail"  Font-Size="Medium"  runat="server"></asp:TextBox>
                 <br />
             </td></tr>
                <br />
      <tr>
      <td colspan="2">
       
       &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
       
       <asp:Button ID="Btn_Register" runat="server"  Font-Size="Medium"  Text="Register"
              onclick="Btn_Register_Click"/>
         
      </tr>
     </table>
    </div>
    </form>
</body>
</html>


                  C# CODING

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

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

    }
    protected void Btn_Register_Click(object sender, EventArgs e)
    {
        Panel1.Visible = true;      
        System.Web.UI.ScriptManager.RegisterClientScriptBlock(Page, typeof(Page), "Script"" ShowPanel();"true);

    }

}