Manath Pathana

Manath Pathana

  • NA
  • 129
  • 0

Error Button with Tabpanel of Ajax Toolkit

Nov 23 2009 4:29 AM
Hi Everyone,

I have one problem that can not resolve.
I have code design below:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebFormTest2.aspx.cs" Inherits="PerfexBankSystem.WebFormTest2" %>

<!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>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
       
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
       
            <ajaxToolkit:TabContainer ID="TabContainer1" runat="server" Height="191px" Width="1070px">
                <ajaxToolkit:TabPanel ID="TabPanel1" runat="server" HeaderText="TabPanel1">
                </ajaxToolkit:TabPanel>
            </ajaxToolkit:TabContainer> 
           

                <asp:Button ID="btnAddNew" runat="server" Text="AddNew" Width="80" OnClick="btnAddNew_Click"/>
                <asp:Button ID="btnUpdate" runat="server" Text="Update" Width="80"/>
                <asp:Button ID="btnDelete" runat="server" Text="Delete" Width="80"/>
              
        </ContentTemplate>
    </asp:UpdatePanel>
    </form>
</body>
</html>


That:

ajaxToolkit:TabContainer and  ajaxToolkit:TabPanel that ajaxToolkit:TabPanel in ajaxToolkit:TabContainer. I use ajaxToolkit:TabContainer is dynamic that we get data from some table in database. Ex: if we have table 5, we will have
TabPanel 5. If we have table 6, we will have TabPanel 6. Tthat each table have dynamic control(TextBox, Dropdownlist, RadioButtonList)
and I can get data show on each TabPanel already. But it have problem when i add some button for make action, It have show error
below:


Line: 4723
Error: Sys.WebForms.PageRequestManagerServerErrorException: Specified argument was out of the range of valid values.
Parameter name: index



