CreateDataTableInCode\PopulateDataGrid


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;


}
 
Ad

Advertisements

A

Alexey Smirnov

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.
 
Ad

Advertisements

A

Alexey Smirnov

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top