473,322 Members | 1,523 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Some events are not executed from child gridview

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

Feb 15 '07 #1
4 4171
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" <CL*****@gmail.comwrote in message
news:11********************@a75g2000cwd.googlegrou ps.com...
>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
Feb 15 '07 #2
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 ?

Feb 16 '07 #3
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" <CL*****@gmail.comwrote in message
news:11**********************@j27g2000cwj.googlegr oups.com...
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 ?
Feb 16 '07 #4
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("Connection String1").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("Connection String1").ConnectionString

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

Feb 16 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: JPRoot | last post by:
Hi I use the following syntax to have events inherited from base to child classes which works nicely (virtual and override keyword on events). But I am wondering if it is a "supported" way of using...
7
by: Colin Young | last post by:
I have a UserControl that contains a calendar control. The calendar is not raising events (month navigation, date selections, etc.). I've checked that the OnSelectionChanged event has a handler...
2
by: ads | last post by:
hi guys, Here's the scenario: i have a gridview on a parent page. Then i open another (child) page where i can modify the data on the dridview. How do i update the gridview soon as i do...
1
by: needin4mation | last post by:
protected void Page_Load(object sender, EventArgs e) { TextBox mpTextBox = (TextBox)(Master.FindControl("txtFreeSearch")); Response.Write("mp" + mpTextBox.Text); //only works the second time ...
0
by: nitinp | last post by:
I am facing the problem in editing records in child gridview which i have placed in the parent gridview's cell. I have bound both parent and child with different sqlDataSource objects. I have...
10
by: Benton | last post by:
Hi there, I have a UserControl with a couple of textboxes and a couple of buttons ("Save" and "Cancel"). The Click event for this buttons is in the UserControl's codebehind of course, so here's...
1
by: Andrew Hayes | last post by:
I have a parent page with a gridview, and a child page with a formview. Using the solution on velocityreviews: ...
4
by: =?Utf-8?B?Y2hyaXM=?= | last post by:
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...
0
by: erkbiz | last post by:
Hello, I have an event that I defined with a delegate. When I bind this event to a button and place the event prior to calling base.OnLoad(e) which is called prior to if (!PostBack) the Event...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.