Some events are not executed from child gridview

Discussion in 'ASP .Net' started by chris, Feb 15, 2007.

  1. chris

    chris Guest

    I have a perent gridview which includes in a template field a child
    gridview. Child gridview includes command buttons for opening
    different windows based on its row selected.

    I used the code below. The event for RowDataBound is executed, rows
    get different color, but event for RowCommand is not executed. What
    could be the problem ?

    Thanks a lot in advance.

    &nbsp;<asp:GridView ID="grv_batches" runat="server"
    AutoGenerateColumns="False"
    DataKeyNames="country_no,product_no,client_no" CssClass="GridView" >
    <Columns>
    <asp:ButtonField CommandName="Send" Text="Finish" >
    <ControlStyle CssClass="GridView_LinkButtons" />
    </asp:ButtonField>
    <asp:BoundField DataField="Country_name"
    HeaderText="Country" />
    <asp:BoundField DataField="product_name"
    HeaderText="Product" />
    <asp:BoundField DataField="client_name"
    HeaderText="Company" />
    <asp:TemplateField HeaderText="Details">
    <ItemTemplate>
    <asp:GridView ID="grv_reports" runat="server"
    AutoGenerateColumns="False" CssClass="GridView"
    OnRowCommand="grv_subscr_reports_RowCommand"
    OnRowDataBound="grv_subscr_reports_RowDataBound">
    <Columns>
    <asp:ButtonField CommandName="Sub"
    Text="S">
    <ControlStyle
    CssClass="GridView_LinkButtons" />
    </asp:ButtonField>

    Protected Sub grv_subscr_reports_RowCommand(ByVal sender As Object,
    ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs)
    If e.CommandName = "Sub" Then

    Protected Sub grv_subscr_reports_RowDataBound(ByVal sender As
    Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs)
    If e.Row.RowType = DataControlRowType.DataRow Then
    Select Case e.Row.Cells(11).Text 'report status
    Case "New"
    e.Row.BackColor = Drawing.Color.LightGreen
    chris, Feb 15, 2007
    #1
    1. Advertising

  2. chris

    Teemu Keiski Guest

    Do you databind the grid initially in

    if not page.ispostback then
    '...
    end if

    check?


    --
    Teemu Keiski
    AspInsider, ASP.NET MVP
    http://blogs.aspadvice.com/joteke
    http://teemukeiski.net



    "chris" <> wrote in message
    news:...
    >I have a perent gridview which includes in a template field a child
    > gridview. Child gridview includes command buttons for opening
    > different windows based on its row selected.
    >
    > I used the code below. The event for RowDataBound is executed, rows
    > get different color, but event for RowCommand is not executed. What
    > could be the problem ?
    >
    > Thanks a lot in advance.
    >
    > &nbsp;<asp:GridView ID="grv_batches" runat="server"
    > AutoGenerateColumns="False"
    > DataKeyNames="country_no,product_no,client_no" CssClass="GridView" >
    > <Columns>
    > <asp:ButtonField CommandName="Send" Text="Finish" >
    > <ControlStyle CssClass="GridView_LinkButtons" />
    > </asp:ButtonField>
    > <asp:BoundField DataField="Country_name"
    > HeaderText="Country" />
    > <asp:BoundField DataField="product_name"
    > HeaderText="Product" />
    > <asp:BoundField DataField="client_name"
    > HeaderText="Company" />
    > <asp:TemplateField HeaderText="Details">
    > <ItemTemplate>
    > <asp:GridView ID="grv_reports" runat="server"
    > AutoGenerateColumns="False" CssClass="GridView"
    > OnRowCommand="grv_subscr_reports_RowCommand"
    > OnRowDataBound="grv_subscr_reports_RowDataBound">
    > <Columns>
    > <asp:ButtonField CommandName="Sub"
    > Text="S">
    > <ControlStyle
    > CssClass="GridView_LinkButtons" />
    > </asp:ButtonField>
    >
    > Protected Sub grv_subscr_reports_RowCommand(ByVal sender As Object,
    > ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs)
    > If e.CommandName = "Sub" Then
    >
    > Protected Sub grv_subscr_reports_RowDataBound(ByVal sender As
    > Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs)
    > If e.Row.RowType = DataControlRowType.DataRow Then
    > Select Case e.Row.Cells(11).Text 'report status
    > Case "New"
    > e.Row.BackColor = Drawing.Color.LightGreen
    >
    Teemu Keiski, Feb 15, 2007
    #2
    1. Advertising

  3. chris

    chris Guest

    The first/parent grid is databinded from a button because user makes
    selection on countries, products, clients and depending on them SQL is
    created and bind the grid. The second/child gridview, shows more
    details for each row of parent grid and it's data is binded in the
    RowDataBound of the parent gridview.

    Since RowDataBound of child gridview works for applying colors to it's
    rows, shouldn't the RowCommand event work also ?
    chris, Feb 16, 2007
    #3
  4. chris

    Teemu Keiski Guest

    Yup,

    point was that if grid is databound on every request, it would prevent
    rowcommand from working.

    post the code


    --
    Teemu Keiski
    AspInsider, ASP.NET MVP
    http://blogs.aspadvice.com/joteke
    http://teemukeiski.net



    "chris" <> wrote in message
    news:...
    > The first/parent grid is databinded from a button because user makes
    > selection on countries, products, clients and depending on them SQL is
    > created and bind the grid. The second/child gridview, shows more
    > details for each row of parent grid and it's data is binded in the
    > RowDataBound of the parent gridview.
    >
    > Since RowDataBound of child gridview works for applying colors to it's
    > rows, shouldn't the RowCommand event work also ?
    >
    Teemu Keiski, Feb 16, 2007
    #4
  5. chris

    chris Guest

    thanks a lot for your message.

    I tried in debug mode break points to check whether code is executed
    in RowCommand event, but nothing. Only code in RowDataBound of child
    gridview is executed. I tried to change the name of event of
    RowCommand in asp and it gives an error that event is not found, so it
    regognises it, just not executes it.

    Here is the code:

    Protected Sub btn_show_Click(ByVal sender As Object, ByVal e As
    System.EventArgs) Handles btn_show.Click

    refresh_gridview_data()

    End Sub

    Protected Sub refresh_gridview_data()

    Dim sdsc As New SqlDataSource
    Dim var_SQL As String


    '------------------------------------------------------------------------------------------------------------------------------------

    sdsc.ConnectionString =
    ConfigurationManager.ConnectionStrings("ConnectionString1").ConnectionString
    sdsc.DataSourceMode = SqlDataSourceMode.DataReader

    var_SQL = "SELECT DISTINCT dbo.Report.country_no,
    dbo.Report.product_no, dbo.Report.client_no, "

    sdsc.SelectCommand = var_SQL

    grv_batches.DataSource = sdsc
    grv_batches.DataBind()

    End Sub

    Protected Sub grv_batches_RowCreated(ByVal sender As Object, ByVal e
    As System.Web.UI.WebControls.GridViewRowEventArgs) Handles
    grv_batches.RowCreated
    If e.Row.RowType = DataControlRowType.DataRow Then
    Dim sdsc As New SqlDataSource
    Dim grv_rep As GridView = e.Row.FindControl("grv_reports")

    sdsc.ConnectionString =
    ConfigurationManager.ConnectionStrings("ConnectionString1").ConnectionString

    sdsc.SelectCommandType =
    SqlDataSourceCommandType.StoredProcedure
    sdsc.SelectCommand = "STP_slct_Reports"

    sdsc.SelectParameters.Add("country_no",
    grv_batches.DataKeys(e.Row.RowIndex).Values("country_no"))
    sdsc.SelectParameters.Add("product_no",
    grv_batches.DataKeys(e.Row.RowIndex).Values("product_no"))
    sdsc.SelectParameters.Add("client_no",
    grv_batches.DataKeys(e.Row.RowIndex).Values("client_no"))

    grv_rep.DataSource = sdsc
    grv_rep.DataBind()
    End If

    Protected Sub grv_subscr_reports_RowCommand(ByVal sender As Object,
    ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs)
    If e.CommandName = "Report" Then
    'one_all = 1 'one report will be edited
    If (Not
    Page.ClientScript.IsStartupScriptRegistered(Me.GetType(), "Report"))
    Then 'Check to see if the startup script is already registered.
    Page.ClientScript.RegisterStartupScript(Me.GetType(),
    "Report", "window.open('Report.aspx',
    '','dialogHeight=850px,Width=800px,menubar=No,toolbar=no,scrollbars=yes');
    ", True)
    End If
    End If
    End Sub

    Protected Sub grv_subscr_reports_RowDataBound(ByVal sender As
    Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs)
    If e.Row.RowType = DataControlRowType.DataRow Then
    Select Case e.Row.Cells(11).Text 'report status
    Case "Cancelled"
    e.Row.BackColor = Drawing.Color.OrangeRed
    Case "On-Hold"
    e.Row.BackColor = Drawing.Color.Orange
    Case "Finished"
    e.Row.BackColor = Drawing.Color.LightSteelBlue
    Case "New"
    e.Row.BackColor = Drawing.Color.LightGreen
    End Select
    End If
    End Sub


    &nbsp;<asp:GridView ID="grv_batches" runat="server"
    AutoGenerateColumns="False"
    DataKeyNames="country_no,product_no,client_no" CssClass="GridView" >
    <Columns>
    <asp:ButtonField CommandName="Finish" Text="Finish" >
    <ControlStyle CssClass="GridView_LinkButtons" />
    </asp:ButtonField>
    <asp:BoundField DataField="Country_name"
    HeaderText="Country" />
    <asp:BoundField DataField="product_name"
    HeaderText="Product" />
    <asp:BoundField DataField="client_name"
    HeaderText="Company" />
    <asp:BoundField DataField="status_name"
    HeaderText="Status" />
    <asp:BoundField HeaderText="Finish Status" />
    <asp:TemplateField HeaderText="Subs">
    <ItemTemplate>
    <asp:GridView ID="grv_reports" runat="server"
    AutoGenerateColumns="False" CssClass="GridView"
    OnRowCommand="grv_subscr_reports_RowCommand"
    OnRowDataBound="grv_subscr_reports_RowDataBound">
    <Columns>
    <asp:ButtonField CommandName="Sub"
    Text="S">
    <ControlStyle
    CssClass="GridView_LinkButtons" />
    </asp:ButtonField>
    <asp:ButtonField CommandName="Report"
    Text="R">
    <ControlStyle
    CssClass="GridView_LinkButtons" />
    </asp:ButtonField>
    <asp:ButtonField CommandName="History"
    Text="H">
    <ControlStyle
    CssClass="GridView_LinkButtons" />
    </asp:ButtonField>
    <asp:BoundField DataField="note"
    HeaderText="N">
    <ItemStyle Font-Bold="True"
    ForeColor="Red" HorizontalAlign="Center" />
    </asp:BoundField>
    <asp:BoundField DataField="company_name"
    HeaderText="Company" />
    <asp:BoundField DataField="full_name"
    HeaderText="User" />
    <asp:BoundField
    DataField="proc_deliverable_name" HeaderText="Deliverable" />
    <asp:BoundField
    DataField="report_deadline" HeaderText="Deadline" />
    <asp:BoundField
    DataField="report_finished" HeaderText="Finish" />
    <asp:BoundField DataField="delay"
    HeaderText="Delay">
    <ItemStyle ForeColor="Red" />
    </asp:BoundField>
    <asp:BoundField
    DataField="report_importance_short_name" HeaderText="Imp" />
    <asp:BoundField
    DataField="report_status_name" HeaderText="Report Status" />
    <asp:BoundField
    DataField="sub_status_name" HeaderText="Sub. Status" />
    <asp:BoundField DataField="date_activated"
    HeaderText="Date Activated" />
    <asp:BoundField DataField="sub_no"
    HeaderText="sub_no" Visible="False" />
    <asp:BoundField DataField="sub_detail_no"
    HeaderText="sub_detail_no"
    Visible="False" />
    <asp:BoundField DataField="report_no"
    HeaderText="report_no" Visible="False" />
    </Columns>
    <RowStyle CssClass="GridView_Row" />
    <HeaderStyle CssClass="GridView_Header2" Font-
    Size="XX-Small" />
    <AlternatingRowStyle
    CssClass="GridView_AlternateRow" />
    </asp:GridView>
    </ItemTemplate>
    </asp:TemplateField>
    </Columns>
    <RowStyle CssClass="GridView_Row" />
    <HeaderStyle CssClass="GridView_Header" />
    <AlternatingRowStyle CssClass="GridView_AlternateRow" />
    </asp:GridView>
    chris, Feb 16, 2007
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Galina Grechka
    Replies:
    1
    Views:
    350
    el_khiyari
    Apr 14, 2005
  2. Luigi
    Replies:
    2
    Views:
    507
    Eliyahu Goldin
    May 22, 2006
  3. Jeff Rodriguez
    Replies:
    23
    Views:
    1,085
    David Schwartz
    Dec 9, 2003
  4. =?Utf-8?B?Y2hyaXM=?=

    Events of child gridview are not executed

    =?Utf-8?B?Y2hyaXM=?=, Feb 16, 2007, in forum: ASP .Net
    Replies:
    4
    Views:
    506
    =?Utf-8?B?Y2hyaXM=?=
    Feb 20, 2007
  5. Chris

    Events Events Events Please Help

    Chris, Aug 30, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    339
    Chris
    Aug 30, 2005
Loading...

Share This Page