Accessing InfoPath Secondary DataSource and Requerying An example of how you can programmatically access an InfoPath secondary DataSource and use it requery with a new value. //Construct a new command for the second dropdown listbox using a Where clause... XDocument.DataObjects("SecondaryDataSourceName ").QueryAdapter.Command = originalSQLQuery1 + " WHERE Items='" + TestValue + "'" //Requery the data source XDocument.DataObjects("SecondaryDataSourceName").Query(); //Force the view to refresh XDocument.View.ForceUpdate();
11:00:01 PM |
comment [] trackback [] |
Programatically Creating a DataGrid Someone recently asked me how you can programmatically create a DataGrid. So here is an example that I put together.
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 DataGrid1.BorderWidth = Unit.Pixel(2) DataGrid1.CellPadding = 10 DataGrid1.GridLines = GridLines.Both DataGrid1.BorderColor = Color.Blue DataGrid1.ShowHeader = True DataGrid1.AutoGenerateColumns = False DataGrid1.SelectedItemStyle.BackColor = Color.Yellow 'add bound columns to the datagrid Dim datagridcol As New BoundColumn datagridcol.HeaderText = "Candy Type" datagridcol.DataField = "CandyType" DataGrid1.Columns.Add(datagridcol) datagridcol = New BoundColumn datagridcol.HeaderText = "Description" datagridcol.DataField = "CandyDescription" DataGrid1.Columns.Add(datagridcol) Dim selectcol As New ButtonColumn selectcol.ButtonType = ButtonColumnType.PushButton selectcol.Text = "Purchase" selectcol.CommandName = "Select" DataGrid1.Columns.Add(selectcol) 'bind datagrid DataGrid1.DataSource = GetDataSet() DataGrid1.DataBind() 'add datagrid to the page Page.Controls(1).Controls.Add(DataGrid1) End Sub Private Function GetDataSet() Dim ws As New localhost.SweetsService Dim ds As New DataSet ds = ws.GetCandyInfo("truffles") Return ds End Function End Class
9:40:06 PM |
comment [] trackback [] |
Adding a checkbox column to a DataGrid Let’s start with a DataGrid that binds to a DataSet that is returned from a Web Service using the following code.
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 Dim ws As New localhost.SweetsService Dim ds As New DataSet
ds = ws.GetCandyInfo("truffles") DataGrid1.DataSource = ds DataGrid1.DataBind()
End Sub
When the page loads, the DataSet is returned and bound to the DataGrid and appears like the following.
For this example, we want to add a custom checkbox control to this DataGrid control. The following steps show one of several ways that is can be done.
When you run the page the checkbox now appears in the DataGrid.
9:06:55 PM |
comment [] trackback [] |