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! | You'll get answers to many questions and more from David Barnes, Lead Evangelist for IBM Emerging Internet Technologies. David will discuss aspects of Web 2.0 that bring value to corporations, academia, and government. He'll also discuss IBM's vision around Web 2.0, including the importance of remixability and consumability. The discussion will culminate with examples of various IBM Software Group solutions you can use to get ahead of the Web 2.0 adoption curve. FREE! Go There Now!
| | | | Join this Rational Talks to You teleconference, featuring Paul Boustany and Mark Krasovich, to speak to the experts about becoming a Rational ClearCase power user. Get a chance to ask your questions and learn tips and tricks for using Rational ClearCase in Agile development FREE! Go There Now!
| | | | This whitepaper presents the benefits of successfully introducing static analysis into your organization using IBM Rational Software Analyzer. Additionally, it identifies some common pitfalls that can hinder the effective use of static analysis tooling as well as presents 10 simple strategies designed to help you quickly realize the value of static analysis using Rational Software Analyzer. FREE! Go There Now!
| | | | Join us for this web seminar to learn how you can defend your web applications from attack. Learn about the 3 most common web application attacks, including how they occur and what can be done to prevent them. We’ll also discuss manual versus automated approaches for scanning and identifying web application vulnerabilities and how IBM Rational AppScan, an automated vulnerability scanner, can help you automate more of what you are doing manually today. FREE! Go There Now!
| | | | Asset Reuse is a key strategy for companies looking to create innovative solutions to solve complex software development problems. Searching for, identifying, updating, using and deploying software assets can be a difficult challenge. Listen to this webcast, to learn about strategies and tools that you can leverage for a successful project, including Rational Asset Manager, Rational Software Architect and WebSphere Service Registry and Repository. FREE! Go There Now!
| | | | Get a free trial download of the latest version of IBM Rational Functional Tester V7.0.1. Rational Functional Tester is an automated functional and regression testing solution for QA teams concerned with the quality of their Java, Microsoft Visual Studio .NET, and Web-based applications. FREE! Go There Now!
| | | | Join the IBM Watchfire team for an informative discussion on techniques and best practices to proactively manage Web application security and how to effectively build application security testing into the software development lifecycle (SDLC). In this Software Delivery Platform webcast you will learn: How to better understand potential web application security vulnerabilities, best practices and how to effectively integrate application security testing into the software development lifecycle, the importance of detecting and removing software vulnerabilities during application development. FREE! Go There Now!
| | | | In this webcast, you'll get an introduction to the eXtreme Transaction Processing (XTP) features of WebSphere Extended Deployment and the common architectural traits required by XTP applications. See how WebSphere Extended Deployment's ObjectGrid feature provides a state-of-the-art infrastructure for hosting XTP applications. FREE! Go There Now!
| | | | Join this webcast to learn how IBM Rational's Functional Testing solution enables you to implement automation your way, at your pace, with your existing staff. In this webcast, you’ll learn how you can eliminate redundancy of manual test scripts, reduce errors, and increase test coverage through test automation. After this presentation you will understand how IBM Rational Functional Testing solution can streamline your manual testing and make test automation easily attainable. FREE! Go There Now!
| | | | WebSphere Process Server delivers a unique integration framework that simplifies existing IT resources. Often, as IT assets grow to support business demand, so too does their complexity and manageability. In this webcast, we’ll discuss how WebSphere Process Server helps deliver an SOA infrastructure that provides a common model to orchestrate, mediate, connect, map, and execute the underlying IT functions. Discover how WebSphere Process Server simplifies integration of business processes by leveraging existing IT assets as reusable services without the complexities of traditional integration methodologies. FREE! Go There Now!
| | | | All FREE IBM® developerWorks Tools! | |