imsse
Messages postés37Date d'inscriptionmercredi 21 janvier 2004StatutMembreDernière intervention 7 avril 2008
-
15 mai 2007 à 17:49
imsse
Messages postés37Date d'inscriptionmercredi 21 janvier 2004StatutMembreDernière intervention 7 avril 2008
-
16 mai 2007 à 12:48
Bonjour,
Es ce possible de contruire avec du code C# et non de l'asp des controles web ?
J'aimerai en fait au changement de ma combox box charger sur ma page un datagrid, qui n'a pas la meme structure selon la selection de ma combo box.
C'est à dire que se serait un datagrid avec un nombre de colone différent , des entetes différente ....
mais jaimerai le positioner a chaque fois sur le meme emplacement dans ma page aspx.
Jusqua présent je faisait comme sa en declarant mon datagrid :
#Region " Vom Web Form Designer generierter Code "
'Dieser Aufruf ist für den Web Form-Designer erforderlich.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
End Sub
'HINWEIS: Die folgende Platzhalterdeklaration ist für den Web
Form-Designer erforderlich.
'Nicht löschen oder verschieben.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: Dieser Methodenaufruf ist für den Web Form-Designer
erforderlich
'Verwenden Sie nicht den Code-Editor zur Bearbeitung.
InitializeComponent()
End Sub
#End Region
Dim mGrid As DataGrid
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
CreateGrid()
End Sub
Public Sub CreateGrid()
'declare a new datagrid and set properties
mGrid = New DataGrid
mGrid.ID = "234"
mGrid.BorderWidth = Unit.Pixel(2)
mGrid.CellPadding = 10
mGrid.GridLines = GridLines.Both
mGrid.BorderColor = Color.Blue
mGrid.ShowHeader = True
mGrid.AutoGenerateColumns = False
mGrid.SelectedItemStyle.BackColor = Color.Yellow
'add bound columns to the datagrid
Dim datagridcol As New BoundColumn
datagridcol.HeaderText = "Column1"
datagridcol.DataField = "Column1"
mGrid.Columns.Add(datagridcol)
'add datagrid to the page
Page.Controls(1).Controls.Add(mGrid)
End Sub
Public Function GetDataSet() As DataTable
Dim dTable As Data.DataTable = Session.Item("DataTable")
If dTable Is Nothing Then
dTable = New Data.DataTable
Dim dCol1 As New Data.DataColumn("Column1")
Dim dCol2 As New Data.DataColumn("Column2")
Session.Add("DataTable", dTable)
End If
Return dTable
End Function
Private Sub DataGrid1_UpdateCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs)
Dim tmpGrid As DataGrid = CType(source, DataGrid)
tmpGrid.EditItemIndex = -1
'bind datagrid
tmpGrid.DataSource = GetDataSet()
tmpGrid.DataBind()
End Sub
Private Sub DataGrid1_CancelCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs)
Dim tmpGrid As DataGrid = CType(source, DataGrid)
tmpGrid.EditItemIndex = -1
'bind datagrid
tmpGrid.DataSource = GetDataSet()
tmpGrid.DataBind()
End Sub
Private Sub DataGrid1_EditCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs)
Dim tmpGrid As DataGrid = CType(source, DataGrid)
tmpGrid.EditItemIndex = CInt(e.Item.ItemIndex)
'bind datagrid
tmpGrid.DataSource = GetDataSet()
tmpGrid.DataBind()
End Sub
Protected Overloads Overrides Sub RaisePostBackEvent(ByVal sourceControl As
System.Web.UI.IPostBackEventHandler, ByVal eventArgument As String)
CType(sourceControl, System.Web.UI.WebControls.LinkButton).CommandName =
"Update"
sourceControl.RaisePostBackEvent(eventArgument)