CreateDataTableInCode\PopulateDataGrid

  • Thread starter Thread starter eg
  • Start date Start date
E

eg

Below is the code I am using to create the columns for a datagrid in
code. Once I create them I populate 1 row and return the dataview to
display the results in the grid on the ASP.Net web page, but nothing is
showing up. What am I missing?

TIA


protected void btnSW_Click(object sender, EventArgs e)
{

grdSW.DataSource = CreateData();
grdSW.DataBind();
}


public DataView CreateData()
{

DataTable lTbl = new DataTable();
lTbl.Columns.Add("FirstName", typeof(String));
lTbl.Columns.Add("LastName", typeof(String));
DataRow dr;
dr = lTbl.NewRow();
dr[0] = "Hello";
dr[1] = "Lap Top";
lTbl.Rows.Add(dr);
DataView dv = new DataView(lTbl);
return dv;


}
 
Below is the code I am using to create the columns for a datagrid in
code.  Once I create them I populate 1 row and return the dataview to
display the results in the grid on the ASP.Net web page, but nothing is
showing up.  What am I missing?

TIA

   protected void btnSW_Click(object sender, EventArgs e)
     {

         grdSW.DataSource = CreateData();
         grdSW.DataBind();
      }

    public DataView CreateData()
     {

         DataTable lTbl = new DataTable();
         lTbl.Columns.Add("FirstName", typeof(String));
         lTbl.Columns.Add("LastName", typeof(String));
         DataRow dr;
         dr = lTbl.NewRow();
         dr[0] = "Hello";
         dr[1] = "Lap Top";
         lTbl.Rows.Add(dr);
         DataView dv = new DataView(lTbl);
         return dv;

     }

What is the layout at your grid? Your code looks good to me, I think,
maybe you have AutoGenerateColumns="false" or something like this,
what blocked the output.
 
Below is the code I am using to create the columns for a datagrid in
code.  Once I create them I populate 1 row and return the dataview to
display the results in the grid on the ASP.Net web page, but nothing is
showing up.  What am I missing?

   protected void btnSW_Click(object sender, EventArgs e)
     {
         grdSW.DataSource = CreateData();
         grdSW.DataBind();
      }
    public DataView CreateData()
     {
         DataTable lTbl = new DataTable();
         lTbl.Columns.Add("FirstName", typeof(String));
         lTbl.Columns.Add("LastName", typeof(String));
         DataRow dr;
         dr = lTbl.NewRow();
         dr[0] = "Hello";
         dr[1] = "Lap Top";
         lTbl.Rows.Add(dr);
         DataView dv = new DataView(lTbl);
         return dv;
     }

What is the layout at your grid? Your code looks good to me, I think,
maybe you have AutoGenerateColumns="false" or something like this,
what blocked the output.- Hide quoted text -

- Show quoted text -

I've tested your code and it works as expected. Sure, my grid was with
AutoGenerateColumns=True
 
Back
Top