Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Events of child gridview are not executed

Reply
Thread Tools

Events of child gridview are not executed

 
 
=?Utf-8?B?Y2hyaXM=?=
Guest
Posts: n/a
 
      02-16-2007
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.

<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

 
Reply With Quote
 
 
 
 
=?Utf-8?B?TWlsb3N6IFNrYWxlY2tpIFtNQ0FEXQ==?=
Guest
Posts: n/a
 
      02-16-2007
Show us how you bind the data. I suspect the data for internal data grid is
being
re-bound on every postback so rowcommand event won't be raised.
--
Milosz


"chris" wrote:

> 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.
>
> <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
>

 
Reply With Quote
 
 
 
 
=?Utf-8?B?Y2hyaXM=?=
Guest
Posts: n/a
 
      02-16-2007
Thanks Milosz for your message.

Here is the code:

My parent gridview is binded in btn_show button, because user select the
countries, products, clients for showing the data in parent gridview which
then refreshes the child gridview.

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("Connection String1").ConnectionStrin¬*g
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("Connection String1").ConnectionStrin¬*g


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


sdsc.SelectParameters.Add("country_no",
grv_batches.DataKeys(e.Row.RowIndex).Values("count ry_no"))
sdsc.SelectParameters.Add("product_no",
grv_batches.DataKeys(e.Row.RowIndex).Values("produ ct_no"))
sdsc.SelectParameters.Add("client_no",
grv_batches.DataKeys(e.Row.RowIndex).Values("clien t_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.Get Type(), "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,tool bar=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


<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>




 
Reply With Quote
 
=?Utf-8?B?TWlsb3N6IFNrYWxlY2tpIFtNQ0FEXQ==?=
Guest
Posts: n/a
 
      02-16-2007
Hi there again,

You're re-binding internal gridview on every postback inside rowcreated
event. Move internal grid data binding to rowdatabound event and everything
will be OK:

Protected Sub grv_batches_RowDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewRowEventArgs) Handles
grv_batches.RowDataBound
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("Connection String1").ConnectionStringsdsc.SelectCommandType =
SqlDataSourceCommandType.StoredProcedure()
sdsc.SelectCommand = "STP_slct_Reports"


sdsc.SelectParameters.Add("country_no",
grv_batches.DataKeys(e.Row.RowIndex).Values("count ry_no"))
sdsc.SelectParameters.Add("product_no",
grv_batches.DataKeys(e.Row.RowIndex).Values("produ ct_no"))
sdsc.SelectParameters.Add("client_no",
grv_batches.DataKeys(e.Row.RowIndex).Values("clien t_no"))

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


Hope it helps
--
Milosz


"chris" wrote:

> Thanks Milosz for your message.
>
> Here is the code:
>
> My parent gridview is binded in btn_show button, because user select the
> countries, products, clients for showing the data in parent gridview which
> then refreshes the child gridview.
>
> 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("Connection String1").ConnectionStrin¬*g
> 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("Connection String1").ConnectionStrin¬*g
>
>
> sdsc.SelectCommandType =
> SqlDataSourceCommandType.StoredProcedure
> sdsc.SelectCommand = "STP_slct_Reports"
>
>
> sdsc.SelectParameters.Add("country_no",
> grv_batches.DataKeys(e.Row.RowIndex).Values("count ry_no"))
> sdsc.SelectParameters.Add("product_no",
> grv_batches.DataKeys(e.Row.RowIndex).Values("produ ct_no"))
> sdsc.SelectParameters.Add("client_no",
> grv_batches.DataKeys(e.Row.RowIndex).Values("clien t_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.Get Type(), "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,tool bar=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
>
>
> <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>
>
>
>
>

 
Reply With Quote
 
=?Utf-8?B?Y2hyaXM=?=
Guest
Posts: n/a
 
      02-20-2007
Thanks a lot Milosz, this was the problem!!

 
Reply With Quote
 
 
 
Reply

Thread Tools

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
Can I control the sequence events are executed? AAaron123 ASP .Net 2 02-11-2009 04:52 PM
Some events are not executed from child gridview chris ASP .Net 4 02-16-2007 12:27 PM
Master page code executed after child page code Luigi ASP .Net 2 05-22-2006 09:53 AM
Events Events Events Please Help Chris ASP .Net Web Controls 0 08-30-2005 08:21 PM
How do I: Main thread spawn child threads, which child processes...control those child processes? Jeff Rodriguez C Programming 23 12-09-2003 11:06 PM



Advertisments