First question how to add custom column to aspxgridview column using looping to get name and value of column.
here is my code behind :
Protected Sub gridSubmission_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles gridSubmission.Init
Dim colBaru As GridViewDataTextColumn = New GridViewDataTextColumn()
For i As Integer = 1 To 6
colBaru.Caption = i
colBaru.FieldName = i
colBaru.UnboundType = DevExpress.Data.UnboundColumnType.Integer
colBaru.VisibleIndex = gridSubmission.VisibleColumns.Count
colBaru.PropertiesTextEdit.DisplayFormatString = "c2"
gridSubmission.Columns.Add(colBaru)
Next
end sub
which i used to add new column at aspxgridview.
but its getting an error, “An item with the same key has already been added.”
second question, what property which i must use to put that code? I wanted load that code after page.load ! if i put in aspxgridview.init its was loaded before page.load.
and the output it must like this :
1 2 3 4 5 6
row row row row row row
row row row row row row
row row row row row row
row row row row row row
row row row row row row
help pelase…
thanks before
As far first question goes, you are trying to add same column object again and again into columns, hence you get that error. Try creating column object in the loop – for example:
As far as second question goes, I am not sure what you are asking here. When you mean before/after page.load, do you mean page_load at server side or page load at client (browser) side? Frankly speaking, grid_init or page_init are the best places to add columns. If you want to add columns in certain event on the page then the best way to do is set some hidden variable on the browser side and use that variable to decide whether to do such initialization or not.