Ajax tabContainer using GridView inside panel, one button outside of the tabContainer

I’m creating Admin Panel using Ajax tab container which has 5 tapPanels and in that each tapPanel, I have one Panel from standard tool. And in that each Panel, I have GridView to show added data. And finally, I have one Add button outside of the Ajax tabContainer. I’ll post the design if it allows. The problem is, I don’t know the coding for tabContainer. I’ve created 10 methods so I can call it when Add button clicks.

Here is my code which is not working.

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(@"styleimgno-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()
        {           
        }        
    }
}

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Please use the following code:

        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";
        }


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x