Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6
This is the forum to discuss the Wrox book ASP.NET 2.0 Instant Results by Imar Spaanjaars, Paul Wilton, Shawn Livermore; ISBN: 9780471749516
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old November 4th, 2007, 12:26 PM
Registered User
 
Join Date: Oct 2007
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Fire Events from Nested GridView

Hi Imar,

I'm using the CMS Project of yours as a base and decided to add a nested Gridview inside an itemtemplate to do a Child Parent type of display with Content and Content Types.

What i'm having problems with is that i can't seem to get access to the nested gridviews events programmically. Here is the example code below.

<asp:GridView ID="GridView1" runat="server" AllowPaging="True" DataKeyNames="Id"
    DataSourceID="sdsContentTypes" AutoGenerateColumns="False"
    CssClass="NestedGridView1Style" Width="100%">

      <SelectedRowStyle CssClass="Green" />
      <HeaderStyle CssClass="Pink" />
      <Columns>

      <asp:TemplateField>
        <HeaderTemplate>
          <table cellpadding="2" cellspacing="0" border="0" width="100%">

            <tr>
              <td width="2%">&nbsp;</td>
              <td width="38%"> Page</td>
              <td width="30%"> Sort Order</td>
              <td width="30%"> Active</td>
            </tr>
          </table>
        </HeaderTemplate>
        <ItemTemplate>
          <table border="0" cellpadding="2" cellspacing="0" width="100%">

            <tr>
              <td width="2%"><asp:ImageButton CommandName="Select" CommandArgument="<%# Container.DataItemIndex %>" ToolTip="Click here to toggle the display of the orders list for this customer" ID="selectBtn" ImageUrl="../Images/expand.gif" runat="server" /></td>
              <td width="38%"><asp:Label ID="lblDescription" runat="server" Text='<%# Eval("Description") %>'></asp:Label>
              </td>
              <td width="30%"><asp:Label ID="lblSortOrder" runat="server" Text='<%# Eval("SortOrder") %>'></asp:Label>
              </td>
              <td width="30%"><asp:Label ID="lblVisible" runat="server" Text='<%# Eval("Visible") %>'></asp:Label>
              </td>
            </tr>

            <tr>
              <td colspan="4">
              <table border="0" cellpadding="3" cellspacing="0" width="100%">
                  <tr>

                    <td align="center">
                    <asp:GridView ID="ChildGridView1" runat="server"
                        DataKeyNames="Id" Visible="False" DataSourceID="sdsContent"
                        AutoGenerateColumns="False" CssClass="GridView1ChildStyle" Width="90%">
                        <SelectedRowStyle CssClass="Blue" />
                        <HeaderStyle CssClass="Header" />
                        <Columns>
                        <asp:TemplateField HeaderText="Title">
                          <ItemTemplate>
                            <asp:Label ID="Label1" runat="server" Text='<%# Bind("Title") %>'></asp:Label>
                          </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Creation Date">
                          <ItemTemplate>
                            <asp:Label ID="Label2" runat="server" Text='<%# Eval("CreateDateTime", "{0:d}") %>'></asp:Label>
                          </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Updated Date">
                          <ItemTemplate>
                            <asp:Label ID="Label4" runat="server" Text='<%# Bind("UpdateDateTime", "{0:d}") %>'></asp:Label>
                          </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Active">
                          <ItemTemplate>
                              <asp:Image runat="server" ID="Image1" ImageUrl='<%# activeChk(Eval("Visible").toString) %>' />
                          </ItemTemplate>
                        </asp:TemplateField>
                         <asp:ButtonField ButtonType="Image" CommandName="Select" ImageUrl="../Images/view.gif" />
                         <asp:ButtonField ButtonType="Image" CommandName="Edit" ImageUrl="../Images/edit.gif" />
                         <asp:ButtonField ButtonType="Image" CommandName="Delete" ImageUrl="../Images/delete.gif" />
                        </Columns>
                      </asp:GridView>
                       </td>
                  </tr>
                </table></td>
            </tr>
          </table>
            <asp:SqlDataSource ID="sdsContent" runat="server"
            ConnectionString="<%$ ConnectionStrings:CMS %>"
             SelectCommand="Select * From cms_Content where ContentTypeId = @ContentTypeId"
             OnUpdating="">
               <SelectParameters>
                    <asp:Parameter Name="ContentTypeId" DefaultValue="0" Type="Int32" />
               </SelectParameters>
            </asp:SqlDataSource>
        </ItemTemplate>
      </asp:TemplateField>
      </Columns>
    </asp:GridView>

The gridview in Bold is what i can't seem to get access to the events programmically.

Any help would be appreciated.
Adam


  #2 (permalink)  
Old November 5th, 2007, 11:10 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi Adam,

Because the controls are nested, you can't directly access them code behind and wire up event handlers using the Handles keyword.

Instead, write explicit code. E.g. in the GridView write something like OnYourEventName="YourEventHandler" and then create a method in the code behind called YourEventHandler with a signature that matches a handler you would normally use.

Does this help?

Imar

---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
  #3 (permalink)  
Old November 5th, 2007, 01:18 PM
Registered User
 
Join Date: Oct 2007
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

That helps alot Imar thanks!



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to fire events of a Active X dll in ASP.NET Brijendra Pandey ASP.NET 3.5 Professionals 1 October 4th, 2008 05:44 PM
Explain the event fire in Gridview? venkatu2005 ASP.NET 1.0 and 1.1 Basics 3 April 8th, 2008 08:41 AM
How to fire events from datagrid cell? param99 ASP.NET 1.0 and 1.1 Professional 2 November 15th, 2006 07:33 AM
ShowPopup doen't fire events on menu bar sumit_kalra Access VBA 1 March 3rd, 2005 11:13 AM
ShowPopup doesn't fire events on menu bar sumit_kalra Excel VBA 0 July 12th, 2003 06:36 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.