PC Review


Reply
Thread Tools Rate Thread

Adding a button to a datagrid

 
 
Chris
Guest
Posts: n/a
 
      12th Jan 2005

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!
 
Reply With Quote
 
 
 
 
=?Utf-8?B?UmVzaG1hIFByYWJodQ==?=
Guest
Posts: n/a
 
      12th Jan 2005
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!
>

 
Reply With Quote
 
Ignacio Machin \( .NET/ C# MVP \)
Guest
Posts: n/a
 
      12th Jan 2005
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" <(E-Mail Removed)> wrote in message
news:%23UvhrAK%(E-Mail Removed)...
>
> 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!



 
Reply With Quote
 
Chris
Guest
Posts: n/a
 
      13th Jan 2005


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!
 
Reply With Quote
 
Ignacio Machin \( .NET/ C# MVP \)
Guest
Posts: n/a
 
      13th Jan 2005
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" <(E-Mail Removed)> wrote in message
news:ebTlifV%(E-Mail Removed)...
>
>
> 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!



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding a select button to my datagrid Bob Hollness Microsoft ASP .NET 2 13th Jan 2005 07:18 PM
Need help with adding button to a datagrid dynamically Mark Microsoft ASP .NET 1 31st Aug 2004 03:51 PM
Adding a command button to a datagrid =?Utf-8?B?SmltIE1hY2U=?= Microsoft ASP .NET 2 22nd Mar 2004 11:41 PM
Adding Button to Datagrid =?Utf-8?B?TWFyaw==?= Microsoft Dot NET Framework Forms 3 4th Mar 2004 10:51 PM
Adding attributes to page button of datagrid sumit Microsoft ASP .NET 5 4th Dec 2003 04:17 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:25 AM.