How to build Datagrid custom web control?

R

reetu

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
 
V

Victor Garcia Aprea [MVP]

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

johny

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 said:
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 said:
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
 
R

Reetu

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 said:
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


.
 
R

Reetu

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 said:
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


.
.
 
V

Victor Garcia Aprea [MVP]

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

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




.
.
 

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

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top