PC Review


Reply
Thread Tools Rate Thread

adding buttons to a datagrid (web forms)

 
 
Phil Townsend
Guest
Posts: n/a
 
      30th Dec 2004
I have a datagrid which is part of a web form. I need to place a button
in each row to invoke a custom method (not an update, delete, cancel,
etc.). I thought that a button in a datagrid item template raises the
ItemCommand event. however, I can get no response from the button. The
code is never reached. I have registered an event handler that points to
the method. What could I be doing wrong?



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
 
 
 
Dan Bass
Guest
Posts: n/a
 
      31st Dec 2004
Phil,

Could you put down your HTML for the grid, as well as the item command event
handler?

We'll see if we can help from there.

Thanks

Dan.
ps. are you related to a Paul Towsend?

"Phil Townsend" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I have a datagrid which is part of a web form. I need to place a button
> in each row to invoke a custom method (not an update, delete, cancel,
> etc.). I thought that a button in a datagrid item template raises the
> ItemCommand event. however, I can get no response from the button. The
> code is never reached. I have registered an event handler that points to
> the method. What could I be doing wrong?
>
>
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!



 
Reply With Quote
 
Phil Townsend
Guest
Posts: n/a
 
      3rd Jan 2005
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.





*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
Dan Bass
Guest
Posts: n/a
 
      4th Jan 2005
Phil,

From you've setup the command for "showQuestions", but there's no link (in
the code you've provided anyway) that assigns the onclick event to the
function.

try this:
<ItemTemplate>
<asp:Button ID="btnQuestionList" OnClick="showQuestions"
CommandName="showQuestions" Text=" ? " Runat="server" />
</ItemTemplate>

I found this page with an example of the sort of thing you're doing...
http://authors.aspalliance.com/aldot...amples/cd.aspx (Example
1)

Hope that helps.
Daniel.

"Phil Townsend" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.
>
>
>
>
>
> *** 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
problem adding buttons to a webforms datagrid Phil Townsend Microsoft C# .NET 5 6th Jan 2005 03:44 PM
adding buttons to a datagrid Phil Townsend Microsoft ASP .NET 1 30th Dec 2004 08:20 PM
Adding Attributes to buttons within datagrid Craig G Microsoft ASP .NET 4 13th Dec 2004 04:53 PM
Adding buttons in a ButtonColumn in a DataGrid a row at a time Adam White Microsoft ASP .NET 1 22nd Nov 2004 04:20 PM
Adding buttons to a datagrid doesn't fire its events Andrés Giraldo Microsoft Dot NET 0 19th Sep 2003 04:24 PM


Features
 

Advertising
 

Newsgroups
 


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