This article will create a DataGrid containing the CheckBox control, which allows you to select multiple columns for detailed browsing. If you have not recovered any way to obtain this function for dynamic SQL statements, you must use the IN operation.
At the end of the article, we wrote an SQL Server user-defined function (UDF), in order to break a string into sub-strings with delimiters. In this article, we can see how such a UDF works. We will create a web form where you can select some records in the DataGrid by selecting the checkbox control. Details of these checked records will appear in another DataGrid in the form. This form is like.
The following shows the ASPX used to create a form. Note: How to Use the TemplateColumn and Checkbox controls to add a DataGrid column. We also use the DataKeyField attribute of the DataGrid to tell the object which field recorded in the database will contain the keyword identifier of the first line.
<Form id = "Form1" method = "post" runat = "server">
<Asp: DataGrid id = "DataGrid1" runat = "server"
AutoGenerateColumns = "False" DataKeyField = "EmployeeID">
<Columns>
<Asp: TemplateColumn>
<ItemTemplate>
<Asp: CheckBox runat = "server" ID = "EmployeeCheckBox"/>
</ItemTemplate>
</Asp: TemplateColumn>
<Asp: TemplateColumn>
<ItemTemplate>
<% # DataBinder. Eval (Container. DataItem, "LastName") %>,
<% # DataBinder. Eval (Container. DataItem, "FirstName") %>
</ItemTemplate>
</Asp: TemplateColumn>
</Columns>
</Asp: DataGrid>
<Hr>
<Asp: Button id = "Orders" runat = "server" Text = "View Orders"> </asp: Button>
<Hr>
<Asp: DataGrid ID = "DataGrid2" Runat = "server" AutoGenerateColumns = "True"/>
</Form>
When loading and initializing a form, you need to assemble the top DataGrid. The Code uses the Enterprise Library to access the SQL Sever Northwind instance database and runs the "SELECT EmployeeID, FirstName, LastName FROM Employees" statement. The code for loading an event is as follows: