Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET C#4.0 VB.NET
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
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 21-Dec-12 23:20pm
Edited 22-Dec-12 3:35am
16.4K
v4
Comments
Sandeep Mewara at 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 at 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 at 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)

  Print Answers RSS
0 Sarvesh Kumar Gupta 228
1 CHill60 170
2 Peter Leow 165
3 Sergey Alexandrovich Kryukov 153
4 DamithSL 153


Advertise | Privacy | Mobile
Web03 | 2.8.140709.1 | Last Updated 22 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid