Click here to Skip to main content
15,912,329 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Page load code as follows

C#
PkgDates.Columns.Add("Cmn_minor_code", typeof(string));
            PkgDates.Columns.Add("BatchID", typeof(string));
            PkgDates.Columns.Add("Disp_Course", typeof(string));
            PkgDates.Columns.Add("Start_date", typeof(DateTime));
            PkgDates.Columns.Add("End_date", typeof(DateTime));
            PkgRows = PkgDates.NewRow();

            if (this.DdlPKGCode.Text != "")
            {
                return;
            }
            ViewState["table"] = PkgDates;



I have one submit button.Submit button code as follows

C#
PkgRows = PkgDates.NewRow();
       PkgRows["Cmn_minor_code"] = this.DDLPKGMinorCode.Text.ToString().TrimEnd();
       PkgRows["BatchID"] = this.LstPKGCrsDate.SelectedValue.ToString().TrimEnd();

      PkgRows["Start_date"] = Dt_Batches.Rows[LstPKGCrsDate.SelectedIndex][2];
      PkgRows["End_date"] = Dt_Batches.Rows[LstPKGCrsDate.SelectedIndex][3];
  PkgRows["Disp_Course"] = this.DDLPKGMinorCode.Text.ToString() + " - " + StrDate;

       this.PkgDates.Rows.Add(PkgRows);
       ViewState["table"] = PkgDates;

       ViewState["AdCrsCount"] = PkgDates.Rows.Count;


When i run and click the submit button shows error as follows

C#
Column 'BatchID' does not belong to table Table1.


please help me from my above what is the mistake i made.
Posted
Updated 23-Sep-14 2:59am
v2
Comments
Ajith K Gatty 23-Sep-14 9:13am    
Hi,
in your program this.DDLPKGMinorCode.Text it self is a string and there is no need to add .ToString() method to it.
Check that once.
[no name] 23-Sep-14 9:50am    
If that's in Ispostback event then it's wrong
Put it out side ispostback I mean write direct code inside of pageloade event

1 solution

Please try adding below line to commit your column addding after adding all column to all your datatable.


C#
PkgDates.AcceptChanges();
 
Share this answer
 

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