473,396 Members | 2,081 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Adding a button to a datagrid


I think I must be going crazy. All I want to do is add a button to the
bottom of a datagrid which will later run some code for a web based
project. I've created a custom control that inherits from the datagrid
and have added just a single line of code thus;

protected override void Render(HtmlTextWriter output)
{

output.Write(new System.Web.UI.WebControls.Button());

base.Render(output);
}
All looks fine at design time but at runtime I'm getting a cast
exception - what am I missing? Many thanks if you can point out where
I'm going wrong.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #1
4 1722
Hi,

You don't need to inherit from datagrid for just adding a button to it.

You can just add a button column or a temlate column from all the templates
supported by datagrid.
Hope this helps.

Reshma

"Chris" wrote:

I think I must be going crazy. All I want to do is add a button to the
bottom of a datagrid which will later run some code for a web based
project. I've created a custom control that inherits from the datagrid
and have added just a single line of code thus;

protected override void Render(HtmlTextWriter output)
{

output.Write(new System.Web.UI.WebControls.Button());

base.Render(output);
}
All looks fine at design time but at runtime I'm getting a cast
exception - what am I missing? Many thanks if you can point out where
I'm going wrong.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 16 '05 #2
Hi,

You do not need to create a new class, just use the Page PreRender event
and add a control to the datagrid.Controls collection

One question though, if you know for sure it will always go there, why not
declare it in the page?
Even if sometimes it's not shown it's easier to declare it alone and use
Visible = false;

Btw, you are getting error below cause Write expect a string, not a Button
instance

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Chris" <no****@devdex.com> wrote in message
news:%2******************@TK2MSFTNGP09.phx.gbl...

I think I must be going crazy. All I want to do is add a button to the
bottom of a datagrid which will later run some code for a web based
project. I've created a custom control that inherits from the datagrid
and have added just a single line of code thus;

protected override void Render(HtmlTextWriter output)
{

output.Write(new System.Web.UI.WebControls.Button());

base.Render(output);
}
All looks fine at design time but at runtime I'm getting a cast
exception - what am I missing? Many thanks if you can point out where
I'm going wrong.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 16 '05 #3


Thank you for your helpful suggestions. However I do want the button to
be part of the datagrid, the reason being is that it will interact with
the data in the grid. Furthermore I want to be able to expose a property
in the designer that allows a developer to choose whether the button is
visible.

Regards,

Chris

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #4
Hi,

Are you designing a control?

From your first post that is not clear

I still think that including the textbox in the grid is not good idea, what
interaction are you planning between the data & the textbox?

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Chris" <no****@devdex.com> wrote in message
news:eb****************@TK2MSFTNGP15.phx.gbl...


Thank you for your helpful suggestions. However I do want the button to
be part of the datagrid, the reason being is that it will interact with
the data in the grid. Furthermore I want to be able to expose a property
in the designer that allows a developer to choose whether the button is
visible.

Regards,

Chris

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Clayton Hamilton | last post by:
I have a DataGrid on a webform bound to a Datasource and can successfully use <ItemTemplate> to create edit/update/cancel functionality for user maintenance of data. I use separate logic to delete...
5
by: Phil Townsend | last post by:
I need to add a button to a datagrid. I have tried using the ButtonColumn and have also tried adding a button to a templatecolumn > itemtemplate. Whatever I have tried doesn't work, nor does it...
3
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that...
1
by: Andrew | last post by:
Hey all, I am very new to ASP.Net (and .Net in general), but that isn't stopping the boss from wanting to begin new projects in it. This latest project has me kinda stumped and after a couple...
2
by: Bob Hollness | last post by:
Hi group. I am a newbie to ASP.NET as you will see from some of the questions I may ask! I have a datagrid which I have populated from a database. It works great! I have added a column, via...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.