Click here to Skip to main content
15,889,034 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Updated 22-Dec-12 3:35am
v4
Comments
Sandeep Mewara 22-Dec-12 5:31am    
Not clear. Elaborate. Further, share the lines of code around which you get this. BTW, make sure that the .NET framework set across project and deployment are same.
db7uk 22-Dec-12 19:43pm    
I would avoid using viewstate for data tables. Use session instead. Also agree with Sandeep. Question is not too clear.
thursunamy 24-Dec-12 15:31pm    
If that table is datatable it is not serializable you can use Dataset. But I agree with db7uk. It is not a good solution to store a table in viewstate. It reduces the performance Session is better.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



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