我正在使用Ajax标签容器创建管理面板,该容器有5个tapPanel,每个tapPanel,我有一个标准工具面板。在每个Panel中,我都有GridView来显示添加的数据。最后,我在Ajax tabContainer之外有一个Add按钮。如果允许,我会发布设计。问题是,我不知道tabContainer的编码。我创建了10个方法,所以我可以在添加按钮单击时调用它。
这是我的代码无效。
namespace Admin_Panel
{
public partial class add : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Session["Page"] = "ADD";
}
protected void btnAddCat_Click(object sender, EventArgs e)
{
AjaxControlToolkit.TabContainer container = (AjaxControlToolkit.TabContainer)TabConAddInfo;
AjaxControlToolkit.TabPanel tcTabPanel = new AjaxControlToolkit.TabPanel();
if (tcTabPanel.HeaderText == "Splash")
{
addSplash();
lblMsgAdd.Text = "Added successfully";
}
else if (tcTabPanel.HeaderText == "Main Category")
{
addMainCat();
lblMsgAdd.Text = "Added successfully";
}
else if (tcTabPanel.HeaderText == "Sub Category")
{
addSubCat();
lblMsgAdd.Text = "Added successfully";
}
else if (tcTabPanel.HeaderText == "Business Contact")
{
addBusinessContact();
lblMsgAdd.Text = "Added successfully";
}
else if (tcTabPanel.HeaderText == "Person Contact")
{
addPersonContact();
lblMsgAdd.Text = "Added successfully";
}
}
Int32 fileLength = 0;
string connStr = WebConfigurationManager.ConnectionStrings["connection"].ConnectionString;
private void addSplash()
{
HttpPostedFile uploadFile = FileLogo.PostedFile;
fileLength = uploadFile.ContentLength;
if (fileLength == 0)
{
string filePath = Server.MapPath(@"\style\img\no-photo-icon.jpg");
string fileName = Path.GetFileName(filePath);
FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read);
fileLength = (Int32)fs.Length;
Byte[] fileByteArr = new Byte[fileLength];
fs.Read(fileByteArr, 0, fileLength);
SqlConnection conn = new SqlConnection(connStr);
SqlCommand cmd = new SqlCommand("insert into SPLASH (VersionNumber, SplashLabel,LoginID) values (@VersionNumber,@SplashLabel,@LoginID)", conn);
cmd.Parameters.AddWithValue("@VersionNumber", txtVnum.Value);
cmd.Parameters.AddWithValue("@SplashLabel", txtSpLabel.Value);
cmd.Parameters.AddWithValue("@LoginID", txtYourID.Value);
cmd.Parameters.AddWithValue("@ImageData", fileByteArr);
cmd.Parameters.AddWithValue("@ImageContentType", "image/jpg");
cmd.Parameters.AddWithValue("@ImageSize", fileLength);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
conn.Dispose();
cmd.Dispose();
}
else
{
Byte[] fileByteArray = new Byte[fileLength];
Stream streamObject = uploadFile.InputStream;
streamObject.Read(fileByteArray, 0, fileLength);
SqlConnection conn = new SqlConnection(connStr);
SqlCommand cmd = new SqlCommand("insert into SPLASH (VersionNumber, SplashLabel,LoginID) values (@VersionNumber,@SplashLabel,@LoginID)", conn);
cmd.Parameters.AddWithValue("@VersionNumber", txtVnum.Value);
cmd.Parameters.AddWithValue("@SplashLabel", txtSpLabel.Value);
cmd.Parameters.AddWithValue("@LoginID", txtYourID.Value);
cmd.Parameters.AddWithValue("@ImageData", fileByteArray);
cmd.Parameters.AddWithValue("@ImageContentType", "image/jpg");
cmd.Parameters.AddWithValue("@ImageSize", fileLength);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
conn.Dispose();
cmd.Dispose();
}
}
private void showSplash()
{
SqlConnection conn = new SqlConnection(connStr);
SqlCommand cmd = new SqlCommand("select * from SPLASH", conn);
conn.Open();
SqlDataReader rdr = cmd.ExecuteReader();
System.Data.DataTable dt = new System.Data.DataTable();
dt.Load(rdr);
GridViewAddSplash.DataSource = dt;
GridViewAddSplash.DataBind();
conn.Close();
conn.Dispose();
cmd.Dispose();
}
private void addMainCat()
{
}
private void showMainCat()
{
}
private void addSubCat()
{
}
private void showSubCat()
{
}
private void addBusinessContact()
{
}
private void showBusinessContact()
{
}
private void addPersonContact()
{
}
private void showPersonContact()
{
}
}
}
答案 0 :(得分:0)
请使用以下代码:
AjaxControlToolkit.TabContainer container = (AjaxControlToolkit.TabContainer)TabConAddInfo;
int index = container.ActiveTabIndex;
if (index == 0)
{
addSplash();
lblMsgAdd.Text = "Added successfully";
}
else if (index == 1)
{
addMainCat();
lblMsgAdd.Text = "Added successfully";
}
else if (index == 2)
{
addSubCat();
lblMsgAdd.Text = "Added successfully";
}
else if (index == 3)
{
addBusinessContact();
lblMsgAdd.Text = "Added successfully";
}
else if (index == 4)
{
addPersonContact();
lblMsgAdd.Text = "Added successfully";
}