472,984 Members | 2,123 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

problem adding buttons to a webforms datagrid

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 produce
errors. The method i have specified to execute is never reached. Can
anybody tell what I am doing wrong? Thanks...

webform code:

<form id="Form1" method="post" runat="server">
<asp:datagrid id="dgconcept" runat="server"
AlternatingItemStyle-BackColor="#99ffcc" AutoGenerateColumns="False"
CellPadding="4">
<Columns>
<asp:TemplateColumn HeaderText="">
<ItemTemplate>

<%#DataBinder.Eval(Container.DataItem,"conceptid") %>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Concept">
<ItemTemplate>

<%#DataBinder.Eval(Container.DataItem,"concept") %>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn>
<ItemTemplate>
<asp:Button ID="btnQuestionList"
CommandName="showQuestions"
Text=" ? " Runat="server" />
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>
<asp:datagrid id="dgquestions"
runat="server"></asp:datagrid>
<asp:datagrid id="dganswers" runat="server"></asp:datagrid>
</form>

Codebehind:
protected void showQuestions(object source,
DataGridCommandEventArgs
e)
{
dgquestions.DataSource=dsfulltest().Tables[1];
dgquestions.Visible=true;
dgquestions.DataBind();
}

As mentioned before, when running this through a VS.NET debugger, the
code in showQuestions method is never reached. I have tried this using
the buttoncolumn instead, but with the same results--the code cannot be
reached.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #1
5 1496
Its possible that the event wiring between the event and the handler
ShowQuestions is broken. Visual Studio does that sometimes. Just open up the
InitializeComponent method and see if the event wiring code is in there.

The other thing I noticed is that you seem to be binding data to the
dgquestions grid instead of the dgconcept grid which has all the controls :)
-amit

"Phil Townsend" <ph*******@yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
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 produce
errors. The method i have specified to execute is never reached. Can
anybody tell what I am doing wrong? Thanks...

webform code:

<form id="Form1" method="post" runat="server">
<asp:datagrid id="dgconcept" runat="server"
AlternatingItemStyle-BackColor="#99ffcc" AutoGenerateColumns="False"
CellPadding="4">
<Columns>
<asp:TemplateColumn HeaderText="">
<ItemTemplate>

<%#DataBinder.Eval(Container.DataItem,"conceptid") %>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Concept">
<ItemTemplate>

<%#DataBinder.Eval(Container.DataItem,"concept") %>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn>
<ItemTemplate>
<asp:Button ID="btnQuestionList"
CommandName="showQuestions"
Text=" ? " Runat="server" />
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>
<asp:datagrid id="dgquestions"
runat="server"></asp:datagrid>
<asp:datagrid id="dganswers" runat="server"></asp:datagrid>
</form>

Codebehind:
protected void showQuestions(object source,
DataGridCommandEventArgs
e)
{
dgquestions.DataSource=dsfulltest().Tables[1];
dgquestions.Visible=true;
dgquestions.DataBind();
}

As mentioned before, when running this through a VS.NET debugger, the
code in showQuestions method is never reached. I have tried this using
the buttoncolumn instead, but with the same results--the code cannot be
reached.

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

Nov 16 '05 #2
Hi,

Replace CommandName by OnCommand in the button declaration:
<asp:Button ID="btnQuestionList"
OnCommand="showQuestions"
Text=" ? " Runat="server" />

Cheers,

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

"Phil Townsend" <ph*******@yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
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 produce
errors. The method i have specified to execute is never reached. Can
anybody tell what I am doing wrong? Thanks...

webform code:

<form id="Form1" method="post" runat="server">
<asp:datagrid id="dgconcept" runat="server"
AlternatingItemStyle-BackColor="#99ffcc" AutoGenerateColumns="False"
CellPadding="4">
<Columns>
<asp:TemplateColumn HeaderText="">
<ItemTemplate>

<%#DataBinder.Eval(Container.DataItem,"conceptid") %>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Concept">
<ItemTemplate>

<%#DataBinder.Eval(Container.DataItem,"concept") %>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn>
<ItemTemplate>
<asp:Button ID="btnQuestionList"
CommandName="showQuestions"
Text=" ? " Runat="server" />
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>
<asp:datagrid id="dgquestions"
runat="server"></asp:datagrid>
<asp:datagrid id="dganswers" runat="server"></asp:datagrid>
</form>

