<asp:TabContainer ID="TabPanel" runat="server" Width="400px" Height="200px"> <asp:TabPanel ID="pane1" runat="server"> <HeaderTemplate> Tab 1 </HeaderTemplate> <ContentTemplate> <asp:GridView ID="GridView1" runat="server"> </asp:GridView> </ContentTemplate> </asp:TabPanel> <asp:TabPanel ID="pane2" runat="server"> <HeaderTemplate> Tab 2 </HeaderTemplate> <ContentTemplate> <asp:GridView ID="GridView2" runat="server"> </asp:GridView> </ContentTemplate> </asp:TabPanel> <asp:TabPanel ID="pane3" runat="server"> <HeaderTemplate> Tab 3 </HeaderTemplate> <ContentTemplate> <asp:GridView ID="GridView3" runat="server"> </asp:GridView> </ContentTemplate> </asp:TabPanel> </asp:TabContainer>
public partial class _Default : System.Web.UI.Page { SqlConnection sqlcon = new SqlConnection(ConfigurationManager.ConnectionStrings["Test"].ConnectionString); SqlCommand sqlcom; SqlDataAdapter sqladp; DataTable dt; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { BindGrid1(); BindGrid2(); BindGrid3(); } } void BindGrid1() { using(sqlcom = new SqlCommand("SELECT * FROM [DBO].[NAME]",sqlcon)) { sqladp = new SqlDataAdapter(sqlcom); dt = new DataTable(); sqladp.Fill(dt); if (dt.Rows.Count > 0) { GridView1.DataSource = dt; GridView1.DataBind(); } else { Response.Write("Data Not Found"); } } } void BindGrid2() { using (sqlcom = new SqlCommand("SELECT * FROM [DBO].[NAME2]", sqlcon)) { sqladp = new SqlDataAdapter(sqlcom); dt = new DataTable(); sqladp.Fill(dt); if (dt.Rows.Count > 0) { GridView2.DataSource = dt; GridView2.DataBind(); } else { Response.Write("Data Not Found"); } } } void BindGrid3() { using (sqlcom = new SqlCommand("SELECT * FROM [DBO].[NAME3]", sqlcon)) { sqladp = new SqlDataAdapter(sqlcom); dt = new DataTable(); sqladp.Fill(dt); if (dt.Rows.Count > 0) { GridView3.DataSource = dt; GridView3.DataBind(); } else { Response.Write("Data Not Found"); } } } }
Source : http://forums.asp.net/t/1779331.aspx?Using+grid+view+in+tab+container+of+ajax+in+Asp+net
No comments:
Post a Comment