these sample code throwed an exception :
Specified argument was out of the range of valid values.
Parameter name: value
1TabPanel tp =new TabPanel();2tp.HeaderText = tableName;3string cmdText =string.Format("SELECT * FROM {0}", tableName);4MySqlCommand cmd =new MySqlCommand(cmdText, conn);5MySqlDataReader dr = cmd.ExecuteReader();6GridView gv =new GridView();7while (dr.Read())8{9 gv.DataSource = dr;10}11gv.DataBind();12tp.ContentTemplate.InstantiateIn(gv);13tabPanels.Add(tp);
How can i add tabpanels into a tabcontainer ??
Hi Franky,
Please use tp.Controls.Add(gv) instead of tp.ContentTemplate.InstantiateIn(gv); Here is the whole sample.
Aspx
<%@. Page Language="C#" AutoEventWireup="true" CodeFile="Dynamically.aspx.cs" Inherits="Tab_Dynamically" %>
<!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>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<ajaxToolkit:TabContainer ID="TabContainer1" runat="server">
</ajaxToolkit:TabContainer>
</form>
</body>
</html>
C# code.
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using AjaxControlToolkit;
public partial class Tab_Dynamically : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
TabPanel tp = new TabPanel();
tp.HeaderText ="111";
List<string> myList = new List<string>();
myList.Add("11111");
myList.Add("22222");
myList.Add("33333");
GridView gv = new GridView();
gv.DataSource = myList;
gv.DataBind();
tp.Controls.Add(gv);
TabContainer1.Tabs.Add(tp);
TabContainer1.ActiveTabIndex = 0;
}
}
For more about InstantiateIn, please visithere.
I hope this help.
Best regards,
Jonathan
No comments:
Post a Comment