Please see code behide:

  public void LoadTab()
        {
            SqlConnection Cnn = new clssDBConnection().dbConnection();

            string str =  " Select a.EDIID,a.FieldType,b.Value,b.Description,a.FieldName,a.FieldCaption,c.ObjectName, c.ObjectType, a.Available " +
                          " From Tbl_EmployeeDependencyInformation a, tbl_EmployeeDependencyObject b, tbl_customerFieldObject c " +
                          " Where a.EDOID=b.EDOID and a.ObjectHandler=c.ObjectID and Available=1";

            cmd = new SqlCommand(str, Cnn);
            cmd.ExecuteNonQuery();
            SqlDataReader dr = cmd.ExecuteReader();

            textbox = new TextBox();
            String strTab = "";
            AjaxControlToolkit.TabPanel tab = new AjaxControlToolkit.TabPanel();

            TextBox tbx = new TextBox();
            DropDownList drp = new DropDownList();
            RadioButtonList rdo = new RadioButtonList();
            Label lb = new Label();
            Table tbl = new Table();
            TableRow tRow = new TableRow();
            TableCell tCell = new TableCell();         
                     
            while (dr.Read())
            {
                tCell = new TableCell();
                tRow = new TableRow();

                tbl = new Table();
                tbl.ID = dr["Value"].ToString();
                tab.Controls.Add(tbl);

                //tbl.BorderWidth = System.Web.UI.WebControls.Unit.Pixel(3);


                tCell.Controls.Add(new LiteralControl("</td><td align='right' Width='200'>" + dr["FieldCaption"].ToString() + "</td><td>"));
                tRow.Cells.Add(tCell);

               

                if (!strTab.Equals(dr["Value"].ToString()))
                {
                    strTab = dr["Value"].ToString();
                    tab = new AjaxControlToolkit.TabPanel();
                    tab.ID = "tab" + dr["Value"].ToString();
                   
                    tab.HeaderText = dr["Description"].ToString();


                    if (dr["ObjectType"].ToString().Equals("TextBox"))
                    {
                        lb = new Label();
                        lb.Text = dr["FieldCaption"].ToString();
                        tbx = new TextBox();

                        tbx.ID = "txt" + dr["FieldName"].ToString();
                        tCell.Controls.Add(tbx);
                        //tab.Controls.Add(lb);
                       // tab.Controls.Add(tbx);
                    }

                    if (dr["ObjectType"].ToString().Equals("DropdownList"))
                    {
                        lb = new Label();
                        lb.Text = dr["FieldCaption"].ToString();
                        drp = new DropDownList();
                        drp.ID = "drp" + dr["FieldName"].ToString();

                        string sql = " Select EDF.Value, EDF.EDIFieldValueID " +
                                     " from tbl_EmployeeDependencyfieldvalue EDF, Tbl_EmployeeDependencyInformation EDI" +
                                     " where EDF.EDIID = EDI.EDIID " +
                                     " and EDF.EDIID ='" + dr["EDIID"].ToString() + "'";

                        DAdapter = new SqlDataAdapter(sql, Cnn1);
                        DataTable dtable = new DataTable();
                        DAdapter.Fill(dtable);

                        drp.DataTextField = "Value";
                        drp.DataValueField = "EDIFieldValueID";
                        drp.DataSource = dtable;
                        drp.DataBind();

                        drp.Width = System.Web.UI.WebControls.Unit.Pixel(285);
                        tCell.Controls.Add(drp);
                        //tab.Controls.Add(lb);
                       // tab.Controls.Add(drp);
                    }


                    if (dr["ObjectType"].ToString().Equals("RadioButtonList"))
                    {
                        lb = new Label();
                        lb.Text = dr["FieldCaption"].ToString();
                        rdo = new RadioButtonList();
                        rdo.ID = "rdo" + dr["FieldName"].ToString();

                        string sql = " Select EDF.Value, EDF.EDIFieldValueID " +
                                     " from tbl_EmployeeDependencyfieldvalue EDF, Tbl_EmployeeDependencyInformation EDI" +
                                     " where EDF.EDIID = EDI.EDIID " +
                                     " and EDI.EDIID ='" + dr["EDIID"].ToString() + "'";

                        DAdapter = new SqlDataAdapter(sql, Cnn1);
                        DataTable dtable = new DataTable();
                        DAdapter.Fill(dtable);

                        rdo.DataTextField = "Value";
                        rdo.DataValueField = "EDIFieldValueID";
                        rdo.DataSource = dtable;
                        rdo.SelectedIndex = 0;
                        rdo.DataBind();

                        tCell.Controls.Add(rdo);
                        //tab.Controls.Add(lb);
                        //tab.Controls.Add(rdo);
                      
                    }
                    tbl.Rows.Add(tRow);
                    TabContainer1.Tabs.Add(tab);

                }
               
                else
                {
                    if (dr["ObjectType"].ToString().Equals("TextBox"))
                    {
                        lb = new Label();
                        lb.Text = dr["FieldCaption"].ToString();
                        tbx = new TextBox();
                        tbx.ID = "txt" + dr["FieldName"].ToString();
                        tCell.Controls.Add(tbx);
                        //tab.Controls.Add(lb);
                       // tab.Controls.Add(tbx);
                       
                    }

                    if (dr["ObjectType"].ToString().Equals("DropdownList"))
                    {
                        lb = new Label();
                        lb.Text = dr["FieldCaption"].ToString();
                        drp = new DropDownList();

                        string sql = " Select EDF.Value, EDF.EDIFieldValueID " +
                                     " from tbl_EmployeeDependencyfieldvalue EDF, Tbl_EmployeeDependencyInformation EDI" +
                                     " where EDF.EDIID = EDI.EDIID " +
                                     " and EDF.EDIID ='" + dr["EDIID"].ToString() + "'";


                        DAdapter = new SqlDataAdapter(sql, Cnn1);
                        DataTable dtable = new DataTable();
                        DAdapter.Fill(dtable);

                        drp.DataTextField = "Value";
                        drp.DataValueField = "EDIFieldValueID";
                        drp.DataSource = dtable;
                        drp.DataBind();
                        drp.ID = "drl" + dr["FieldName"].ToString();
                        drp.Width = System.Web.UI.WebControls.Unit.Pixel(285);
                       // tab.Controls.Add(lb);
                        //tab.Controls.Add(drp);
                        tCell.Controls.Add(drp);
                    }


                    if (dr["ObjectType"].ToString().Equals("RadioButtonList"))
                    {
                        lb = new Label();
                        lb.Text = dr["FieldCaption"].ToString();
                        rdo = new RadioButtonList();
                        rdo.ID = "rdo" + dr["FieldName"].ToString();

                        string sql = " Select EDF.Value, EDF.EDIFieldValueID " +
                                     " from tbl_EmployeeDependencyfieldvalue EDF, Tbl_EmployeeDependencyInformation EDI" +
                                     " where EDF.EDIID = EDI.EDIID " +
                                     " and EDI.EDIID ='" + dr["EDIID"].ToString() + "'";

                        DAdapter = new SqlDataAdapter(sql, Cnn1);
                        DataTable dtable = new DataTable();
                        DAdapter.Fill(dtable);

                        rdo.DataTextField = "Value";
                        rdo.DataValueField = "EDIFieldValueID";
                        rdo.DataSource = dtable;
                        rdo.SelectedIndex = 0;
                        rdo.DataBind();
                       // tab.Controls.Add(lb);
                       // tab.Controls.Add(rdo);
                        tCell.Controls.Add(rdo);
                    }
                }
                tbl.Rows.Add(tRow);

               

            }
            dr.Close();
            TabContainer1.Tabs.RemoveAt(0);
        }

I think this error of couse this sub procedure. Becuse I close this sub procedure and click button, It not show error.

Whis you can help me.

Thank Advance

Answers (7)