Button in a Repeater in a Datagrid

C

Cuperman

Hi,

I have a button, in a repeater in a datagrid.

I need to get the datagrid itemcommand event to fire when one of the
buttons from within the rpeater is clicked.

I need to obtain the datagrid item index (to swtich to edit mode) and
the button command arguement (in this case the order id - used to load
additional data to populate a form in edit mode)

So far during debugging I am hitting ButtonCommand and Rep_ItemCommand,
but RadGrid1_ItemCommand is not firing. Code provided below as an
example.

Any ideas,
Thanks,
Mark

**************************
<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="WebForm2.aspx.vb" Inherits="WebApplication4.WebForm2" %>
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<title>Test</title>
<LINK href="res/css/Site.css" type=text/css rel=stylesheet >
</head>
<body>
<form id=Form1 method=post runat="server">
<div
xmlns:radg="http://schemas.telerik.com/Intellisense/RadCallback"><radc:callbackpanel

id=Callbackpanel1 runat="server">
<asp:datagrid id="dg" runat="server" autogeneratecolumns="False"
onitemcommand="RadGrid1_ItemCommand">
<columns >
<asp:boundcolumn datafield="customerid" />
<asp:boundcolumn datafield="customerid" />
<asp:templatecolumn >
<itemtemplate >
<asp:repeater id="Repeater" runat="server"
onitemcommand="rep_ItemCommand">
<itemtemplate>
<asp:button runat="server"
text='<%#Databinder.Eval(Container.DataItem, "OrderId")%>' id="edit"
commandargument='<%#Databinder.Eval(Container.DataItem, "OrderId")%>'
oncommand="ButtonCommand"/>
</itemtemplate>
</asp:repeater>
</itemtemplate>
</asp:templatecolumn>
</columns>
</asp:datagrid></radc:callbackpanel><asp:label id=Label1
runat="server">Label</asp:label></DIV></FORM>
</body>
</html>

**************************
Public Class WebForm2
Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.OleDbDataAdapter1 = New System.Data.OleDb.OleDbDataAdapter
Me.OleDbSelectCommand1 = New System.Data.OleDb.OleDbCommand
Me.OleDbConnection1 = New System.Data.OleDb.OleDbConnection
'
'OleDbDataAdapter1
'
Me.OleDbDataAdapter1.SelectCommand = Me.OleDbSelectCommand1
Me.OleDbConnection1.ConnectionString =
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
Server.MapPath("nwind.mdb") & ";"

'
'OleDbSelectCommand1
'
Me.OleDbSelectCommand1.CommandText = "SELECT Top 5 * FROM customers"
Me.OleDbSelectCommand1.Connection = Me.OleDbConnection1

End Sub
Protected WithEvents dg As System.Web.UI.WebControls.DataGrid
Protected WithEvents OleDbDataAdapter1 As
System.Data.OleDb.OleDbDataAdapter
Protected WithEvents OleDbSelectCommand1 As
System.Data.OleDb.OleDbCommand
Protected WithEvents OleDbConnection1 As
System.Data.OleDb.OleDbConnection
Protected WithEvents Callbackpanel1 As
Telerik.WebControls.CallbackPanel
Protected WithEvents Label1 As System.Web.UI.WebControls.Label

'NOTE: The following placeholder declaration is required by the Web
Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private m_ds As DataSet
Private m_arrL As ArrayList

Private Property DataSource() As DataSet
Get
m_ds = New DataSet
m_ds.Clear()
OleDbDataAdapter1.Fill(m_ds, "Customers")
Return m_ds
End Get
Set(ByVal Value As DataSet)
m_ds = Value
End Set
End Property

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not Page.IsPostBack Then DgLoad()
End Sub

Private Sub DgLoad()
dg.DataSource = Me.DataSource
dg.DataBind()
End Sub

Public Sub RadGrid1_ItemCommand(ByVal s As System.Object, ByVal e As
DataGridCommandEventArgs)
If TypeOf e.Item Is GridDataItem Then
Select Case e.CommandName
Case "EditOrder"
dg.EditItemIndex = e.Item.ItemIndex
dg.DataBind()

End Select

End If
End Sub

Private Sub RadGrid1_UpdateCommand(ByVal source As System.Object,
ByVal e As DataGridCommandEventArgs) Handles dg.UpdateCommand
If TypeOf (e.Item) Is DataGridItem Then
'do something
End If
End Sub

Private Sub RadGrid1_ItemDataBound(ByVal s As System.Object, ByVal e
As DataGridItemEventArgs) Handles dg.ItemDataBound

'Private Sub RadGrid1_ItemCreated(ByVal s As Object, ByVal e As
Telerik.WebControls.GridItemEventArgs) Handles dg.ItemCreated
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType =
ListItemType.AlternatingItem Then

'for each item in the datatable, I need to load some 'child'
objects.
'In this example I am using orders.
'Each order will be represented by a button.
'when clicked the button needs to put data into the
EditUserControl...

'open the child dataaset
Dim ds As New DataSet
Dim da As New OleDb.OleDbDataAdapter
Dim cmd As New OleDb.OleDbCommand
cmd.CommandText = "SELECT Top 5 * FROM Orders WHERE
CustomerId=@CustomerId;"
cmd.Parameters.Add(New OleDb.OleDbParameter("@CustomerId",
e.Item.DataItem("CustomerId")))
cmd.Connection = OleDbConnection1

da.SelectCommand = cmd
da.Fill(ds, "Foobar")

Dim gDataItem As DataGridItem = e.Item
Dim rep As Repeater = e.Item.Cells(2).FindControl("Repeater")
rep.DataSource = ds
rep.DataBind()

End If
End Sub

Public Sub rep_ItemCommand(ByVal s As Object, ByVal e As
System.Web.UI.WebControls.RepeaterCommandEventArgs)
'do something
End Sub

Public Sub ButtonCommand(ByVal s As Object, ByVal e As
CommandEventArgs)
'do something
End Sub


End Class

**************************
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top