Click here to Skip to main content
15,885,979 members

how to asign the dynamic created table or panel to view state in c#

penigandlakoti asked:

Open original thread
hi,

I am koti, i am faceing the problem when "asign the table to view state".the table contains the dynamic created dropdownlist with different "ids".
i asign the table to view state crror comes as follows

asp.net
<asp:tabel ID="table1" runat="server">

codebehind
C#
if (int.TryParse(TextBox1.Text.Trim(), out numOfColumns) && int.TryParse(TextBox2.Text.Trim(), out numOfRows))
        {
            //Generate the Table based from the inputs
            GenerateTable(numOfColumns, numOfRows, "eng"); 

      viewstate["ko"]=table1;
}

private void GenerateTable(int colsCount, int rowsCount, string cat)
{
   try
   {
      //Table t = (Table)table1;
      //Page.Form.Controls.Add(table1);           
      for (int i = 0; i < rowsCount; i++)
      {
         TableRow row = new TableRow();
         for (int j = 0; j < colsCount; j++)
         {
            TableCell cell = new TableCell();
            //TextBox tb = new TextBox();
            DropDownList dl = new DropDownList();
            FileUpload ful = new FileUpload();
            // Set a unique ID for each TextBox added
            //tb.ID = "tb_" + i + "Col_" + j;
            dl.ID = cat + "dl_" + i + "Col_" + j;
            ful.ID = cat + "ful_" + i + "Col_" + j;
            
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = con;
            DataSet ds = new DataSet();
            SqlDataAdapter da = new SqlDataAdapter("select PaperName from [7Seas_News_displayT]", con);
            da.Fill(ds, "[7Seas_News_displayT]");
            con.Open();
            cmd.CommandText = "select PaperName from [7Seas_News_displayT]";
            DataTable dt = new DataTable();
            dt.Load(cmd.ExecuteReader());
            dl.DataSource = dt;
            dl.DataTextField = "PaperName";
            //dl.DataValueField = "Sno";
            dl.DataBind();
            con.Close();
            // Add the control to the TableCell
            //cell.Controls.Add(tb);
              
            table1.Controls.Add(dl);
            table1.Controls.Add(ful);
            // Add the TableCell to the TableRow
           }
           // Add the TableRow to the Table
        }
      }
      catch
      {
      }
      //Creat the Table and Add it to the Page
}

Type 'System.Web.UI.WebControls.Panel' in Assembly 'System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' is not marked as serializable

if any one knows how to solve the this problem , please share the information for me.
Thanks In Advance.

/EDIT Inline code Format
Tags: C# (C# 4.0), Visual Basic, ASP.NET

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900