Feb 01, 2010, 7:26 PM
save more than two dynamic gridpanels with one button
<DIV class=forum-post>Hello,
I have more than two GridPanel's which I build dynamic in my PageLoad Method.
I would like to save these GridPanel's with one Button.
Could anybody help me how I can save more than two GridPanel's with one Button?
<DIV class=forum-code><%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="WebApp" enableSessionState="True" %>
<%@ Register assembly="System.Web.Entity, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" namespace="System.Web.UI.WebControls" tagprefix="asp" %>
<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="cc1" %>
<%@ Register assembly="Coolite.Ext.Web" namespace="Coolite.Ext.Web" tagprefix="ext" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>
<asp:Literal id="ltlTitle" Text="Coolite" Runat="Server"></asp:Literal>
</title>
</head>
<body>
<form id="frmMain" runat="server">
<asp:ScriptManager ID="ScriptManager" runat="server" ScriptMode="Debug"></asp:ScriptManager>
<ext:ScriptManager ID="CooliteScriptManager" runat="server"></ext:ScriptManager>
<table width="100%">
<tr>
<td width="80%" align="left">
<asp:MultiView ID="mv" runat="server">
<asp:View ID="vMain" runat="server">
<br />
</asp:View>
</asp:MultiView>
</td>
</tr>
</table>
</form>
</body>
</html>
<script>
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'**********
'* Report *
'**********
Dim btSave As New Coolite.Ext.Web.Button()
btSave.ID = "Save"
btSave.Text = "Save"
mv.SetActiveView(vMain)
' Hauptelement für Zielabfrage einbauen und dieses als neue Root setzen.
Dim targetRootElement As System.Web.UI.Control
targetRootElement = Me.FindControl("vMain")
Dim pnl As New Panel
pnl.ID = "pnlTargetsMain"
'TARGETROOTELEMENT
If (targetRootElement.FindControl(pnl.ID) Is Nothing) Then
targetRootElement.Controls.Add(pnl)
End If
targetRootElement = Me.FindControl("pnlTargetsMain")
'************************
'* Dynamische REPORTs *
'************************
Dim sButtonHandler As String = ""
Dim dt() As Integer = New Integer() {1, 2, 3}
If Not dt.Count = 0 Then
Dim Store_dyn(dt.Length) As Coolite.Ext.Web.Store
Dim Grid_dyn(dt.Length) As Coolite.Ext.Web.GridPanel
For Each dr As Integer In dt
pnl = New Panel()
pnl.ID = "Panel_" & dr.ToString()
pnl.BackColor = Drawing.Color.AliceBlue
pnl.Style.Add("background-color", "#FFFFCC")
pnl.Style.Add("cursor", "pointer")
Dim NameLabel = New Label()
NameLabel.ID = "LabelName_" & dr.ToString()
NameLabel.Text = dr.ToString()
NameLabel.ToolTip = "LabelName" & dr.ToString()
pnl.Controls.Add(NameLabel)
'TARGETROOTELEMENT
If (targetRootElement.FindControl(pnl.ID) Is Nothing) Then
targetRootElement.Controls.Add(pnl)
End If
pnl = New Panel()
pnl.ID = "Panel2_" & dr
pnl.Style.Add("background-color", "#EFEFEF")
pnl.Style.Add("overflow", "hidden")
Dim DescriptionLabel = New Label()
DescriptionLabel.ID = "LabelName2_" & dr.ToString()
DescriptionLabel.Text = dr.ToString()
DescriptionLabel.ToolTip = "LabelName2" & dr.ToString()
pnl.Controls.Add(DescriptionLabel)
'TARGETROOTELEMENT
If (targetRootElement.FindControl(pnl.ID) Is Nothing) Then
targetRootElement.Controls.Add(pnl)
End If
Dim ExtCollapsiblePanel As AjaxControlToolkit.CollapsiblePanelExtender
ExtCollapsiblePanel = New AjaxControlToolkit.CollapsiblePanelExtender
ExtCollapsiblePanel.ID = "CollapsiblePanelExtenderID_" & dr.ToString()
ExtCollapsiblePanel.TargetControlID = "Panel2_" & dr.ToString()
ExtCollapsiblePanel.ExpandControlID = "Panel_" & dr.ToString()
ExtCollapsiblePanel.CollapseControlID = "Panel_" & dr.ToString()
ExtCollapsiblePanel.Enabled = True
'TARGETROOTELEMENT
If (targetRootElement.FindControl(ExtCollapsiblePanel.ID) Is Nothing) Then
targetRootElement.Controls.Add(ExtCollapsiblePanel)
End If
Dim Coolitepnl = New Coolite.Ext.Web.Panel()
Coolitepnl.ID = "Coolitepnl_" & dr.ToString()
Dim formpnl = New Coolite.Ext.Web.FormPanel()
formpnl.ID = "FormPanel_" & dr.ToString()
Dim formlayout = New Coolite.Ext.Web.FormLayout()
formlayout.ID = "LayoutForm_" & dr.ToString()
Dim Company = New Coolite.Ext.Web.TextField()
Company.ID = "Company_" & dr.ToString()
Company.Width = 1000
Company.DataIndex = "company"
Company.FieldLabel = "Company"
Company.ReadOnly = True
formlayout.Anchors.Add(Company)
formpnl.BodyControls.Add(formlayout)
Coolitepnl.BodyControls.Add(formpnl)
'TARGETROOTELEMENT
If (targetRootElement.FindControl(Coolitepnl.ID) Is Nothing) Then
targetRootElement.Controls.Add(Coolitepnl)
End If
'************************
'* STORE *
'************************
Store_dyn(dr) = New Coolite.Ext.Web.Store()
Store_dyn(dr).ID = "Store_" & dr.ToString()
'Store_dyn(dr).AutoDataBind = True
If dr = 1 Then
Store_dyn(dr).DataSource = New Object() {New Object() {"3m Co", 71.72, 0.02, 0.03}, _
New Object() {"Alcoa Inc", 29.01, 0.42, 1.47}, _
New Object() {"Altria Group Inc", 83.81, 0.28, 0.34}, _
New Object() {"American Express Company", 52.55, 0.01, 0.02}, _
New Object() {"American International Group, Inc.", 64.13, 0.31, 0.49}}
ElseIf dr = 2 Then
Store_dyn(dr).DataSource = New Object() {New Object() {"AT&T Inc.", 31.61, -0.48, -1.54}, _
New Object() {"Boeing Co.", 75.43, 0.53, 0.71}, _
New Object() {"Caterpillar Inc.", 67.27, 0.92, 1.39}, _
New Object() {"Citigroup, Inc.", 49.37, 0.02, 0.04}}
ElseIf dr = 3 Then
Store_dyn(dr).DataSource = New Object() {New Object() {"E.I. du Pont de Nemours and Company", 40.48, 0.51, 1.28}}
End If
'Store_dyn(dr).DataBind()
Store_dyn(dr).Enabled = True
Store_dyn(dr).GroupField = "company"
Store_dyn(dr).UseIdConfirmation = True
Store_dyn(dr).RefreshAfterSaving = Coolite.Ext.Web.RefreshAfterSavingMode.Always
AddHandler Store_dyn(dr).AfterRecordUpdated, AddressOf Store_AfterRecordUpdated
Dim ArrayReader As Coolite.Ext.Web.ArrayReader
ArrayReader = New Coolite.Ext.Web.ArrayReader()
ArrayReader.ReaderID = "JsonReader_" & dr.ToString()
Dim companyIdS As Coolite.Ext.Web.RecordField
companyIdS = New Coolite.Ext.Web.RecordField()
companyIdS.Name = "company"
Dim priceIdS As Coolite.Ext.Web.RecordField
priceIdS = New Coolite.Ext.Web.RecordField()
priceIdS.Name = "price"
Dim changeIdS As Coolite.Ext.Web.RecordField
changeIdS = New Coolite.Ext.Web.RecordField()
changeIdS.Name = "change"
changeIdS.Type = Coolite.Ext.Web.RecordFieldType.Float
Dim pctChangeIdS As Coolite.Ext.Web.RecordField
pctChangeIdS = New Coolite.Ext.Web.RecordField()
pctChangeIdS.Name = "pctChange"
pctChangeIdS.Type = Coolite.Ext.Web.RecordFieldType.Float
ArrayReader.Fields.Add(companyIdS)
ArrayReader.Fields.Add(priceIdS)
ArrayReader.Fields.Add(changeIdS)
ArrayReader.Fields.Add(pctChangeIdS)
Dim SortInfo As Coolite.Ext.Web.SortInfo
SortInfo = New Coolite.Ext.Web.SortInfo()
SortInfo.Field = "company"
Store_dyn(dr).SortInfo = SortInfo
Store_dyn(dr).SortInfo.Direction = Coolite.Ext.Web.SortDirection.ASC
Store_dyn(dr).Reader.Add(ArrayReader)
'---------------------------------------------------------------------------------
'TARGETROOTELEMENT
If (targetRootElement.FindControl(Store_dyn(dr).ID) Is Nothing) Then
targetRootElement.Controls.Add(Store_dyn(dr))
End If
'************************
'* GRID PANEL *
'************************
Grid_dyn(dr) = New Coolite.Ext.Web.GridPanel()
Grid_dyn(dr).ID = "Grid_" & dr.ToString()
Grid_dyn(dr).StoreID = "Store_" & dr.ToString()
Grid_dyn(dr).DataBind()
Grid_dyn(dr).Height = 250
Grid_dyn(dr).AutoDataBind = True
Grid_dyn(dr).AutoHeight = True
Grid_dyn(dr).Enabled = True
Grid_dyn(dr).Frame = True
Grid_dyn(dr).Visible = True
Dim companyIdG As Coolite.Ext.Web.ColumnBase
companyIdG = New Coolite.Ext.Web.Column()
companyIdG.Header = "company"
companyIdG.DataIndex = "company"
Dim priceIdG As Coolite.Ext.Web.ColumnBase
priceIdG = New Coolite.Ext.Web.Column()
priceIdG.Header = "price"
priceIdG.DataIndex = "price"
Dim changeIdG As Coolite.Ext.Web.ColumnBase
changeIdG = New Coolite.Ext.Web.Column()
changeIdG.Header = "change"
changeIdG.Width = 100
changeIdG.DataIndex = "change"
Dim changeIdE As Coolite.Ext.Web.Field
changeIdE = New Coolite.Ext.Web.TextField()
changeIdE.ID = "change" & dr.ToString()
changeIdG.Editor.Add(changeIdE)
Dim pctChangeIdG As Coolite.Ext.Web.ColumnBase
pctChangeIdG = New Coolite.Ext.Web.Column()
pctChangeIdG.Header = "pctChange"
pctChangeIdG.Width = 100
pctChangeIdG.DataIndex = "pctChange"
Dim pctChangeIdE As Coolite.Ext.Web.Field
pctChangeIdE = New Coolite.Ext.Web.TextField()
pctChangeIdE.ID = "pctChange" & dr.ToString()
pctChangeIdG.Editor.Add(pctChangeIdE)
Grid_dyn(dr).ColumnModel.Columns.Add(companyIdG)
Grid_dyn(dr).ColumnModel.Columns.Add(priceIdG)
Grid_dyn(dr).ColumnModel.Columns.Add(changeIdG)
Grid_dyn(dr).ColumnModel.Columns.Add(pctChangeIdG)
Dim CommandColumn As Coolite.Ext.Web.CommandColumn
CommandColumn = New Coolite.Ext.Web.CommandColumn()
CommandColumn.Hidden = "true"
Dim GridCommand As Coolite.Ext.Web.GridCommand
GridCommand = New Coolite.Ext.Web.GridCommand()
GridCommand.CommandName = "company"
Dim CommandFill As Coolite.Ext.Web.CommandFill
CommandFill = New Coolite.Ext.Web.CommandFill()
CommandColumn.Commands.Add(CommandFill)
CommandColumn.GroupCommands.Add(GridCommand)
Grid_dyn(dr).ColumnModel.Columns.Add(CommandColumn)
Dim GroupView As Coolite.Ext.Web.GroupingView
GroupView = New Coolite.Ext.Web.GroupingView()
GroupView.ID = "GroupView_" & dr.ToString()
GroupView.GroupByText = "{text} ({[values.rs.length]} {[values.rs.length > 1 ? ""Items"" : ""Item""]})"
GroupView.EnableRowBody = True
GroupView.ForceFit = True
GroupView.StartCollapsed = False
Grid_dyn(dr).View.Add(GroupView)
Dim RowSelection As Coolite.Ext.Web.RowSelectionModel
RowSelection = New Coolite.Ext.Web.RowSelectionModel()
RowSelection.ID = "RowSelection_" & dr.ToString()
RowSelection.Listeners.RowSelect.Handler = "#{FormPanel_" & dr.ToString() & "}.getForm().loadRecord(record);"
Grid_dyn(dr).SelectionModel.Add(RowSelection)
'Add the GridPanel to save!!!
sButtonHandler = sButtonHandler + "#{Grid_" & dr.ToString() & "}.save();"
'TARGETROOTELEMENT
If (targetRootElement.FindControl(Grid_dyn(dr).ID) Is Nothing) Then
targetRootElement.Controls.Add(Grid_dyn(dr))
End If
targetRootElement.DataBind()
Next dr
btSave.OnClientClick = sButtonHandler
'TARGETROOTELEMENT
If (targetRootElement.FindControl(btSave.ID) Is Nothing) Then
targetRootElement.Controls.Add(btSave)
End If
End If
End Sub
Public Sub Store_AfterRecordUpdated(ByVal sender As Object, ByVal e As Coolite.Ext.Web.AfterRecordUpdatedEventArgs)
Dim bSave As New Boolean
bSave = True
If Not IsNumeric(e.NewValues("company")) Then
e.Confirmation.Confirm = False
bSave = False
End If
If Not IsNumeric(e.NewValues("price")) Then
e.Confirmation.Confirm = False
bSave = False
End If
If bSave Then
If (Not (e.NewValues("company").ToString().Equals("") And e.NewValues("price").ToString().Equals(""))) Then
Dim conn As New SqlConnection
Try
conn.ConnectionString = "Data Source..."
conn.Open()
Dim cmdSQL As New SqlCommand
cmdSQL.Connection = conn
cmdSQL.CommandText = "insertValue" ' Stored Procedure to Call
cmdSQL.CommandType = CommandType.StoredProcedure ' Setup Command Type
cmdSQL.Parameters.Add(New SqlClient.SqlParameter("company", SqlDbType.VarChar, 100, ParameterDirection.Input, False, 30, 0, "", DataRowVersion.Default, e.NewValues("company")))
cmdSQL.Parameters.Add(New SqlClient.SqlParameter("price", SqlDbType.VarChar, 100, ParameterDirection.Input, False, 30, 0, "", DataRowVersion.Default, e.NewValues("price")))
cmdSQL.Parameters.Add(New SqlClient.SqlParameter("change", SqlDbType.Int, 10, ParameterDirection.Input, False, 30, 0, "", DataRowVersion.Default, e.NewValues("change")))
cmdSQL.Parameters.Add(New SqlClient.SqlParameter("pctChange", SqlDbType.Int, 10, ParameterDirection.Input, False, 30, 0, "", DataRowVersion.Default, e.NewValues("pctChange")))
cmdSQL.ExecuteNonQuery()
Catch exc As Exception
MsgBox("ERROR: " + exc.Message)
Finally
conn.Close()
End Try
End If
End If
End Sub
</script>
</PRE>Thanks a lot. I'm very grateful for any answers I get!
With best regards,
Stephan