Conditional DataGrid Item and using checkboxesUsing datagrid in ASP.NET and having one bound column with checkboxes. This code check certain certain conditions before displaying the grid. Here is the code: <%@ Page EnableSessionState="false" EnableViewState="false" Language="vb" %> <%@ import Namespace="System.Data" %> <%@ import Namespace="System.Data.SqlClient" %>
<script runat="server"> Dim conn as SQLConnection = new SQLConnection(ConfigurationSettings.AppSettings("DSN_Northwind"))
Sub Page_Load(sender As Object, e As EventArgs) Dim sqlText as String Dim ds AS DataSet Dim dbComm AS SQLDataAdapter Dim sqlServer as String
If Not IsPostBack Then sqlText = "select EmployeeID , firstname,lastname from employees" ds = new DataSet() dbComm = New SQLDataAdapter(sqlText,conn) dbComm.Fill(ds,"Employees")
dbGrid.DataSource = ds.Tables("Employees").DefaultView dbGrid.DataBind() End if End Sub
Function myFunc(myInt as Integer) as Boolean If myInt >3 and myInt <7 then Return True Else Return False End if End Function </script> <html> <head> <title></title> </head> <body bgcolor="#FFFFFF"> <form runat=server id=form1 name=form1> <ASP:DataGrid id="MyDataGrid" runat="server" BorderColor="black" BorderWidth="1" GridLines="none" CellPadding="4" Font-Name="Verdana" Font-Size="8pt" HeaderStyle-BackColor="#aaaadd" AutoGenerateColumns="False" > <Columns> <asp:TemplateColumn HeaderText="Quantity"> <ItemTemplate> <asp:checkbox id="mycheckbox" Checked=<%# myFunc(Container.DataItem("EmployeeID") ) %> runat="server" /> </ItemTemplate> </asp:TemplateColumn> <asp:BoundColumn HeaderText="EmployeeID" DataField="EmployeeID"/> <asp:BoundColumn HeaderText="firstname" DataField="firstname"/> <asp:BoundColumn HeaderText="lastname" DataField="lastname"/> </Columns> </asp:DataGrid> </form> </body> </html> Web.Config file <configuration> <appSettings> <add key="DSN" value="server=localhost;uid=sa;pwd=;database=aspfree"> </add> <add key="DSN_NorthWind" value="server=localhost; database=Northwind;Trusted_Connection=Yes" /> </appSettings> </configuration>
|
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |
More ASP Code Articles More By aspfree developerWorks - FREE Tools! | The IBM DB2 Deep Compression ROI tool is designed for DBA’s and IT management personnel to perform a clinical analysis of the cost savings gained from the Storage Optimization feature of DB2 9 for Linux, UNIX and Windows. The feature, also known as Deep Compression, compresses data that lies within a database by up to 80% at times. FREE! Go There Now!
| | | | Learn how you can extend modern application lifecycle management to IBM System z through the IBM Rational Software Delivery Platform (SDP). The Did you say mainframe? e-kit includes podcasts, webcasts, tutorials, white and red papers, demos, and articles designed to help ease the challenges of modernizing your enterprise. This complimentary kit for mainframe developers is a practical, how-to guide for making the most of an existing development environment, including the skills and infrastructure already in place at an established enterprise. FREE! Go There Now!
| | | | Download the Rational Application Developer (RAD) v7.5 open beta code and start developing applications for the JEE5 standard which features EJB3.0, JPA, JSF 1.2, JSP 2.1 and Servlet 2.5 standards. When you use this beta you will see how you can increase developer productivity for already existing applications with improved support for refactoring, as well as adding new features to existing applications. In addition, the beta provides tooling for JD Edwards, Oracle, SAP, Siebel and PeopleSoft to improve the developer productivity with these enterprise systems. FREE! Go There Now!
| | | | In this tutorial, you can learn how to install and configure the IBM Rational Asset Manager Eclipse client, explore the different views in the Asset Management perspective, learn various search techniques, work with existing assets, and submit a new asset. FREE! Go There Now!
| | | | Join this Rational Talks to You teleconference on November 29 at 1:00 pm ET to participate in an interactive discusssion with Grady Booch around architecture and reuse. Get your questions answered! FREE! Go There Now!
| | | | As organizations have grown increasingly dependent on online software, the risk of malicious attacks has also become far more serious. Fortunately, well-governed organizations can protect their Web applications by injecting vulnerability assessments and ethical hacks into their software development and delivery processes. This paper describes 12 of the most common hacker attacks and provides basic rules that you can follow to help create more hack-resistant Web applications. FREE! Go There Now!
| | | | Visit IBM developerWorks to try the IBM SOA Sandbox for people. The SOA Sandbox for people provides a trial environment with the necessary tooling and components required to enable consistent human and process interaction and collaboration, showing how you can improve user experience and business productivity. FREE! Go There Now!
| | | | Whether you are creating new applications or modifying existing ones, managing integration of new components with traditional z/OS elements is a critical part of building and deploying modern applications. Listen to this webcast to see how IBM can help you optimize your development process using an IDE like Rational Developer for System z that integrates with management tools, such as ClearCase to manage your application development on mainframes. FREE! Go There Now!
| | | | Join this Rational Talks to You teleconference, to hear how Enterprise Generation Language (EGL) eliminates the need for tedious and error-prone low level coding, so developers can focus on business requirements. EGL extends the Rational software development platform with a simplified programming language that enables developers who have little or no experience with Java, Web technologies or Service Oriented Architecture, to create enterprise-class applications and services quickly and easily. It also allows developers who may have little or no mainframe programming experience to quickly create traditional mainframe components. FREE! Go There Now!
| | | | Explore how Rational and WebSphere software enable enterprise documentation in SOA environments. Specifically, a new integration between IBM WebSphere® Business Modeler and IBM Rational® Method Composer software can help technical writers more easily keep enterprise operations manuals in sync with changes that are made to business processes, resulting in more accurate and timely documentation that benefits the entire enterprise. FREE! Go There Now!
| | | | All FREE IBM® developerWorks Tools! | |