Hi all!
I have a gridview inside a datagrid (nested) for which (gridview) the
rowcommand is not raised in order to delete a row from the grid!
I also tried OnRowCommand="method", didn't work either!
Does anyone know how can I make this work?
Thanks in advance! 7 17283
Hi,
As long as you bind the datasource for the nested - Inner gridview in
the ItemDataBound event and not in the ItemCreated Event of the outer Data
grid, it shd work...the RowCommand event of the inner Gridview will fire.
// dgMyGrid is my outer DataGrid.
// gvMyGridView is the inner GridView.
protected void dgMyGrid_ItemDataBound(object sender, DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem )
{
((GridView)e.Item.FindControl("gvMyGridView")).Dat aSource = dt;
((GridView)e.Item.FindControl("gvMyGridView")).Dat aBind();
}
}
public void gvMyGridView_RowCommand(object sender, GridViewCommandEventArgs e)
{
// Your delete code for the RowCommand...
}
In the HTML Source:
<asp:DataGrid ID="dgMyGrid" runat="server" AutoGenerateColumns="false"
OnItemDataBound="dgMyGrid_ItemDataBound" >
<Columns>
<asp:BoundColumn DataField="col1" HeaderText="Colum 1" />
<asp:TemplateColumn HeaderText="Nested GridView Column">
<ItemTemplate >
<asp:GridView ID="gvMyGridView" runat="server"
OnRowCommand="gvMyGridView_RowCommand"
AutoGenerateColumns="false" >
<Columns>
<asp:BoundField DataField="col2"
HeaderText="InnerCol1" />
<asp:BoundField DataField="col3"
HeaderText="InnerCol2"/>
<asp:ButtonField ButtonType="button"
CommandName="Delete"
Text="delete"
HeaderText="Delete" />
</Columns>
</asp:GridView>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
I guess this shd work...
-Parvathy Padmanabhan
oops... sorry,
it's actually a gridview inside a datalist, sorry for that...
I DO bind the gridview inside the datalist's ItemDataBound event and doesn't
work!!!
Please help me out, I can't figure out what is going wrong here!
"Parvathy Padmanabhan" wrote:
Hi,
As long as you bind the datasource for the nested - Inner gridview in
the ItemDataBound event and not in the ItemCreated Event of the outer Data
grid, it shd work...the RowCommand event of the inner Gridview will fire.
// dgMyGrid is my outer DataGrid.
// gvMyGridView is the inner GridView.
protected void dgMyGrid_ItemDataBound(object sender, DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem )
{
((GridView)e.Item.FindControl("gvMyGridView")).Dat aSource = dt;
((GridView)e.Item.FindControl("gvMyGridView")).Dat aBind();
}
}
public void gvMyGridView_RowCommand(object sender, GridViewCommandEventArgs e)
{
// Your delete code for the RowCommand...
}
In the HTML Source:
<asp:DataGrid ID="dgMyGrid" runat="server" AutoGenerateColumns="false"
OnItemDataBound="dgMyGrid_ItemDataBound" >
<Columns>
<asp:BoundColumn DataField="col1" HeaderText="Colum 1" />
<asp:TemplateColumn HeaderText="Nested GridView Column">
<ItemTemplate >
<asp:GridView ID="gvMyGridView" runat="server"
OnRowCommand="gvMyGridView_RowCommand"
AutoGenerateColumns="false" >
<Columns>
<asp:BoundField DataField="col2"
HeaderText="InnerCol1" />
<asp:BoundField DataField="col3"
HeaderText="InnerCol2"/>
<asp:ButtonField ButtonType="button"
CommandName="Delete"
Text="delete"
HeaderText="Delete" />
</Columns>
</asp:GridView>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
I guess this shd work...
-Parvathy Padmanabhan
Hi,
The RowCommand event of the inner gridview wld fire, provided you bind
your Datalist in the first request and not again in the subsequent post backs.
//dlMyDataList is the datalist am using and dt is my datatable, which will
be the source.
if (! IsPostBack)
{
dlMyDataList.DataSource = dt;
dlMyDataList.DataBind();
}
if you have bound your datalist on the page load and if you are rebinding it
during every post back, the onRowCommand event will not fire because, the
grid view gets created every single time.
I guess that shd resolve your problem....
- Parvathy Padmanabhan
No, I don't!
Well here is my code: -
<asp:datalist id="lstTicketsInfo" cellspacing="0" cellpadding="0"
-
repeatdirection="Vertical" enableviewstate="false" runat="Server" >
-
<ItemTemplate>
-
<asp:gridview id="gvBasket" runat="server"
-
CssClass="myGrid" GridLines="None" ShowHeader="True"
-
ShowFooter="True" autogeneratecolumns="False"
-
OnRowCommand="gvBasket_RowCommand">
-
<headerstyle horizontalalign="Right"></headerstyle>
-
<rowstyle HorizontalAlign="Right"/>
-
<FooterStyle HorizontalAlign="Right"/>
-
<columns>
-
<asp:TemplateField HeaderText="Quantity">
-
<headerstyle horizontalalign="Right"></headerstyle>
-
<ItemTemplate><input id="txtQuantity" style="text-align: right;"
-
runat="server" Value='<%# Eval("Quantity") %>' /></ItemTemplate>
-
<FooterTemplate><input id="txtQuantityTotal" style="text-align:
-
right;" readonly="readonly" runat="server" /></FooterTemplate>
-
</asp:TemplateField>
-
-
<asp:TemplateField HeaderText="Price">
-
<ItemTemplate><asp:Label ID="lblPrice" runat="server" Text='<%#
-
Eval("Price") %>'></asp:Label></ItemTemplate>
-
</asp:TemplateField>
-
-
<asp:TemplateField HeaderText="Total">
-
<ItemTemplate><asp:Label ID="lblTotalSingle" runat="server"
-
Text='<%# Eval("Total") %>'></asp:Label></ItemTemplate>
-
<FooterTemplate><input id="txtPriceTotal" style="text-align:
-
right;" readonly="readonly" runat="server" /></FooterTemplate>
-
</asp:TemplateField>
-
-
<asp:TemplateField>
-
<ItemTemplate><asp:button id="btnDelete" text="" CommandName =
-
"Delete" CommandArgument='<%# Eval("EventID").ToString() & "~" &
-
Eval("D13_D05_IDs").ToString() & "|" & Eval("E01_i03_id").ToString() & "~" &
-
Eval("E01_index").ToString() %>' runat="server" OnCommand="DeleteTicket"
-
/></ItemTemplate>
-
</asp:TemplateField>
-
</columns>
-
</asp:gridview>
-
</ItemTemplate>
-
</asp:datalist>
-
-
Imports System.Data
-
-
Partial Class Basket
-
Inherits System.Web.UI.Page
-
-
Private m_QuantitySubTotal As Byte
-
Private m_PriceSubTotal As Double
-
Private WithEvents gvBasket As GridView
-
Private m_ActiveGridCounter As Byte
-
-
Private m_QuantityTotal As Byte
-
Private m_PriceTotal As Double
-
-
Private ReadOnly Property colBasketItems() As helperclasses.BasketItems
-
Get
-
If Session("colBasketItems") Is Nothing Then
-
Return Nothing
-
Else
-
Return CType(Session("colBasketItems"), helperclasses.BasketItems)
-
End If
-
End Get
-
End Property
-
-
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
-
System.EventArgs) Handles Me.Load
-
-
Master.BasketControl.Visible = False
-
-
If Me.IsPostBack Then Exit Sub
-
-
LoadMasterData()
-
-
End Sub
-
-
Private Sub LoadMasterData()
-
-
If colBasketItems Is Nothing OrElse (Not CBool(colBasketItems.Count)) Then
-
If Session("EventId") Is Nothing OrElse (Not
-
IsNumeric(Session("EventId"))) Then Exit Sub
-
Response.Redirect("~/BookingSteps/EventBookStep1.aspx?id=" &
-
Session("EventId").ToString)
-
Exit Sub
-
End If
-
-
Dim dsBasketItems As New DataSet
-
With dsBasketItems
-
.Tables.Add("BasketItems")
-
With .Tables(0).Columns
-
.Add("EventName", GetType(String))
-
.Add("VenueName", GetType(String))
-
.Add("EventDate", GetType(String))
-
.Add("EventID", GetType(Integer))
-
.Add("D13_D05_IDs", GetType(String))
-
End With
-
End With
-
-
For Each colTickets As helperclasses.Tickets In colBasketItems
-
Dim dr As DataRow = dsBasketItems.Tables(0).NewRow
-
With colTickets
-
dr("EventName") = .EventName
-
dr("VenueName") = .VenueName
-
dr("EventDate") = String.Format("{0:dd\/MM\/yyyy - HH:mm}",
-
..EventDate)
-
dr("EventID") = .EventID
-
dr("D13_D05_IDs") = .D13_D05_IDs
-
End With
-
dsBasketItems.Tables(0).Rows.Add(dr)
-
Next
-
-
If Not CBool(dsBasketItems.Tables(0).Rows.Count) Then
-
InfoLabel1.InnerHtml = "Δεν βρ*θηκαν δεδομ*να."
-
Exit Sub
-
End If
-
-
lstTicketsInfo.DataSource = dsBasketItems
-
lstTicketsInfo.DataBind()
-
-
txtQuantityTotal.Value = m_QuantityTotal.ToString
-
txtPriceTotal.Value = String.Format("{0:##,##0.00;(##,##0.00);0}",
-
m_PriceTotal)
-
-
End Sub
-
-
Protected Sub lstTicketsInfo_ItemDataBound(ByVal sender As Object, ByVal e
-
As System.Web.UI.WebControls.DataListItemEventArgs) Handles
-
lstTicketsInfo.ItemDataBound
-
-
gvBasket = CType(e.Item.FindControl("gvBasket"),
-
System.Web.UI.WebControls.GridView)
-
LoadDetailData(gvBasket, _
-
CType(CType(e.Item.FindControl("lblEventID"),
-
Label).Text, Integer), _
-
CType(e.Item.FindControl("lblD13_D05_IDs"), Label).Text)
-
-
End Sub
-
-
Protected Sub lstTicketsInfo_ItemCreated(ByVal sender As Object, ByVal e
-
As System.Web.UI.WebControls.DataListItemEventArgs) Handles
-
lstTicketsInfo.ItemCreated
-
-
Dim gvInnerBasket As GridView = CType(e.Item.FindControl("gvBasket"),
-
GridView)
-
AddHandler gvInnerBasket.RowCommand, AddressOf gvBasket_RowCommand
-
-
End Sub
-
-
Private Sub LoadDetailData(ByRef gvBasket As GridView, ByVal nEventId As
-
Integer, ByVal sD13_D05_IDs As String)
-
-
Dim dsTickets As New DataSet
-
With dsTickets
-
.Tables.Add("Tickets")
-
With .Tables(0).Columns
-
.Add("Quantity", GetType(String))
-
.Add("Price", GetType(String))
-
.Add("Total", GetType(String))
-
.Add("EventID", GetType(Integer))
-
.Add("D13_D05_IDs", GetType(String))
-
.Add("E01_i03_id", GetType(Integer))
-
.Add("E01_index", GetType(Integer))
-
End With
-
End With
-
-
For Each ticket As helperclasses.Ticket In
-
colBasketItems(nEventId.ToString & "~" & sD13_D05_IDs)
-
Dim dr As DataRow = dsTickets.Tables(0).NewRow()
-
With ticket
-
dr("Price") = String.Format("{0:##,##0.00;(##,##0.00);0}", .Price +
-
..ServiceCharge)
-
If .Section = "" Then
-
dr("Quantity") = .E01_index.ToString
-
Else
-
dr("Quantity") = colBasketItems(nEventId.ToString & "~" &
-
sD13_D05_IDs).Count
-
End If
-
dr("Total") = String.Format("{0:##,##0.00;(##,##0.00);0}", (.Price +
-
..ServiceCharge) * .E01_index)
-
dr("EventID") = nEventId.ToString
-
dr("D13_D05_IDs") = sD13_D05_IDs
-
dr("E01_i03_id") = .E01_i03_id
-
dr("E01_index") = .E01_index
-
End With
-
dsTickets.Tables(0).Rows.Add(dr)
-
Next
-
-
If Not CBool(dsTickets.Tables(0).Rows.Count) Then
-
Exit Sub
-
End If
-
-
m_QuantitySubTotal = 0
-
m_PriceSubTotal = 0
-
-
gvBasket.DataSource = dsTickets
-
gvBasket.DataBind()
-
-
m_QuantityTotal += m_QuantitySubTotal
-
m_PriceTotal += m_PriceSubTotal
-
-
End Sub
-
-
Protected Sub gvBasket_RowDataBound(ByVal sender As Object, ByVal e As
-
System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvBasket.RowDataBound
-
-
If e.Row.RowType = DataControlRowType.DataRow Then
-
m_QuantitySubTotal +=
-
CType(Val(CType(e.Row().FindControl("txtQuantity"), HtmlInputText).Value),
-
Integer)
-
m_PriceSubTotal +=
-
CType(Val(CType(e.Row().FindControl("lblTotalSingle"), Label).Text), Double)
-
ElseIf e.Row.RowType = DataControlRowType.Footer Then
-
CType(e.Row.FindControl("txtQuantityTotal"), HtmlInputText).Value =
-
m_QuantitySubTotal.ToString
-
CType(e.Row.FindControl("txtPriceTotal"), HtmlInputText).Value =
-
String.Format("{0:##,##0.00;(##,##0.00);0}", m_PriceSubTotal)
-
End If
-
-
End Sub
-
-
Protected Sub gvBasket_RowCommand(ByVal sender As Object, ByVal e As
-
System.Web.UI.WebControls.GridViewCommandEventArgs) Handles
-
gvBasket.RowCommand
-
-
If e.CommandName = "Delete" Then
-
colBasketItems(Split(e.CommandArgument.ToString,
-
"|")(0)).Remove(Split(e.CommandArgument.ToString, "|")(1))
-
LoadMasterData()
-
End If
-
-
End Sub
-
-
Protected Sub DeleteTicket(ByVal sender As Object, ByVal e As
-
System.Web.UI.WebControls.CommandEventArgs)
-
-
colBasketItems(Split(e.CommandArgument.ToString,
-
"|")(0)).Remove(Split(e.CommandArgument.ToString, "|")(1))
-
LoadMasterData()
-
-
End Sub
-
End Class
-
Hi,
You need not have to handle your ItemCreated event for the datalist and
also it is not necessary to create an event handler for the rowCommand of the
grid view.
You cld take a look at my sample code for the same.
Html:
<asp:DataList ID="dlDataList" runat="Server"
OnItemDataBound="dlDataList_ItemDataBound">
<ItemTemplate>
<asp:GridView ID="gvMyGridView_1" runat="server"
OnRowCommand="gvMyGridView_1_RowCommand"
AutoGenerateColumns="false" >
<Columns>
<asp:BoundField DataField="col2" HeaderText="InnerCol1" />
<asp:BoundField DataField="col3" HeaderText="InnerCol2"/>
<asp:ButtonField ButtonType="button"
CommandName="test" Text="delete"
HeaderText="Delete" />
</Columns>
</asp:GridView>
</ItemTemplate>
</asp:DataList>
Source Code C#:
// I am using the same datatable for both the girdView and the
datalist,
// but that shd not have any effect here..
DataTable dt = new DataTable();
protected void Page_Load(object sender, EventArgs e)
{
dt.Columns.Add("col1");
dt.Columns.Add("col2");
dt.Columns.Add("col3");
DataRow dr = dt.NewRow();
dr[0] = "A11";
dr[1] = "A12";
dr[2] = "A13";
dt.Rows.Add(dr);
dr = dt.NewRow();
dr[0] = "A21";
dr[1] = "A22";
dr[2] = "A23";
dt.Rows.Add(dr);
dr = dt.NewRow();
dr[0] = "A31";
dr[1] = "A32";
dr[2] = "A33";
dt.Rows.Add(dr);
if (! IsPostBack)
{
dlDataList.DataSource = dt;
dlDataList.DataBind();
}
}
protected void dlDataList_ItemDataBound(object sender, DataListItemEventArgs
e)
{
if (e.Item.ItemType == ListItemType.AlternatingItem ||
e.Item.ItemType == ListItemType.Item)
{
((GridView)e.Item.FindControl("gvMyGridView_1")).D ataSource
= dt;
((GridView)e.Item.FindControl("gvMyGridView_1")).D ataBind();
}
}
public void gvMyGridView_1_RowCommand(object sender,
GridViewCommandEventArgs e)
{
if (e.CommandName == "test")
Response.Write("My rowCommand jus fired");
}
The code above works fine...
Probably jus try removing the itemCreated event of the datalist and re-run
your code.
I guess the rest of it is completely fine.
Let me know how it goes.....
- Parvathy Padmanabhan
thanks for your herp Parvathy Padmanabhan!
The ItemCreated event is just for testing in order to make that event work!
I'll try tomorrow and I'll let you know!
found that!
it was not working because I had enableviewstate="false" on the datalist This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Tim_Mac |
last post by:
hi,
i'm new to .net 2.0, and am just starting to get to grips with the
gridview.
my page has autoEventWireUp set to true, which i gather is supposed to
figure out which handlers to invoke when...
|
by: luisxx |
last post by:
WinSrv2003 SP1
IIS 6.0
ASP.NET C#, 2.0
SQL 2005
All on same machine
Hello everyone!
I have a method in ASP.NET 2.0 that I can't seem to get right,
Gridview1_rowcommand.
|
by: Mike P |
last post by:
When you specify updateparameters or deleteparameters for your gridview,
I was under the impression that whether or not you write some code in
the rowcommand event to deal with this, the update or...
|
by: Chris Davoli |
last post by:
I've got two questions on how to do things in the new GridView. I'm used to
the DataGrid in ASP 1.1, so I need the equavalent in ASP 2.0 Gridview.
1.) What is the equavalent for Item Command...
|
by: Kevin Attard |
last post by:
I am using a GridView inside a UserControl which has a template column for
deleting the rows. Before databinding the gridview i am attaching the
RowCommand and RowDataBound event.
I am using the...
|
by: Gabriel |
last post by:
Hello,
Is there a way to add a Textbox to a GridView ? I'd like one TextBox by
record.
Thanks,
|
by: HockeyFan |
last post by:
protected void gvAuthorizedSigners_RowCommand(object sender,
GridViewCommandEventArgs e)
{
if (e.CommandName == "EmptyInsert")
{
odsAuthorizedSigners.Insert();
return;
}
if (e.CommandName...
|
by: jrnail23 |
last post by:
I have a user control which contains an UpdatePanel, which contains a
MultiView inside, with a GridView in one of the views.
In my GridView, I have a ButtonField which is supposed to trigger a...
|
by: =?Utf-8?B?SlA=?= |
last post by:
<asp:GridView ID="gridResults" runat="server" AutoGenerateColumns="False"
Width="98%" PageSize="25" AllowPaging="True" OnSorting="gridResults_Sorting"
OnPageIndexChanging...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |