Click here to Skip to main content
15,917,964 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
protected void Page_Load(object sender, EventArgs e)
  {

      if(!IsPostBack)
      {

   var da=objlinq.Facs.ToList();
   DataTable dt = new DataTable();
   dt.Tables.Add[da];
   dt.Columns.Add("Did");
   lblDid.Text = Request.QueryString["Did"].ToString();


   if (lblDid.Text == ds.Tables[0].Rows[0]["Did"])
   {

       GridView1.DataSource = da;
       GridView1.DataBind();
   }


What I have tried:

protected void Page_Load(object sender, EventArgs e)
{

if(!IsPostBack)
{

var da=objlinq.Facs.ToList();
DataTable dt = new DataTable();
dt.Tables.Add[da];
dt.Columns.Add("Did");
lblDid.Text = Request.QueryString["Did"].ToString();


if (lblDid.Text == ds.Tables[0].Rows[0]["Did"])
{

GridView1.DataSource = da;
GridView1.DataBind();
}
Posted
Updated 22-Feb-16 22:48pm
Comments
Member 12306844 23-Feb-16 4:22am    
i have two tables department(Did,Dname,Hod) Fac(Did,Fid,Fname,Subjects),
i have bind departments in the gridview. if i select the one department record i need to bind fac data in the other page in the gridview....based on the Did
Kornfeld Eliyahu Peter 23-Feb-16 4:30am    
1. You are using the outcome of ToList(); as index for an array!!!
2. No Tables property for DataTable

1 solution

Um. That code looks like you are guessing and hoping here:
1) dt is a DataTable, so it doesn't have a Tables property. That's for DataSets instead.
2) Whatever objling.Facs returns, I'm pretty sure it won;t involve a collection of DataTables - so da will be a List of whatever those objects are.
3) Add is a method, not an array, so you need round brackets instead of square ones.
4) Add adds a single item to a collection, AddRange is used to add collections of items to a different collection.

Exactly what you are trying to do here I'm not sure - there are too many conflicting mistakes to be sure - so I'd suggest you take a step back, think about what you are trying to achieve and and start again from the beginning! :laugh:
 
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