gridView C# dll

Jayesh Acharya
Jayesh Acharya used Ask the Experts™
on
I want to put the following code into a DLL that I create, the the DLL does nto recognize the GridView type.

in my .cs file the procedure is fine because I can always add the following line:

protected global::System.Web.UI.WebControls.GridView GridView1;

but the is nto recognized and I dont knwo how to make it so ... I am sure there must be a way to find and attached the System.Web.UI.WebControls.GridView dll some how to the dll i create. Below is the code I am trying to place in my own DLL

        public void BindDataTableToGridView
            (GridView lv_GridView
            ,DataTable lv_DataTable)
        {
            //bind the data to the grid
            lv_GridView.DataSource = lv_DataTable.DefaultView;
            lv_GridView.DataBind();
        }
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
You may need to import the namespace which contains the GridView at the very beginning of your class file:

--> using System.Web.UI.WebControls;
Jayesh AcharyaTechnichal Consultant

Author

Commented:
the
 using System.Web.UI.WebControls;

is not recgonzied when I try to create the dll, but its fine when I use it in a  normal project. the .UI is the part that the DLL does not like. Remember I am trying to create my own DLL. I am using Visual Studio 2008 so I dont know if that makes a difference.

But when i add the using System.Web.UI.WebControls; in a aspx.cs file its fine, but when I create a class it does not like it....

Commented:
Have you added a reference to System.Web to your class library file?
Jayesh AcharyaTechnichal Consultant

Author

Commented:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Xml.Linq;
using System.Data.OracleClient;
using System.Text;
using System.Web.DynamicData.Design;



namespace testdll
{
    public class MAC
    {
        public MAC()
        {
        }

        public void BindDataTableToGridView
            (GridView lv_GridView
            , DataTable lv_DataTable)
        {
            //bind the data to the grid
            lv_GridView.DataSource = lv_DataTable.DefaultView;
            lv_GridView.DataBind();
        }

        public void BuildGridViewStructure
               (Dictionary<string, string> lv_AllGridCols
               , Dictionary<string, bool> lv_ShowHideGridViewColDictionary
               , System.Web.UI.WebControls.GridView lv_GridView)
        {

            lv_GridView.AutoGenerateColumns = false;
            // this is columns
            System.Web.UI.WebControls.BoundField nameColumn;

            //build the datagrid columns programatically
            //and populate the data
            foreach (KeyValuePair<string, string> AllGridPair in lv_AllGridCols)
            {
                nameColumn = new BoundField();
                nameColumn.DataField = AllGridPair.Key;
                nameColumn.HeaderText = AllGridPair.Key;
                nameColumn.Visible = lv_ShowHideGridViewColDictionary[AllGridPair.Key];
                lv_GridView.Columns.Add(nameColumn);
            }
        }
   
    }
}

these are the error I get

--BindDataTableToGridView  does not like the GridView
The type or namespace name 'GridView' could not be found (are you missing a using directive or an assembly reference?)      

--BuildGridViewStructure does not like the bound field option
The type or namespace name 'UI' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)

This codes works in my aspx.cs file since I can access the  System.Web.UI.WebControls, but this for some reason is not availble to me when trying to create DLL
Commented:
So have you added a reference to system.web?

Right click your project file, choose add reference then in the .net tab choose System.Web.

You should then be able to import the System.Web.UI.WebControls namespace
Jayesh AcharyaTechnichal Consultant

Author

Commented:
I needed the idiots version to help me ghet past this one ... so thanks again ....

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial