Triggering events in the child grid

Last post 07-11-2008 3:08 AM by Samu Zhang - MSFT. 3 replies.

Sort Posts:

  • Triggering events in the child grid

    07-10-2008, 5:30 AM
    • Member
      18 point Member
    • jayachitra
    • Member since 01-22-2008, 4:10 AM
    • India
    • Posts 33

    Dear All,

    I have a grid view in my application, which contains child grid for each and every row bounded to it.

    I want to have paging in the child grid and I have assigned an event handler for it in the code while binding it to the main grid.

    But it is not triggered.

    Can any one help me to resolve this issue?

    Thanks a lot in advance.

  • Re: Triggering events in the child grid

    07-10-2008, 8:34 AM
    • Member
      434 point Member
    • manish.singhal
    • Member since 12-19-2007, 8:30 AM
    • Noida
    • Posts 73

    Hi,

    You can attach the handler like below. Its for the Button click event inside another control. You can do it for Grid control inside the Main Grid Item created event.

     AddHandler btnAdd.Click, AddressOf AddNew_Click

    Regards,

    Manish

    www.componentone.com 

     

     

     

    Manish Singhal
    www.ComponentOne.com
  • Re: Triggering events in the child grid

    07-11-2008, 12:59 AM
    • Member
      18 point Member
    • jayachitra
    • Member since 01-22-2008, 4:10 AM
    • India
    • Posts 33

     Dear Manish,

    Thank you for your valuable reply.

     Actually I am using c#, I have added the paging change event handler, event though the event is not triggered.

     I kept a button inside the child grid and triggered  the event, that is also not working. 

     Is there any other way to resolve this?

  • Re: Triggering events in the child grid

    07-11-2008, 3:08 AM
    Answer

    Hi jayachitra ,

    Have a look at my sample,

     

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DataSourceSelectArguments arg = new DataSourceSelectArguments();
               DataView dv =  this.SqlDataSource1.Select(arg) as DataView;
               this.GridView1.DataSource = dv;
               GridView1.DataBind();
            }
        }
        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                GridView inner = e.Row.FindControl("GridView2") as GridView;
                DataSourceSelectArguments arg = new DataSourceSelectArguments();
                DataView dv = this.SqlDataSource1.Select(arg) as DataView;
                inner.DataSource = dv; inner.DataBind();
            }
        }
        protected void GridView2_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GridView self = sender as GridView;
            self.PageIndex = e.NewPageIndex;
            DataSourceSelectArguments arg = new DataSourceSelectArguments();
            DataView dv = this.SqlDataSource1.Select(arg) as DataView;
            self.DataSource = dv; self.DataBind();
        }
      
        <form id="form1" runat="server">
        <div>
            <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="countryid"
                Width="320px" OnRowDataBound="GridView1_RowDataBound">
                <Columns>
                    <asp:BoundField DataField="countryid" HeaderText="countryid" ReadOnly="True" SortExpression="countryid" />
                    <asp:BoundField DataField="countryname" HeaderText="countryname" SortExpression="countryname" />
                    <asp:TemplateField>
                        <ItemTemplate>
                            <asp:GridView ID="GridView2" runat="server" AllowPaging="True" PageSize="2" OnPageIndexChanging="GridView2_PageIndexChanging">
                            </asp:GridView>
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
            </asp:GridView>
        
        </div>
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString2 %>"
                SelectCommand="SELECT * FROM [country]"></asp:SqlDataSource>
        </form>

     

     


    Samu Zhang
    Microsoft Online Community Support

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question.
Page 1 of 1 (4 items)