Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
345
How to add row with dynamically created columns?
posted

I'm using version 9.2.20092.1003. Trying to switch from ultrawebgrid to webdatagrid and need to create a simple webdatagrid with CRUD.

I'm dynamically adding columns. My grid can update and delete with no problems. The problem is with adding a new row using the blank new row at the bottom. It saves a blank row with the ID field populated but won't save anything I type in the fields. What am I missing? Thanks!

If I specify columns in the design, then I don't have this problem. Does automatic add row work with dynamic columns?

My aspx.vb looks like:

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        SqlDataSource1.SelectCommand = "SELECT TestCol2, TestCol3, TestCol4, ModifiedBy, ModifiedOn, TestCol1 FROM [TestTable]"
        CreateColumns()
    End Sub

    Private Sub CreateColumns()
        If Not Page.IsPostBack Then
            AddColumn("TestCol2", "Test Col 2", False)
            AddColumn("TestCol3", "Test Col 3", False)
            AddColumn("TestCol4", "Test Col 4", False)
            AddColumn("ModifiedBy", "Modified By", False)
            AddColumn("ModifiedOn", "Modified On", False)
            AddColumn("TestCol1", "TestCol1", True)

        End If
    End Sub

    Private Sub AddColumn(ByVal FieldName As String, ByVal HeaderText As String, ByVal AmIHidden As Boolean)
        Dim NewField As BoundDataField = New BoundDataField(True)
        NewField.Key = "Key_" & FieldName
        NewField.DataFieldName = FieldName
        NewField.Header.Text = HeaderText
        NewField.Hidden = AmIHidden
        WebDataGrid1.Columns.Add(NewField)
    End Sub

My aspx page has:

   <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <ig:WebDataGrid ID="WebDataGrid1" runat="server" Height="348px" Width="529px"
        AutoGenerateColumns="False" DataSourceID="SqlDataSource1"
        DefaultColumnWidth="150px" DataKeyFields="TestCol1">
        <Behaviors>
            <ig:Activation>
            </ig:Activation>
            <ig:ColumnMoving DragMarkupCssClass="">
            </ig:ColumnMoving>
            <ig:ColumnResizing>
            </ig:ColumnResizing>
            <ig:EditingCore>
                <Behaviors>
                    <ig:RowAdding>
                    </ig:RowAdding>
                    <ig:CellEditing>
                    </ig:CellEditing>
                    <ig:RowDeleting />
                </Behaviors>
            </ig:EditingCore>
            <ig:Selection CellClickAction="Row" RowSelectType="Single">
            </ig:Selection>
            <ig:RowSelectors>
            </ig:RowSelectors>
            <ig:Filtering>
            </ig:Filtering>
            <ig:Paging>
            </ig:Paging>
            <ig:Sorting>
            </ig:Sorting>
        </Behaviors>
    </ig:WebDataGrid>
   
    <asp:Button ID="Button1" runat="server" Text="Save" />
   
    <asp:SqlDataSource ID="SqlDataSource1" runat="server"
        ConnectionString="<%$ ConnectionStrings:AccentaDBConnectionString %>"
        DeleteCommand="DELETE FROM [TestTable] WHERE [TestCol1] = @TestCol1"
        InsertCommand="INSERT INTO [TestTable] ([TestCol2], [TestCol3], [TestCol4], [ModifiedOn], [ModifiedBy]) VALUES (@TestCol2, @TestCol3, @TestCol4, @ModifiedOn, @ModifiedBy)"
        SelectCommand="SELECT * FROM [TestTable]"
        UpdateCommand="UPDATE [TestTable] SET [TestCol2] = @TestCol2, [TestCol3] = @TestCol3, [TestCol4] = @TestCol4, [ModifiedOn] = @ModifiedOn, [ModifiedBy] = @ModifiedBy WHERE [TestCol1] = @TestCol1">
        <DeleteParameters>
            <asp:Parameter Name="TestCol1" Type="Int32" />
        </DeleteParameters>
        <UpdateParameters>
            <asp:Parameter Name="TestCol2" Type="String" />
            <asp:Parameter Name="TestCol3" Type="String" />
            <asp:Parameter Name="TestCol4" Type="Double" />
            <asp:Parameter Name="ModifiedOn" Type="DateTime" />
            <asp:Parameter Name="ModifiedBy" Type="String" />
            <asp:Parameter Name="TestCol1" Type="Int32" />
        </UpdateParameters>
        <InsertParameters>
            <asp:Parameter Name="TestCol2" Type="String" />
            <asp:Parameter Name="TestCol3" Type="String" />
            <asp:Parameter Name="TestCol4" Type="Double" />
            <asp:Parameter Name="ModifiedOn" Type="DateTime" />
            <asp:Parameter Name="ModifiedBy" Type="String" />
        </InsertParameters>
    </asp:SqlDataSource>