Link to home
Start Free TrialLog in
Avatar of Jayesh Acharya
Jayesh AcharyaFlag for United States of America

asked on

gridView C# dll

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();
        }
Avatar of WoodgerJ
WoodgerJ
Flag of Australia image

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

--> using System.Web.UI.WebControls;
Avatar of Jayesh Acharya

ASKER

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

Have you added a reference to System.Web to your class library file?
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
ASKER CERTIFIED SOLUTION
Avatar of NazoUK
NazoUK
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I needed the idiots version to help me ghet past this one ... so thanks again ....