Friday 13 September 2013

How to Use Multiview in asp.net

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
       <%-- <asp:MultiView ID="MultiView1" runat="server" ActiveViewIndex="0">

            <asp:View ID="View1" runat="server">
                <asp:Label ID="Label1" runat="server" BackColor="Gray" Font-Bold="true" Width="250px"  Text="View1"></asp:Label><br />
            </asp:View>
            <asp:View ID="View2" runat="server">
                <asp:Label ID="Label2" runat="server" BackColor="Gray" Font-Bold="true" Width="250px"  Text="View1"></asp:Label><br />
            </asp:View>
            <asp:View ID="View3" runat="server">
                <asp:Label ID="Label3" runat="server" BackColor="Gray" Font-Bold="true" Width="250px"  Text="View1"></asp:Label><br />
            </asp:View>

        </asp:MultiView>--%>

    <center>
    <br /><br /><br /><br /><br /><br />
<asp:MultiView ID="MultiView1" runat="server">
<table width="100%" cellpadding="2" cellspacing="5">
<tr>
<td>
<asp:View ID="View1" runat="server">
<asp:LinkButton ID="LinkButton1" runat="server" Width="150px" BackColor="Gray" OnClick="lnkTab1_Click">Tab1</asp:LinkButton><br />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
    <asp:GridView ID="GridView1" AutoGenerateColumns="false" runat="server"  >
        <Columns>
            <asp:TemplateField HeaderText="Sname">
               
                <ItemTemplate>
                     <%#Eval("Sname") %>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>
    <asp:LinkButton ID="LinkButton2" runat="server" Width="150px" BackColor="Gray" OnClick="lnkTab2_Click">Tab2</asp:LinkButton><br />
<asp:LinkButton ID="LinkButton3" runat="server" Width="150px" BackColor="Gray" OnClick="lnkTab3_Click">Tab3</asp:LinkButton>
 </asp:View>
</td>
<td>
<asp:View ID="View2" runat="server">
<asp:LinkButton ID="LinkButton4" runat="server"  Width="150px" BackColor="Gray" OnClick="lnkTab1_Click">Tab1</asp:LinkButton><br />
<asp:LinkButton ID="LinkButton5" runat="server" Width="150px" BackColor="Gray"  OnClick="lnkTab2_Click">Tab2</asp:LinkButton><br />


     <asp:TextBox ID="TextBox2"
        runat="server"></asp:TextBox><br /><asp:TextBox ID="TextBox3" runat="server"></asp:TextBox><br />
    <asp:GridView ID="GridView2" AutoGenerateColumns="false" runat="server"  >
        <Columns>
            <asp:TemplateField HeaderText="Address">
               
                <ItemTemplate>
                     <%#Eval("Address")%>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>
   <asp:LinkButton ID="LinkButton6" runat="server" Width="150px" BackColor="Gray" OnClick="lnkTab3_Click">Tab3</asp:LinkButton>
</asp:View>
</td>
<td>
<asp:View ID="View3" runat="server">

<asp:LinkButton ID="LinkButton7" runat="server" Width="150px" BackColor="Gray"   OnClick="lnkTab1_Click">Tab1</asp:LinkButton><br />
<asp:LinkButton ID="LinkButton8" runat="server" Width="150px" BackColor="Gray" OnClick="lnkTab2_Click">Tab2</asp:LinkButton><br />
<asp:LinkButton ID="LinkButton9" runat="server" Width="150px" BackColor="Gray" OnClick="lnkTab3_Click">Tab3</asp:LinkButton><br />
<br />
 <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox> <br /><asp:TextBox ID="TextBox5"
        runat="server"></asp:TextBox><br /><asp:TextBox ID="TextBox6" runat="server"></asp:TextBox><br />
       
    <asp:GridView ID="GridView3" AutoGenerateColumns="false"   runat="server"
         >
         <Columns>
            <asp:TemplateField HeaderText="Mobile
            ">
               
                <ItemTemplate>
                     <%#Eval("Mob") %>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>
    <br />
    <asp:LinkButton ID="LinkButton10" Width="150px" BackColor="Gray" ForeColor="Gray" runat="server">v</asp:LinkButton>
</asp:View>
</td>
</tr>
</table>
</asp:MultiView>

</center>  
</td>
</tr>
</table>
    </div>
    </form>
</body>
</html>

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;
using System.Configuration;
public partial class _Default : System.Web.UI.Page
{
    SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=tarun;User ID=sa;Password=123");
    SqlDataAdapter da;
    DataTable dt;
    SqlCommand cmd;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            SetDefaultView();
        }

    }
    public void showgrid()
    {
        
    }


    private void SetDefaultView()
    {
        MultiView1.ActiveViewIndex = 0;
        da = new SqlDataAdapter("select Sname from tar", con);
        dt = new DataTable();
        da.Fill(dt);
        GridView1.DataSource = dt;
        GridView1.DataBind();
    }

    protected void lnkTab1_Click(object sender, EventArgs e)
    {
        MultiView1.ActiveViewIndex = 0;

        da = new SqlDataAdapter("select Sname from tar", con);
        dt = new DataTable();
        da.Fill(dt);
        GridView1.DataSource = dt;
        GridView1.DataBind();
    }
    protected void lnkTab2_Click(object sender, EventArgs e)
    {
        MultiView1.ActiveViewIndex = 1;

        da = new SqlDataAdapter("select Address from tar", con);
        dt = new DataTable();
        da.Fill(dt);
        GridView2.DataSource = dt;
        GridView2.DataBind();
    }
    protected void lnkTab3_Click(object sender, EventArgs e)
    {
        MultiView1.ActiveViewIndex = 2;

        da = new SqlDataAdapter("select Mob from tar", con);
        dt = new DataTable();
        da.Fill(dt);
        GridView3.DataSource = dt;
        GridView3.DataBind();
    }
}




No comments:

Post a Comment