Codebehind:
protected void showQuestions(object source,
DataGridCommandEventArgs
e)
{
dgquestions.DataSource=dsfulltest().Tables[1];
dgquestions.Visible=true;
dgquestions.DataBind();
}

As mentioned before, when running this through a VS.NET debugger, the
code in showQuestions method is never reached. I have tried this using
the buttoncolumn instead, but with the same results--the code cannot be
reached.

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

Nov 16 '05 #3
Thanks for all the replies, but unfortunately nothing seems to work. I
have tried using an ItemTemplate. I have tried using a ButtonColumn. I
have tried with and without registering an event handler in codebehind.
I have using OnCommand & OnClick (within the asp:button or
buttoncolumn), and OnItemCommand (within the datagrid itself), and still
the method I am referencing is never reached. Should I abandon attempts
at trying to use a button from within a datagrid? I have found that the
only buttons that work within datagrids are the standard Edit, Update,
Delete and Cancel. Is the datagrid even capable of issuing an action to
a custom method? One would certainly think so, but it appears not so...

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

Did you make sure that you have runat=server in the button?

"Phil Townsend" <ph*******@yahoo.com> wrote in message
news:OK**************@TK2MSFTNGP10.phx.gbl...
Thanks for all the replies, but unfortunately nothing seems to work. I
have tried using an ItemTemplate. I have tried using a ButtonColumn. I
have tried with and without registering an event handler in codebehind.
I have using OnCommand & OnClick (within the asp:button or
buttoncolumn), and OnItemCommand (within the datagrid itself), and still
the method I am referencing is never reached. Should I abandon attempts
at trying to use a button from within a datagrid? I have found that the
only buttons that work within datagrids are the standard Edit, Update,
Delete and Cancel. Is the datagrid even capable of issuing an action to
a custom method? One would certainly think so, but it appears not so...

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

Nov 16 '05 #5
Yes, I have runat=server in the button tag. It is as if there is no
wiring to the event handler, even though I have specified it in
InitializeComponent...

private void InitializeComponent()
{
this.dgconcept.ItemCommand+=new
DataGridCommandEventHandler(this.showQuestions);
this.Load+=new System.EventHandler(this.Page_Load);
}

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

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

Similar topics

0
by: Andrés Giraldo | last post by:
Hi! I'm adding an asp button to a datagrid on the ItemDataBound event, when the user clicks on this button, I basically remove the button and create other 2 buttons... my problem is.. the 2 last...
6
by: Jon | last post by:
Hello, I have a datagrid and the data in it is dynamically created at runtime... For iCounter = 0 To dataset.Tables(0).Columns.Count - 1 Dim objbc As New BoundColumn() With objbc .DataField...
2
by: Will | last post by:
Hi I've been looking a way to put buttons in a column, but almost every example is for WebForms and I need it for WinForms... I found a way for doing it, with the DataGridColumnStyle class,...
3
by: kscdavefl | last post by:
I am using the following code to iterate through a DataGrid to change the value in one of the columns: private void UpdateFCA() { for (int i = 0; i <= reportGrid.Items.Count; i++) {...
0
by: Nikhil Patel | last post by:
Hi all, I am having a problem adding a reference in an ASP.Net project. I have written a custom control using a Web Control Library project. I compiled this project and generated a dll. Now...
2
by: saleek | last post by:
Hi, I am trying to figure out why my datagrid has stopped firing the page and sort commands. Scenario: I originally had template columns in my datagrid and had set up custom bi-directional...
1
by: Joel Byrd | last post by:
I am having a problem adding a node to the page. This works on other browser (Opera, Firefox, etc.), but not in IE. The following is the function to add the node: (the id "test_div" is a...
0
by: bostjanj | last post by:
Hi, I have a problem adding web service to project. I get the following error: There was an error downloading '/service.asmx'. The request failed with the error message: Object moved to...
1
by: Paddy | last post by:
The problem I am facing is as follows: I am populating an HTML table on my webpage with rows of data from a database. The rows may be sometimes 10 and sometimes say,3. I have two buttons on that...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

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.