How to build Datagrid custom web control?

Discussion in 'ASP .Net Web Controls' started by reetu, Jul 12, 2003.

  1. reetu

    reetu Guest

    Hi All,

    I read about webcontrols and learnt how to display
    controls like textbox , buttons etc on the aspx page.

    I want to build a webcontrol that would display Datagrid
    when placed on the form. I couldn't find a link that would
    provide step by step detail on how to do this.

    I tried few things and now I can see the data grid control
    on the form. When I run the application the page appears
    to be blank.

    The code is as follows:

    public class TasksPage :System.Web.UI.WebControls.DataGrid
    {
    DataGrid DataGrid1 = new DataGrid();

    override protected void OnInit(EventArgs e)
    {
    // Put user code to initialize the page here
    SqlConnection connection = new SqlConnection
    ("server=(local);database=trial;Trusted_Connection=yes");

    string query = "select * from Author";
    SqlDataAdapter adapter = new SqlDataAdapter
    (query,connection);

    DataSet dset = new DataSet();

    adapter.Fill(dset,"Author");

    DataGrid1.DataSource = dset.Tables
    ["Author"].DefaultView;

    DataGrid1.DataBind();
    }
    }

    I am not sure if I am missing some keypoints.

    Sincerely,
    -Reetu
    reetu, Jul 12, 2003
    #1
    1. Advertising

  2. Hi reetu,

    You may be confusing things a little. If you just want to extend DataGrid
    functionallity then inheriting from the DataGrid class may be a good choice
    but in your sample code you're also creating another instance of a DataGrid,
    I'm not sure why you're doing this, could you add a little on what exactly
    are you trying to achieve?. Also for handling the design-time representation
    of your custom controls, specially ones with complex output, considering
    writing a custom designer (take a look a ControlDesigner class) to have more
    control over what gets rendered at design-time,

    --
    Victor Garcia Aprea
    Microsoft MVP | ASP.NET
    Looking for insights on ASP.NET? Read my blog:
    http://obies.com/vga/blog.aspx
    To contact me remove 'NOSPAM'. Please post all questions to the newsgroup
    and not by private mail.

    "reetu" <> wrote in message
    news:046601c34808$b648abe0$...
    > Hi All,
    >
    > I read about webcontrols and learnt how to display
    > controls like textbox , buttons etc on the aspx page.
    >
    > I want to build a webcontrol that would display Datagrid
    > when placed on the form. I couldn't find a link that would
    > provide step by step detail on how to do this.
    >
    > I tried few things and now I can see the data grid control
    > on the form. When I run the application the page appears
    > to be blank.
    >
    > The code is as follows:
    >
    > public class TasksPage :System.Web.UI.WebControls.DataGrid
    > {
    > DataGrid DataGrid1 = new DataGrid();
    >
    > override protected void OnInit(EventArgs e)
    > {
    > // Put user code to initialize the page here
    > SqlConnection connection = new SqlConnection
    > ("server=(local);database=trial;Trusted_Connection=yes");
    >
    > string query = "select * from Author";
    > SqlDataAdapter adapter = new SqlDataAdapter
    > (query,connection);
    >
    > DataSet dset = new DataSet();
    >
    > adapter.Fill(dset,"Author");
    >
    > DataGrid1.DataSource = dset.Tables
    > ["Author"].DefaultView;
    >
    > DataGrid1.DataBind();
    > }
    > }
    >
    > I am not sure if I am missing some keypoints.
    >
    > Sincerely,
    > -Reetu
    >
    >
    Victor Garcia Aprea [MVP], Jul 12, 2003
    #2
    1. Advertising

  3. reetu

    johny Guest

    Hi,
    I'm doing the same thing by inheriting the datagrid control
    and everything is working fine. But when I go to the HTML
    Viewer it gives error that Control Doesn't support inner
    Tags.
    Like <Columns> in the datagrid
    So my question is how to add support for Inner Tags in
    Custom Controls


    "Victor Garcia Aprea [MVP]" <> wrote in message
    news:...
    > Hi reetu,
    >
    > You may be confusing things a little. If you just want to extend DataGrid
    > functionallity then inheriting from the DataGrid class may be a good

    choice
    > but in your sample code you're also creating another instance of a

    DataGrid,
    > I'm not sure why you're doing this, could you add a little on what exactly
    > are you trying to achieve?. Also for handling the design-time

    representation
    > of your custom controls, specially ones with complex output, considering
    > writing a custom designer (take a look a ControlDesigner class) to have

    more
    > control over what gets rendered at design-time,
    >
    > --
    > Victor Garcia Aprea
    > Microsoft MVP | ASP.NET
    > Looking for insights on ASP.NET? Read my blog:
    > http://obies.com/vga/blog.aspx
    > To contact me remove 'NOSPAM'. Please post all questions to the newsgroup
    > and not by private mail.
    >
    > "reetu" <> wrote in message
    > news:046601c34808$b648abe0$...
    > > Hi All,
    > >
    > > I read about webcontrols and learnt how to display
    > > controls like textbox , buttons etc on the aspx page.
    > >
    > > I want to build a webcontrol that would display Datagrid
    > > when placed on the form. I couldn't find a link that would
    > > provide step by step detail on how to do this.
    > >
    > > I tried few things and now I can see the data grid control
    > > on the form. When I run the application the page appears
    > > to be blank.
    > >
    > > The code is as follows:
    > >
    > > public class TasksPage :System.Web.UI.WebControls.DataGrid
    > > {
    > > DataGrid DataGrid1 = new DataGrid();
    > >
    > > override protected void OnInit(EventArgs e)
    > > {
    > > // Put user code to initialize the page here
    > > SqlConnection connection = new SqlConnection
    > > ("server=(local);database=trial;Trusted_Connection=yes");
    > >
    > > string query = "select * from Author";
    > > SqlDataAdapter adapter = new SqlDataAdapter
    > > (query,connection);
    > >
    > > DataSet dset = new DataSet();
    > >
    > > adapter.Fill(dset,"Author");
    > >
    > > DataGrid1.DataSource = dset.Tables
    > > ["Author"].DefaultView;
    > >
    > > DataGrid1.DataBind();
    > > }
    > > }
    > >
    > > I am not sure if I am missing some keypoints.
    > >
    > > Sincerely,
    > > -Reetu
    > >
    > >

    >
    >
    johny, Jul 12, 2003
    #3
  4. reetu

    Reetu Guest

    Hi Victor,

    PROBLEM:

    I am trying to achieve the following functionality.

    Presently I have a grid control placed on an aspx page
    from the toolbox which has five columns and it displays
    data from the database.
    We are using some of our own APIs in the code. In many of
    the functions on that page we have to keep repeating few
    lines of code(containing our APIs) again and again.

    SOLUTION:
    So we plan to build a web custom control so that :

    1. When we drag and drop the web control from the toolbox,
    we should see the datagrid, the data from the database
    when executed.
    2. The lines of code which we keep repeating can be plaed
    in webcontrol.

    I am a bit lost on how to proceed ahead after inheriting
    the class.
    public class TasksPage :System.Web.UI.WebControls.DataGrid

    I would really appreciate if I am provided with some link
    or article that would provide some details.

    Thanks & Regards,
    -Reetu


    >-----Original Message-----
    >Hi reetu,
    >
    >You may be confusing things a little. If you just want to

    extend DataGrid
    >functionallity then inheriting from the DataGrid class

    may be a good choice
    >but in your sample code you're also creating another

    instance of a DataGrid,
    >I'm not sure why you're doing this, could you add a

    little on what exactly
    >are you trying to achieve?. Also for handling the design-

    time representation
    >of your custom controls, specially ones with complex

    output, considering
    >writing a custom designer (take a look a ControlDesigner

    class) to have more
    >control over what gets rendered at design-time,
    >
    >--
    >Victor Garcia Aprea
    >Microsoft MVP | ASP.NET
    >Looking for insights on ASP.NET? Read my blog:
    >http://obies.com/vga/blog.aspx
    >To contact me remove 'NOSPAM'. Please post all questions

    to the newsgroup
    >and not by private mail.
    >
    >"reetu" <> wrote in message
    >news:046601c34808$b648abe0$...
    >> Hi All,
    >>
    >> I read about webcontrols and learnt how to display
    >> controls like textbox , buttons etc on the aspx page.
    >>
    >> I want to build a webcontrol that would display Datagrid
    >> when placed on the form. I couldn't find a link that

    would
    >> provide step by step detail on how to do this.
    >>
    >> I tried few things and now I can see the data grid

    control
    >> on the form. When I run the application the page appears
    >> to be blank.
    >>
    >> The code is as follows:
    >>
    >> public class

    TasksPage :System.Web.UI.WebControls.DataGrid
    >> {
    >> DataGrid DataGrid1 = new DataGrid();
    >>
    >> override protected void OnInit(EventArgs e)
    >> {
    >> // Put user code to initialize the page here
    >> SqlConnection connection = new SqlConnection
    >> ("server=

    (local);database=trial;Trusted_Connection=yes");
    >>
    >> string query = "select * from Author";
    >> SqlDataAdapter adapter = new SqlDataAdapter
    >> (query,connection);
    >>
    >> DataSet dset = new DataSet();
    >>
    >> adapter.Fill(dset,"Author");
    >>
    >> DataGrid1.DataSource = dset.Tables
    >> ["Author"].DefaultView;
    >>
    >> DataGrid1.DataBind();
    >> }
    >> }
    >>
    >> I am not sure if I am missing some keypoints.
    >>
    >> Sincerely,
    >> -Reetu
    >>
    >>

    >
    >
    >.
    >
    Reetu, Jul 14, 2003
    #4
  5. reetu

    Reetu Guest

    Hello Victor,

    I just made a silly mistake. Now I can see datagrid along
    with data when executed. It works fine now.

    Thanks & Regards,
    -Reetu

    >-----Original Message-----
    >Hi Victor,
    >
    >PROBLEM:
    >
    >I am trying to achieve the following functionality.
    >
    >Presently I have a grid control placed on an aspx page
    >from the toolbox which has five columns and it displays
    >data from the database.
    >We are using some of our own APIs in the code. In many of
    >the functions on that page we have to keep repeating few
    >lines of code(containing our APIs) again and again.
    >
    >SOLUTION:
    >So we plan to build a web custom control so that :
    >
    >1. When we drag and drop the web control from the

    toolbox,
    >we should see the datagrid, the data from the database
    >when executed.
    >2. The lines of code which we keep repeating can be plaed
    >in webcontrol.
    >
    >I am a bit lost on how to proceed ahead after inheriting
    >the class.
    >public class TasksPage :System.Web.UI.WebControls.DataGrid
    >
    >I would really appreciate if I am provided with some link
    >or article that would provide some details.
    >
    >Thanks & Regards,
    >-Reetu
    >
    >
    >>-----Original Message-----
    >>Hi reetu,
    >>
    >>You may be confusing things a little. If you just want

    to
    >extend DataGrid
    >>functionallity then inheriting from the DataGrid class

    >may be a good choice
    >>but in your sample code you're also creating another

    >instance of a DataGrid,
    >>I'm not sure why you're doing this, could you add a

    >little on what exactly
    >>are you trying to achieve?. Also for handling the design-

    >time representation
    >>of your custom controls, specially ones with complex

    >output, considering
    >>writing a custom designer (take a look a ControlDesigner

    >class) to have more
    >>control over what gets rendered at design-time,
    >>
    >>--
    >>Victor Garcia Aprea
    >>Microsoft MVP | ASP.NET
    >>Looking for insights on ASP.NET? Read my blog:
    >>http://obies.com/vga/blog.aspx
    >>To contact me remove 'NOSPAM'. Please post all questions

    >to the newsgroup
    >>and not by private mail.
    >>
    >>"reetu" <> wrote in message
    >>news:046601c34808$b648abe0$...
    >>> Hi All,
    >>>
    >>> I read about webcontrols and learnt how to display
    >>> controls like textbox , buttons etc on the aspx page.
    >>>
    >>> I want to build a webcontrol that would display

    Datagrid
    >>> when placed on the form. I couldn't find a link that

    >would
    >>> provide step by step detail on how to do this.
    >>>
    >>> I tried few things and now I can see the data grid

    >control
    >>> on the form. When I run the application the page

    appears
    >>> to be blank.
    >>>
    >>> The code is as follows:
    >>>
    >>> public class

    >TasksPage :System.Web.UI.WebControls.DataGrid
    >>> {
    >>> DataGrid DataGrid1 = new DataGrid();
    >>>
    >>> override protected void OnInit(EventArgs e)
    >>> {
    >>> // Put user code to initialize the page here
    >>> SqlConnection connection = new SqlConnection
    >>> ("server=

    >(local);database=trial;Trusted_Connection=yes");
    >>>
    >>> string query = "select * from Author";
    >>> SqlDataAdapter adapter = new SqlDataAdapter
    >>> (query,connection);
    >>>
    >>> DataSet dset = new DataSet();
    >>>
    >>> adapter.Fill(dset,"Author");
    >>>
    >>> DataGrid1.DataSource = dset.Tables
    >>> ["Author"].DefaultView;
    >>>
    >>> DataGrid1.DataBind();
    >>> }
    >>> }
    >>>
    >>> I am not sure if I am missing some keypoints.
    >>>
    >>> Sincerely,
    >>> -Reetu
    >>>
    >>>

    >>
    >>
    >>.
    >>

    >.
    >
    Reetu, Jul 14, 2003
    #5
  6. Glad you could solve it! and thanks for getting back

    --
    Victor Garcia Aprea
    Microsoft MVP | ASP.NET
    Looking for insights on ASP.NET? Read my blog:
    http://obies.com/vga/blog.aspx

    To contact me remove 'NOSPAM'. Please post all questions to the newsgroup

    and not by private mail.
    "Reetu" <> wrote in message
    news:018301c34a2d$c36b51c0$...
    > Hello Victor,
    >
    > I just made a silly mistake. Now I can see datagrid along
    > with data when executed. It works fine now.
    >
    > Thanks & Regards,
    > -Reetu
    >
    > >-----Original Message-----
    > >Hi Victor,
    > >
    > >PROBLEM:
    > >
    > >I am trying to achieve the following functionality.
    > >
    > >Presently I have a grid control placed on an aspx page
    > >from the toolbox which has five columns and it displays
    > >data from the database.
    > >We are using some of our own APIs in the code. In many of
    > >the functions on that page we have to keep repeating few
    > >lines of code(containing our APIs) again and again.
    > >
    > >SOLUTION:
    > >So we plan to build a web custom control so that :
    > >
    > >1. When we drag and drop the web control from the

    > toolbox,
    > >we should see the datagrid, the data from the database
    > >when executed.
    > >2. The lines of code which we keep repeating can be plaed
    > >in webcontrol.
    > >
    > >I am a bit lost on how to proceed ahead after inheriting
    > >the class.
    > >public class TasksPage :System.Web.UI.WebControls.DataGrid
    > >
    > >I would really appreciate if I am provided with some link
    > >or article that would provide some details.
    > >
    > >Thanks & Regards,
    > >-Reetu
    > >
    > >
    > >>-----Original Message-----
    > >>Hi reetu,
    > >>
    > >>You may be confusing things a little. If you just want

    > to
    > >extend DataGrid
    > >>functionallity then inheriting from the DataGrid class

    > >may be a good choice
    > >>but in your sample code you're also creating another

    > >instance of a DataGrid,
    > >>I'm not sure why you're doing this, could you add a

    > >little on what exactly
    > >>are you trying to achieve?. Also for handling the design-

    > >time representation
    > >>of your custom controls, specially ones with complex

    > >output, considering
    > >>writing a custom designer (take a look a ControlDesigner

    > >class) to have more
    > >>control over what gets rendered at design-time,
    > >>
    > >>--
    > >>Victor Garcia Aprea
    > >>Microsoft MVP | ASP.NET
    > >>Looking for insights on ASP.NET? Read my blog:
    > >>http://obies.com/vga/blog.aspx
    > >>To contact me remove 'NOSPAM'. Please post all questions

    > >to the newsgroup
    > >>and not by private mail.
    > >>
    > >>"reetu" <> wrote in message
    > >>news:046601c34808$b648abe0$...
    > >>> Hi All,
    > >>>
    > >>> I read about webcontrols and learnt how to display
    > >>> controls like textbox , buttons etc on the aspx page.
    > >>>
    > >>> I want to build a webcontrol that would display

    > Datagrid
    > >>> when placed on the form. I couldn't find a link that

    > >would
    > >>> provide step by step detail on how to do this.
    > >>>
    > >>> I tried few things and now I can see the data grid

    > >control
    > >>> on the form. When I run the application the page

    > appears
    > >>> to be blank.
    > >>>
    > >>> The code is as follows:
    > >>>
    > >>> public class

    > >TasksPage :System.Web.UI.WebControls.DataGrid
    > >>> {
    > >>> DataGrid DataGrid1 = new DataGrid();
    > >>>
    > >>> override protected void OnInit(EventArgs e)
    > >>> {
    > >>> // Put user code to initialize the page here
    > >>> SqlConnection connection = new SqlConnection
    > >>> ("server=

    > >(local);database=trial;Trusted_Connection=yes");
    > >>>
    > >>> string query = "select * from Author";
    > >>> SqlDataAdapter adapter = new SqlDataAdapter
    > >>> (query,connection);
    > >>>
    > >>> DataSet dset = new DataSet();
    > >>>
    > >>> adapter.Fill(dset,"Author");
    > >>>
    > >>> DataGrid1.DataSource = dset.Tables
    > >>> ["Author"].DefaultView;
    > >>>
    > >>> DataGrid1.DataBind();
    > >>> }
    > >>> }
    > >>>
    > >>> I am not sure if I am missing some keypoints.
    > >>>
    > >>> Sincerely,
    > >>> -Reetu
    > >>>
    > >>>
    > >>
    > >>
    > >>.
    > >>

    > >.
    > >
    Victor Garcia Aprea [MVP], Jul 15, 2003
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Dalberg
    Replies:
    1
    Views:
    366
    Greg9Strat
    Mar 9, 2007
  2. =?Utf-8?B?cGF0cmlja2RyZA==?=

    datagrid custom (dynamic) pager build at runtime?

    =?Utf-8?B?cGF0cmlja2RyZA==?=, May 6, 2007, in forum: ASP .Net
    Replies:
    1
    Views:
    330
    MasterGaurav \(www.edujini-labs.com\)
    May 6, 2007
  3. Matt Sokol
    Replies:
    2
    Views:
    375
    Theo Tillotson
    Aug 7, 2003
  4. Sumana

    How do we build a custom control using datagrid from scratch?

    Sumana, Jan 22, 2004, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    164
    James Alexander
    Jan 22, 2004
  5. Dexter

    Problem with Build Custom Web Control

    Dexter, Nov 26, 2004, in forum: ASP .Net Building Controls
    Replies:
    4
    Views:
    108
    Naveen K Kohli
    Nov 28, 2004
Loading...

Share This Page