HOW TO: Loop Through and Examine CheckBox Control Values in a DataGrid Column by Using ASP.NET and Visual Basic .NET
Create an ASP.NET Web Application by Using Visual Basic .NET
Start Microsoft Visual Studio .NET.
On the File menu, point to New, and then click Project.
In the New Project dialog box, click Visual Basic Projects under Project Types, and then click ASP.NET Web Application under Templates.
In the Location box, replace the WebApplication# default name with MyWebApp. If you are using the local server, you can leave the server name as http://localhost. The resulting Location box appears as follows:
http://localhost/MyWebApp
Create the Sample Web Form Page
1)Add a new Web Form to the ASP.NET Web application as follows:
Right-click the project node in Solution Explorer, point to Add, and then click Add Web Form.
In the Name box, type MySample.aspx, and then click Open.
2)In the Properties window, change the pageLayout property for the document to FlowLayout. Although you do not have to do this to use the sample code, this will make the presentation appear cleaner.
3)Add a DataGrid, a Button, and a Label server control to the page as follows:
Drag an ASP.NET DataGrid server control from the Web Forms toolbox onto the page.
In the Properties window, change the ID of the DataGrid control to DemoGrid.
Drag an ASP.NET Button server control from the Web Forms toolbox onto the page below the DataGrid.
In the Properties window, change the ID of the Button control to GetSelections, and then change the Text property to Get Selections.
Drag an ASP.NET Label server control from the Web Forms toolbox onto the page below the Button control.
In the Properties window, change the ID of the Label control to ResultsInfo, and then delete any text in the Text property.
4)Switch to HTML view in the editor. Add the code to the default DataGrid template to construct the columns. The resulting code for the control should appear as follows:
<asp:DataGrid id="DemoGrid" runat="server" DataKeyField="CustomerID">
<Columns>
<asp:TemplateColumn HeaderText="Customer">
<ItemTemplate>
<asp:CheckBox ID="myCheckbox" Runat="server" />
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
Start Microsoft Visual Studio .NET.
On the File menu, point to New, and then click Project.
In the New Project dialog box, click Visual Basic Projects under Project Types, and then click ASP.NET Web Application under Templates.
In the Location box, replace the WebApplication# default name with MyWebApp. If you are using the local server, you can leave the server name as http://localhost. The resulting Location box appears as follows:
http://localhost/MyWebApp
Create the Sample Web Form Page
1)Add a new Web Form to the ASP.NET Web application as follows:
Right-click the project node in Solution Explorer, point to Add, and then click Add Web Form.
In the Name box, type MySample.aspx, and then click Open.
2)In the Properties window, change the pageLayout property for the document to FlowLayout. Although you do not have to do this to use the sample code, this will make the presentation appear cleaner.
3)Add a DataGrid, a Button, and a Label server control to the page as follows:
Drag an ASP.NET DataGrid server control from the Web Forms toolbox onto the page.
In the Properties window, change the ID of the DataGrid control to DemoGrid.
Drag an ASP.NET Button server control from the Web Forms toolbox onto the page below the DataGrid.
In the Properties window, change the ID of the Button control to GetSelections, and then change the Text property to Get Selections.
Drag an ASP.NET Label server control from the Web Forms toolbox onto the page below the Button control.
In the Properties window, change the ID of the Label control to ResultsInfo, and then delete any text in the Text property.
4)Switch to HTML view in the editor. Add the code to the default DataGrid template to construct the columns. The resulting code for the control should appear as follows:
<asp:DataGrid id="DemoGrid" runat="server" DataKeyField="CustomerID">
<Columns>
<asp:TemplateColumn HeaderText="Customer">
<ItemTemplate>
<asp:CheckBox ID="myCheckbox" Runat="server" />
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
Labels: DataGrid

0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home